本文介绍使用spire.pdf for .net将pdf转为pdf/a的方法。
c#
using spire.pdf;
using spire.pdf.graphics;
namespace convertpdftopdfa
{
class program
{
static void main(string[] args)
{
//加载pdf测试文档
pdfdocument pdf = new pdfdocument();
pdf.loadfromfile("test.pdf");
//实例化pdfnewdocument类,并设置conformance级别(支持pdf_a1a、pdf_a1b、pdf_a2a、pdf_x1a2001)
pdfnewdocument newpdf = new pdfnewdocument();
newpdf.conformance = pdfconformancelevel.pdf_a1b;
//遍历文档所有页面
for (int i = 0; i < pdf.pages.count; i )
{
pdfpagebase page = pdf.pages[i];
//基于原页面大小创建模板
pdfpagebase p = newpdf.pages.add(page.size, new pdfmargins(0, 0));
page.createtemplate().draw(p,0,0);
}
//保存文档
newpdf.save("topdfa.pdf");
system.diagnostics.process.start("topdfa.pdf");
}
}
}
vb.net
imports spire.pdf
imports spire.pdf.graphics
namespace convertpdftopdfa
class program
private shared sub main(args as string())
'加载pdf测试文档
dim pdf as new pdfdocument()
pdf.loadfromfile("test.pdf")
'实例化pdfnewdocument类,并设置conformance级别(支持pdf_a1a、pdf_a1b、pdf_a2a、pdf_x1a2001)
dim newpdf as new pdfnewdocument()
newpdf.conformance = pdfconformancelevel.pdf_a1b
'遍历文档所有页面
for i as integer = 0 to pdf.pages.count - 1
dim page as pdfpagebase = pdf.pages(i)
'基于原页面大小创建模板
dim p as pdfpagebase = newpdf.pages.add(page.size, new pdfmargins(0, 0))
page.createtemplate().draw(p, 0, 0)
next
'保存文档
newpdf.save("topdfa.pdf")
system.diagnostics.process.start("topdfa.pdf")
end sub
end class
end namespace
转换效果: