1

我正在尝试使用 EVOPDF 在 HTML -> PDF 生成的文件上设置一些属性。

设置 PdfDocumentInfo 属性似乎很简单。如文档所示:http ://www.evopdf.com/help/azure-html-to-pdf/html/T_EvoPdf_HtmlToPdfClient_PdfDocumentInfo.htm

但是,Adobe Acrobat Reader 在查看文件-> 属性时显示空框。十六进制编辑器也找不到任何数据。

我尝试了从这里下载的“EvoHtmlToPdfDemo_VS2013”​​v6.4 解决方案 http://www.evopdf.com/download.aspx但在整个解决方案中找不到 PdfDocumentInfo。所以没有演示代码来显示应该如何设置文档属性。

请参阅下面的代码

  var converter = new HtmlToPdfConverter();
        converter.ConversionDelay = 0;
        converter.ClipHtmlView = false;

        var paperSize = PaperSizeToSizeF(pPaperSize);
        var pdfPageOrientation = (pIsLandscape) ? PdfPageOrientation.Landscape : PdfPageOrientation.Portrait;
        converter.PdfDocumentOptions.PdfPageOrientation = pdfPageOrientation;
        converter.PdfDocumentOptions.PdfStandardSubset = PdfStandardSubset.Pdf_A_1b;

        //IMPORTANT FOR COMPLIANCE
        converter.PdfDocumentInfo.AuthorName = "Mike de Klerk";
        converter.PdfDocumentInfo.Title = "PDF/A-1b Test";
        converter.PdfDocumentInfo.Subject = "Testing generation of PDF/A-1b compliant file by EVOPDF library.";
        converter.PdfDocumentInfo.Keywords = "HTML, PDF, Converter, PDF/A-1b. compliance";
        converter.PdfDocumentInfo.CreatedDate = DateTime.Now;

编辑

使用该EvoPdf.Document对象时,我可以完成它。但是我无法使用该EvoPdf.HtmlToPdfConverter对象完成它。不过我更喜欢使用后一个对象,因为大多数文档都引用了HtmlToPdfConverter. 对象的用法见下面的代码EvoPdf.Document

        // Create the PDF document where to add the HTML documents
        var pdfDocument = new Document();

        // Set license key received after purchase to use the converter in licensed mode
        // Leave it not set to use the converter in demo mode
        pdfDocument.LicenseKey = LicenseKey;
        pdfDocument.DocumentInformation.Author = "Mike de Klerk";
        pdfDocument.DocumentInformation.Title = "PDF/A-1b Test";
        pdfDocument.DocumentInformation.Subject = "Testing generation of PDF/A-1b compliant file by EVOPDF library.";
        pdfDocument.DocumentInformation.Keywords = "HTML, PDF, Converter, PDF/A-1b. compliance";
        pdfDocument.DocumentInformation.CreationDate = DateTime.Now;

编辑2:

有一个HtmlToPdfConverter.PdfDocumentOptions.DocumentObject.DocumentInformation对象。但DocumentObject在转换之前为空。文件说

转换期间由转换器初始化的对内部 Document 对象的引用

DocumentObject转换后确实存在,我可以确认DocumentInformation转换后没有设置属性。

编辑 3:

此外,设置DocumentInformation转换前/转换后事件似乎也无法正常工作。

converter.PrepareRenderPdfPageEvent += (eventParams) =>
{
    converter.PdfDocumentOptions.DocumentObject.DocumentInformation.Author = "Mike de Klerk";
    converter.PdfDocumentOptions.DocumentObject.DocumentInformation.Title = "PDF/A-1b Test";
    converter.PdfDocumentOptions.DocumentObject.DocumentInformation.Subject = "Testing generation of PDF/A-1b compliant file by EVOPDF library.";
    converter.PdfDocumentOptions.DocumentObject.DocumentInformation.Keywords = "HTML, PDF, Converter, PDF/A-1b. compliance";
    converter.PdfDocumentOptions.DocumentObject.DocumentInformation.CreationDate = DateTime.Now;
};
converter.AfterRenderPdfPageEvent += (eventParams) =>
{
    eventParams.Page.Document.DocumentInformation.Author = "Mike de Klerk";
    eventParams.Page.Document.DocumentInformation.Title = "PDF/A-1b Test";
    eventParams.Page.Document.DocumentInformation.Subject = "Testing generation of PDF/A-1b compliant file by EVOPDF library.";
    eventParams.Page.Document.DocumentInformation.Keywords = "HTML, PDF, Converter, PDF/A-1b. compliance";
    eventParams.Page.Document.DocumentInformation.CreationDate = DateTime.Now;
};
converter.ConvertHtmlFileToStream(pContentHtmlFile, pOutputStream);

编辑4:

Document首先转换为对象,然后设置DocumentInformation然后写入Document输出流时甚至不起作用。我觉得我在这里没有可能的解决方法......

        var documentObject = converter.ConvertHtmlFileToPdfDocumentObject(pContentHtmlFile);
        documentObject.DocumentInformation.Author = "Mike de Klerk";
        documentObject.DocumentInformation.Title = "PDF/A-1b Test";
        documentObject.DocumentInformation.Subject = "Testing generation of PDF/A-1b compliant file by EVOPDF library.";
        documentObject.DocumentInformation.Keywords = "HTML, PDF, Converter, PDF/A-1b. compliance";
        documentObject.DocumentInformation.CreationDate = DateTime.Now;
        documentObject.Save(pOutputStream);

编辑 5:

我假设当一个人这样做时documentObject.DocumentInformation.Author = "Value";,它有一个设置器,它实际上是设置的。但事实并非如此。因此,我尝试在哪里设置这些值并不重要。他们只是不被记住。这一定是个bug。为什么还有一个EvoPdf.DocumentInfo和一个EvoPdf.PdfDocumentInfo类?一种用途AuthorName,另一种Author。还有更多这些差异。

4

3 回答 3

0

元数据(如作者、标题等)应以符合 PDF/A-1b 的 PDF 格式写入 XMP 流。请参阅 PDF/A 中的 XMP 元数据

EvoPdf 将元数据写入不是 XMP 流的流。因此,生成符合 PDf/A-1b 的文件并添加(非 XMP 流)元数据会导致文件不符合 PDF/A-1b。所以元数据根本不被写入,以保持文件兼容。

有一个Adob​​e XMP Toolkit可以帮助您将元数据添加到使用 EvoPdf 生成的 PDF/A-1b 兼容文件中。但我不知道在使用 EvoPdf 生成文件时是否可以对文件进行签名和/或密码保护。

于 2015-09-14T07:05:19.223 回答
0

您不能将 EVO HTML 生成的 PDF 文档的生成器更改为 PDF Converter。该属性是只读的。

于 2015-09-11T12:27:41.323 回答
-1

问题是您正在创建 PDF/A 文档。本标准不允许设置作者姓名。

于 2015-09-11T13:35:20.473 回答