将PDF转换为PDF / A3或PDF / A-1转换为PDF / A-3 [英] Convert PDF to PDF/A3 or PDF/A-1 to PDF/A-3

查看:278
本文介绍了将PDF转换为PDF / A3或PDF / A-1转换为PDF / A-3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试iTextSharp以生成ZUGFeRD文件。我的第一步是从现有的PDF / A-3文件生成ZUGFeRD一致性文件。这是成功的,使用PDFACopy并创建必要的PDFFileSpecification。

I'm testing iTextSharp to generate ZUGFeRD-Files. My first step was to generate a ZUGFeRD conform file from an existing PDF/A-3 file. This was successfull by using PDFACopy and creating the necessary PDFFileSpecification.

下一步是从现有PDF或PDF / A-生成PDF / A-3文件1个文件,这是最难的部分。

The next step would be to generate a PDF/A-3 file from an existing PDF or PDF/A-1 file and this is the hard part.

首先,当我尝试将PDFACopy与常规PDF(不是PDF / A)结合使用时出现错误PDFACopy只能与PDF / A-conform文件一起使用。 我的第一个问题是,如何从带有iTextSharp的PDF获取PDF / A-3-conform文件?

First, when I'm trying to use PDFACopy in combination with a regular PDF (not PDF/A) im getting an error that PDFACopy can only be used with PDF/A-conform files. My first question is, how to get an PDF/A-3-conform file from a PDF with iTextSharp?

为了缩小差距,我决定使用ghostscript将PDF转换为PDF / A-1文件(参见如何使用ghostscript将PDF转换为PDF / A或PDF / X?)。
这是成功的,我又试了一次。然后错误不同的PDF / A版本。被扔了。我似乎无法将现有的PDF / A-1复制到新的PDF / A-3中。 如何从现有PDF(/ A-1)创建此PDF / A-3?这有可能吗?

To reduce the gap, I decided to convert the PDF into PDF/A-1 file with ghostscript (cf. How to use ghostscript to convert PDF to PDF/A or PDF/X?). This was succesfull and I tried again. Then the error "Different PDF/A version." was thrown. It seems that I can't copy from existing PDF/A-1 into a new PDF/A-3. How can I create this PDF/A-3 from an existing PDF(/A-1)? Is that even possible?

这是我的代码:

XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(XML);
        byte[] xmlBytes = Encoding.Default.GetBytes(xmlDoc.OuterXml);

        Document doc = new Document();
        PdfReader src_reader = new PdfReader(pdfPath);    

        FileStream fs = new FileStream(DEST, FileMode.Create, FileAccess.ReadWrite);

        PdfACopy aCopy = new PdfACopy(doc, fs, PdfAConformanceLevel.ZUGFeRD);

        doc.AddLanguage("de-DE");
        doc.AddTitle("title");
        doc.SetPageSize(src_reader.GetPageSizeWithRotation(1));

        aCopy.SetTagged();
        aCopy.UserProperties = true;
        aCopy.PdfVersion = PdfCopy.VERSION_1_7;
        aCopy.ViewerPreferences = PdfCopy.DisplayDocTitle;
        aCopy.CreateXmpMetadata();
        aCopy.XmpWriter.SetProperty(PdfAXmpWriter.zugferdSchemaNS, PdfAXmpWriter.zugferdDocumentFileName, "ZUGFeRD-invoice.xml");

        //Ab hier können keine Metadaten mehr geschrieben werden
        doc.Open();

        ICC_Profile icc = ICC_Profile.GetInstance(new FileStream(ICM, FileMode.Open));
        aCopy.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

        [...add the dictionary to doc..]
        aCopy.AddDocument(src_reader);
        doc.Close();

还有一个问题: addDocument有效,但当我使用副本时.addPage(copy.getImportedPage(src_reader,i)),将抛出错误文档没有页面。 为什么?

One more question: addDocument works, but when I'm using copy.addPage(copy.getImportedPage(src_reader, i)), an error "the document has no pages" will be thrown. WHY?

推荐答案

