1

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.

Mike de Klerk
  • 11,906
  • 8
  • 54
  • 76

3 Answers3

0

You cannot change the producer of the PDF documents generated by EVO HTML to PDF Converter. This property is read only.

EvoPdf
  • 523
  • 3
  • 9
  • I've written it successfully to a PDF using `EvoPdf.Document`. But using `EvoPdf.HtmlToPdfConverter` it simply doesn't work. The property has a public setter. How can you say it is read-only? – Mike de Klerk Sep 11 '15 at 12:45
  • And what about the rest of the properties that don't get written to file? – Mike de Klerk Sep 11 '15 at 12:46
  • I could set the author for example with htmlToPdfConverter.PdfDocumentInfo.AuthorName = "author" . But the Producer property is read-only. – EvoPdf Sep 11 '15 at 13:24
0

Meta data, like author, title, etc. should be written to XMP stream in a PDF that is PDF/A-1b compliant. See XMP Metadata in PDF/A

EvoPdf writes meta data to a stream that is not a XMP stream. Therefore, generating a PDf/A-1b compliant file, and adding (non-XMP stream) meta data would result in a file that doesn't comply with PDF/A-1b. So the meta data simply isn't written, to keep the file compliant.

There is a Adobe XMP Toolkit that could help you achieve adding meta data to a PDF/A-1b compliant file generated with EvoPdf. But I don't know if it is possible when the file is signed and/or password protected during the generation with EvoPdf.

Mike de Klerk
  • 11,906
  • 8
  • 54
  • 76
-1

The problem is that you are creating PDF/A document. This standard does not allow setting an author name.

EvoPdf
  • 523
  • 3
  • 9
  • This isn't true, meta data is supported in a PDF/A-1b file. But is has to be written to a XMP stream. http://www.pdfa.org/2009/06/xmp-metadata-in-pdfa-%E2%80%93-metadata-and-the-xmp-format/ – Mike de Klerk Sep 14 '15 at 07:17