【发布时间】: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 对象完成它。不过我更喜欢使用后一个对象,因为大多数文档都引用了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。还有更多这些差异。
【问题讨论】:
-
@EvoPdfHelpDesk 请帮帮我:)
标签: c# properties metadata document evopdf