1。您可以将常规PDF转换为PDF / A文档吗?

答案是:取决于。

PDF / A是PDF的一个子集,涉及一些义务(例如,必须嵌入所有字体)和限制(例如,不允许使用Javascript)。由于多种原因,iText无法自动将常规PDF转换为PDF / A.例如:如果没有嵌入字体,iText不知道用哪种字体替换未嵌入字体,也不知道在哪里找到必要的字体程序。通常这需要人工交互,因为用任意其他字体替换一种字体通常会导致非常难看的PDF。

PDF/A is a subset of PDF and involves some obligations (e.g. all fonts must be embedded) and restrictions (e.g. no Javascript is allowed). iText can't "automatically" convert a regular PDF to a PDF/A for a number of reasons. For instance: if a font is not embedded, iText doesn't know which font to use to replace the unembedded font, nor where to find the necessary font program. Usually this requires human interaction because replacing one font by an arbitrary other font usually results in very ugly PDFs.

答案是:它取决于因为有些人正在使用iText将PDF转换为PDF / A,但这需要大量的编程和人工决策。我发现你在使用GhostScript时取得了成功。在这种情况下,GhostScript会在您的位置做出一些决定。这可以产生可接受的结果。在某些情况下,结果是不可接受的(例如,如果字体不匹配,看起来非常奇怪的PDF)。

The answer is: it depends because some people are using iText to convert PDF to PDF/A, but this involves a lot of programming and human decisions. I see that you succeed when using GhostScript. In that case, GhostScript is making some decisions in your place. This can lead to acceptable results. In some cases, the result will not be acceptable (e.g. very odd-looking PDFs if the fonts don't match).

2。您可以将PDF / A-1文件转换为PDF / A-3文件吗?

PDF / A标准的编写方式是旧版本的PDF / A规范永远不会过时。较新的版本仅添加更新的功能。例如:PDF / A-1基于PDF 1.4规范。 PDF 1.5中引入了可选内容功能(OCG)。 OCG的引入是PDF / A-2和PDF / A-1之间的差异之一。

The PDF/A standard is written in such a way that old versions of the PDF/A specification are never outdated. Newer versions only add newer functionality. For instance: PDF/A-1 was based on the PDF 1.4 specification. Optional Content functionality (OCG) was introduced in PDF 1.5. The introduction of OCG is one of the differences between PDF/A-2 and PDF/A-1.

这意味着每个符合PDF / A-1的文件自动符合PDF / A-2。但是,PDF / A-2文件可能包含PDF / A-1不支持的功能。

This means that every file that conforms to PDF/A-1 automatically conforms to PDF/A-2. However, a PDF/A-2 file could contain functionality that isn't supported in PDF/A-1.

3。 PDF / A-2和PDF / A-3有什么区别?

PDF / A-2和PDF / A-3是相同的,除了一个区别:PDF / A-3文件可以包含非PDF / A文件的附件。例如:PDF / A-3文件可以将Word文件作为附件,XLS文件,纯文本文件,......你提到ZUGFeRD:在这种情况下,PDF / A-3文件至少有一个XML作为附件存档。

PDF/A-2 and PDF/A-3 are identical, except for one difference: a PDF/A-3 file can have attachments that aren't PDF/A files. For instance: a PDF/A-3 file can have a Word file as attachment, an XLS file, a plain text file,... You mention ZUGFeRD: in that case, the PDF/A-3 file has at least an XML file as attachment.

摘要:

这是一个广泛的答案广泛的问题(你的问题有很多不同的方向,所以很难给你一个具体的答案)。为什么不使用已经内置的ZUGFeRD支持来创建发票?阅读 ZUGFeRD,发票的未来以获取更多信息。

This is a broad answer to a broad question (your question goes in many different directions, so it's hard to give you a specific answer). Why don't you use the already built-in ZUGFeRD support to create the invoices? Read ZUGFeRD, the future of invoicing for more info.

这篇关于将PDF转换为PDF / A3或PDF / A-1转换为PDF / A-3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