我正在尝试将现有的pdf变成pdf/a-1b。我知道在这个意义上,itext不能将pdf转换成pdf/a,使它符合pdf/a。但它绝对可以将文件标记为pdf/a。然而,我看了很多例子,但我似乎想不出怎么做。主要的问题是
writer.PDFXConformance = PdfWriter.PDFA1B;不再起作用了。首先,PDFA1B没有被识别,其次,pdfwriter似乎被重写了,而且没有多少关于它的信息。似乎唯一的方法(在itext java版本中)是:
PdfAWriter writer = PdfAWriter.getInstance(document, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_1B);但这需要一种文档类型。它可以在从头开始创建pdf时使用。
有人能给出一个pdf到pdf/a转换的例子吗?谢谢。
发布于 2013-10-02 14:09:57
我想不出有什么合理的理由这么做,但显然你有一个理由。
iText中的一致性设置打算与PdfWriter一起使用,该对象(通常)仅用于新文档。因为iText从未打算将文档转换为一致性,这正是构建它的方式。
要完成您想做的事情,您可以打开原始文档并更新文档字典中的适当标记,也可以创建一个设置了适当条目的新文档,然后导入旧文档。下面的代码显示了后一条路线,它首先创建一个常规的不符合规定的PDF,然后创建第二个文档,说明它是符合的,即使它可能或可能不符合。有关详细信息,请参阅代码注释。它的目标是iTextSharp 5.4.2.0。
//Folder that we're working from
var workingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
//Create a regular non-conformant PDF, nothing special below
var RegularPdf = Path.Combine(workingFolder, "File1.pdf");
using (var fs = new FileStream(RegularPdf, FileMode.Create, FileAccess.Write, FileShare.None)) {
using (var doc = new Document()) {
using (var writer = PdfWriter.GetInstance(doc, fs)) {
doc.Open();
doc.Add(new Paragraph("Hello world!"));
doc.Close();
}
}
}
//Create our conformant document from the above file
var ConformantPdf = Path.Combine(workingFolder, "File2.pdf");
using (var fs = new FileStream(ConformantPdf, FileMode.Create, FileAccess.Write, FileShare.None)) {
using (var doc = new Document()) {
//Use PdfSmartCopy to get every page
using (var copy = new PdfSmartCopy(doc, fs)) {
//Set our conformance levels
copy.SetPdfVersion(PdfWriter.PDF_VERSION_1_3);
copy.PDFXConformance = PdfWriter.PDFX1A2001;
//Open our new document for writing
doc.Open();
//Bring in every page from the old PDF
using (var r = new PdfReader(RegularPdf)) {
for (var i = 1; i <= r.NumberOfPages; i++) {
copy.AddPage(copy.GetImportedPage(r, i));
}
}
//Close up
doc.Close();
}
}
}为了100%的澄清,这个不会使一个符合PDF格式的,只是一个文件,说它符合。
https://stackoverflow.com/questions/19133355
复制相似问题