【问题标题】:Setting PDF document title and author with EVOPDF in a PDF/A-1b compliant file在 PDF/A-1b 兼容文件中使用 EVOPDF 设置 PDF 文档标题和作者
【发布时间】:2015-12-07 17:08:51
【问题描述】:

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

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

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

我尝试了从此处http://www.evopdf.com/download.aspx 下载的“EvoHtmlToPdfDemo_VS2013”​​v6.4 解决方案,但在整个解决方案中找不到 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 对象完成它。不过我更喜欢使用后一个对象,因为大多数文档都引用了HtmlToPdfConverterEvoPdf.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.DocumentInfoEvoPdf.PdfDocumentInfo 类?一个使用AuthorName,另一个使用Author。还有更多这些差异。

【问题讨论】:

  • @EvoPdfHelpDesk 请帮帮我:)

标签: c# properties metadata document evopdf


【解决方案1】:

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

【讨论】:

  • 我已使用EvoPdf.Document 成功将其写入PDF。但是使用EvoPdf.HtmlToPdfConverter 根本行不通。该属性有一个公共设置器。你怎么能说它是只读的呢?
  • 那么其他没有写入文件的属性呢?
  • 我可以使用 htmlToPdfConverter.PdfDocumentInfo.AuthorName = "author" 来设置作者。但是 Producer 属性是只读的。
【解决方案2】:

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

【讨论】:

  • 这不是真的,PDF/A-1b 文件支持元数据。但是必须将其写入 XMP 流。 pdfa.org/2009/06/…
【解决方案3】:

元数据,如作者、标题等,应以符合 PDF/A-1b 的 PDF 格式写入 XMP 流。 See XMP Metadata in PDF/A

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

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

【讨论】:

    猜你喜欢
    • 2018-12-18
    • 2013-10-18
    • 1970-01-01
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多