Class OpenHtmlToPdfAConverter

java.lang.Object
org.projecthusky.fhir.emed.ch.epr.narrative.pdf.OpenHtmlToPdfAConverter
All Implemented Interfaces:
HtmlToPdfAConverter

public class OpenHtmlToPdfAConverter extends Object implements HtmlToPdfAConverter
The implementation of HtmlToPdfAConverter with the Open HTML to PDF converter library.
Author:
Quentin Ligier
  • Constructor Details

    • OpenHtmlToPdfAConverter

      public OpenHtmlToPdfAConverter()
      Constructor.
  • Method Details

    • getProducerName

      public @Nullable String getProducerName()
      Gets the producer name.
    • setProducerName

      public void setProducerName(@Nullable String producerName)
      Sets the producer name that will be included in generated PDF documents. Use null to disable.
      Parameters:
      producerName - The producer name or null.
    • addFont

      public void addFont(String family, int weight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle style, Callable<InputStream> inputStream)
      Declares a new font. Fonts are embedded in the PDF document only when they are used by the converter.
      Parameters:
      family - The font family (name).
      weight - The font CSS weight (100-900).
      style - The font style.
      inputStream - The font InputStream supplier. It shall not return null.
    • getFonts

      public List<@NonNull OpenHtmlToPdfAConverter.Font> getFonts()
      Gets the declared fonts.
    • getPdfRendererBuilderConsumer

      public @Nullable Consumer<com.openhtmltopdf.pdfboxout.PdfRendererBuilder> getPdfRendererBuilderConsumer()
    • setPdfRendererBuilderConsumer

      public void setPdfRendererBuilderConsumer(@Nullable Consumer<com.openhtmltopdf.pdfboxout.PdfRendererBuilder> pdfRendererBuilderConsumer)
    • convert

      public byte[] convert(NarrativeLanguage lang, Map<String,Object> contextVariables, String templateContent)
      Description copied from interface: HtmlToPdfAConverter
      Converts the HTML content to its PDF/A representation, with a custom template.
      Specified by:
      convert in interface HtmlToPdfAConverter
      Parameters:
      lang - The document language, as an ISO code.
      contextVariables - The context variables to be added to the template processing. Note that a context variable lang is automatically added with the code value of the received lang parameter. Furthermore, the following context variables – and, possibly, others – are expected by the default templates provided with this module, since they are needed to produce a valid PDF/A document:
      • title - a string with the document's title.
      • subject - a string with the document's subject
      • author - a string with the document's author
      • description - a string with the document's description
      • bookmarks - a map of <String, String> pairs:
        • Key: a string with the bookmark link reference, that is, the value of the href attribute of an anchor element within the processed template.
        • Value: the value of the bookmark, that is, the string that will be used to display the bookmark itself.
        For instance, the pair ("Active Treatments", "#active-treatments") should be used to produce a bookmark to be rendered as Active Treatments that would point to the HTML element with id active-treatments in the processed template.
      Any callers using custom templates must make sure they are still setting these in their templates either by means of these context variables or by any other method (e.g. hardcoded in the template), as well as providing any other context variables that might be required by said templates.
      templateContent - The custom Thymeleaf content.
      Returns:
      The content of the generated PDF/A.