Tweaking Fonts in PDF


If the font in the generated PDF document does not match the font style defined in the HTML/CSS, first ensure that the font mapping is configured correctly.

Ideally, the font-family parameter (e.g., font-family: My Font) should correspond to the font key in the pd4fonts.properties file:

My\ Font=mybrandfont.ttf

(The space in the key name is escaped with a backslash.)

If the required font appears in the pd4fonts.properties file under a different name, for example:

My\ Brand\ Font=mybrandfont.ttf

you have two options:

  1. Modify the HTML or CSS to reference the registered font name: font-family: My Brand Font;
     
  2. Add a new entry to the pd4fonts.properties file using the exact font name actually applied in the code:
     
    My\ Brand\ Font=mybrandfont.ttf
    My\ Font=mybrandfont.ttf
    

    If for any reason you are using the actual TTF filename directly in your HTML/CSS (font-family: mybrandfont;), you can also add the corresponding key to the mapping file:

    My\ Brand\ Font=mybrandfont.ttf
    My\ Font=mybrandfont.ttf
    mybrandfont=mybrandfont.ttf

If the names of the fonts used in HTML are not known in advance, there is a high probability that font substitution fallback logic will be triggered. In such a case, the system will select any font belonging to the same typeface category (serif, sans-serif, or monospace) that is capable of displaying the specified text.

However, some fonts cannot be automatically assigned to a specific typeface category, so a bit of manual tweaking would help.

PD4ML supports a list of predefined placeholders for fallback font names, covering three font family categories (five for each):

customserif1
...
customserif5

customsans1
...
customsans5

custommono1
...
custommono5

Thus, you can add your font to a fallback list:

customsans1=mybrandfont.ttf

or even to all the lists at once if you prefer that this font be used in place of any missing ones

customserif1=mybrandfont.ttf
customsans1=mybrandfont.ttf
custommono1=mybrandfont.ttf

Compliance with PDF standards


PD4ML v4.1.0 introduces a new API method, pd4ml.writePDF(OutputStream, PdfSpec), which allows you to specify the required PDF standard compliance level.

Available options:

  • PDF1.4PdfSpec.PDF_1_4 – Acrobat 5
  • PDF1.5PdfSpec.PDF_1_5 – Acrobat 6
  • PDF1.6PdfSpec.PDF_1_6 – Acrobat 7
  • PDF1.7PdfSpec.PDF_1_7 – Acrobat 8 / ISO 3200-1
  • PDF1.7ext1PdfSpec.PDF_1_7_1
  • PDF1.7ext2PdfSpec.PDF_1_7_2
  • PDF1.7ext3PdfSpec.PDF_1_7_3 – Acrobat 9
  • PDF1.7ext4PdfSpec.PDF_1_7_4
  • PDF1.7ext5PdfSpec.PDF_1_7_5
  • PDF1.7ext6PdfSpec.PDF_1_7_6
  • PDF1.7ext7PdfSpec.PDF_1_7_7
  • PDF1.7ext8PdfSpec.PDF_1_7_8 – Acrobat X
  • PDF1.7ext9PdfSpec.PDF_1_7_9
  • PDF1.7ext10PdfSpec.PDF_1_7_10
  • PDF1.7ext11PdfSpec.PDF_1_7_11 – Acrobat XI
  • PDF2.0PdfSpec.PDF_2_0

The PdfSpec parameter can be combined with one of PDF/A modifiers

  • PDF/A-1a:2005PdfSpec.PDFA_1A
  • PDF/A-1b:2005PdfSpec.PDFA_1B
  • PDF/A-2aPdfSpec.PDFA_2A
  • PDF/A-2bPdfSpec.PDFA_2B
  • PDF/A-2uPdfSpec.PDFA_2U
  • PDF/A-3aPdfSpec.PDFA_3A
  • PDF/A-3bPdfSpec.PDFA_3B
  • PDF/A-3uPdfSpec.PDFA_3U
  • PDF/A-4PdfSpec.PDFA_4 – requires PDF2.0
  • PDF/A-4ePdfSpec.PDFA_4E – requires PDF2.0

The combining can be done as follows:

    pd4ml.writePDF(os, PdfSpec.PDFA_3B); // implicitly adds PDF1.7 conformance
    pd4ml.writePDF(os, PdfSpec.PDF_1_7_8.combine(PdfSpec.PDFA_3B));

And also PDF or PDF/A-a can be combined with PDF/UA

  • PDF/UA-1PdfSpec.PDFUA_1
  • PDF/UA-2PdfSpec.PDFUA_2 – requires PDF2.0

Examples:

    pd4ml.writePDF(os, PdfSpec.PDFUA_1); // implicitly adds PDF1.7 conformance
    pd4ml.writePDF(os, PdfSpec.PDF_1_7_8.combine(PdfSpec.PDFUA_1));
    pd4ml.writePDF(os, PdfSpec.PDF_1_7_11.combine(PdfSpec.PDFA_3A).combine(PdfSpec.PDFUA_1));

There are also several predefined constants that combine PDF standards as required by XML invoicing specs:

  • ZUGFeRDPdfSpec.ZUGFeRD, which is PdfSpec.PDF_1_7.combine(PdfSpec.PDFA_3B)
  • ZUGFeRD (tagged)PdfSpec.ZUGFeRD_a, which is PdfSpec.PDF_1_7.combine(PdfSpec.PDFA_3A)
  • Factur-XPdfSpec.FacturX, which is PdfSpec.PDF_1_7.combine(PdfSpec.PDFA_3B)
  • Factur-X (tagged)PdfSpec.FacturX_a, which is PdfSpec.PDF_1_7.combine(PdfSpec.PDFA_3A)

 

NOTE: Not all the standards can be combined with each other. PdfSpec.combine() throws PdfSpecViolationException and PdfSpecUnsupportedException in incompatibility cases.

Creating DOCX Files


v4.0.19 introduces support for creating OOXML (DOCX) files from HTML.

It is already functionally superior to the long-standing PD4ML HTML to RTF converter. It allows you to define text and paragraph styles, nested tables, ordered and unordered lists, headers and footers, table of contents, hyperlinks, bookmarks, borders, backgrounds, and embed images.

To force DOCX output you only need to trigger pd4ml.writeDOCX() API method instead of pd4ml.writePDF() in usual conversion scenarios.

The converter is available under the PD4ML DMS or PD4ML UA license.

Read more: https://pd4ml.com/creation-of-ooxml-docx-documents/