I'm trying to set some attributes on a HTML -> PDF generated file using EVOPDF.
It seems pretty straightforward to set the PdfDocumentInfo properties. As given by the documentation: http://www.evopdf.com/help/azure-html-to-pdf/html/T_EvoPdf_HtmlToPdfClient_PdfDocumentInfo.htm
However, Adobe Acrobat Reader shows empty boxes when viewing File->Properties. And a Hex editor doesn't find any of the data either.
I tried the "EvoHtmlToPdfDemo_VS2013" v6.4 solution which I downloaded from here http://www.evopdf.com/download.aspx but PdfDocumentInfo isn't found in the entire solution. So no demo code to show how document properties should be set.
See my code below
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;
EDIT:
When using the EvoPdf.Document
object I can get it done. But I can't get it done using the EvoPdf.HtmlToPdfConverter
object. I prefer to use the latter object though, because most of the documentation refers to the HtmlToPdfConverter
. See the code below for the usage of EvoPdf.Document
object.
// 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;
EDIT 2:
There is a HtmlToPdfConverter.PdfDocumentOptions.DocumentObject.DocumentInformation
object. But the DocumentObject
is null before conversion. The documentation says
A reference to the internal Document object initialized by converter during conversion
DocumentObject
exists indeed after conversion, and I can confirm that the DocumentInformation
properties aren't set after conversion.
EDIT 3:
Also setting the DocumentInformation
in pre/post convert events don't seem to get it working.
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);
EDIT 4:
Not even working when converting to a Document
object first, setting the DocumentInformation
then, and write the Document
to the output stream. I feel I am running out of possible workarounds here...
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);
EDIT 5:
I assumed that when one does documentObject.DocumentInformation.Author = "Value";
, and it has a setter, it is actually set. but it isn't. Hence, it doesn't matter where I am trying to set these values. They just aren't remembered. This must be a bug. Why is there even a EvoPdf.DocumentInfo
and a EvoPdf.PdfDocumentInfo
class? One uses AuthorName
, and the other Author
. And more of these differences.