【问题标题】:Existing PDF to PDF/A "conversion"现有 PDF 到 PDF/A“转换”
【发布时间】:2013-10-02 08:59:53
【问题描述】:

我正在尝试将现有的 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 时使用。

有人可以举一个使用当前版本的 itextsharp 将 pdf 转换为 pdf/a 的示例吗? 谢谢。

【问题讨论】:

    标签: pdf itextsharp


    【解决方案1】:

    我无法想象这样做的正当理由,但显然你有一个。

    iText 中的一致性设置旨在用于PdfWriter,并且该对象(通常)仅用于新文档。因为 iText 从来没有打算将文档转换为一致性,这正是它的构建方式。

    要执行您想做的事情,您可以打开原始文档并更新文档字典中的相应标签,或者您可以创建一个具有相应条目集的新文档,然后导入您的旧文档。下面的代码显示了后一种路线,它首先创建一个常规的不合格 PDF,然后创建第二个文档,说明它是否符合,即使它可能符合也可能不符合。有关详细信息,请参阅代码 cmets。这针对 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,只是一个说明它符合标准的文档。

    【讨论】:

    • 感谢您的回答。该示例提供 PDFX 一致性。我如何将文档设置为符合 PDF/A-1B 标准?我发现的例子提到了 PDFA1B 而不是 PDFX1A2001,但是,在 itextsharp 5.4.4 中没有 PDFA1B 的定义,我查看了源代码,确实没有提到 PDFA1B。
    • 我前面没有编译器,但看起来这有你的答案:itext-general.2136553.n4.nabble.com/…
    • 这实际上是我已经遇到的问题,问题是如何将 PdfAWriter 的语法合并到使用 PdfSmartCopy 的示例中。我相信我需要做的是将页面导入文档类,然后将此文档类与 PdfAWrite 一起使用。你知道怎么做吗?谢谢。
    • 我实际上使用这个示例作为strip PDF/A 合规性的基础。 ;)
    猜你喜欢
    • 1970-01-01
    • 2016-03-17
    • 2015-05-25
    • 1970-01-01
    • 2016-05-09
    • 2016-06-15
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    相关资源
    最近更新 更多