我正在尝试使用 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
。还有更多这些差异。