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() throws IOException
      Constructor.
      Throws:
      IOException
  • 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(String subject, String author, String description, String title, NarrativeLanguage lang, Map<String,String> bookmarks, String cssContent, String bodyContent) throws IOException
      Converts the HTML content to its PDF/A representation, with the default template.
      Specified by:
      convert in interface HtmlToPdfAConverter
      Parameters:
      subject - The document subject. It's inserted in a <meta name="subject"> tag.
      author - The document author. It's inserted in a <meta name="author"> tag.
      description - The document description. It's inserted in a <meta name="description"> tag.
      title - The document title.
      lang - The document language, as an ISO code.
      bookmarks - A list of bookmarks to interesting parts of the document. The keys are labels that are shown to the user, the values are HTML ID references (starting with '#').
      cssContent - The CSS content to inject.
      bodyContent - The HTML content to convert. It will be inserted in a <body> tag.
      Returns:
      The content of the generated PDF/A.
      Throws:
      IOException - if a font cannot be read.
    • convert

      public byte[] convert(String subject, String author, String description, String title, NarrativeLanguage lang, Map<String,String> bookmarks, String cssContent, String bodyContent, String templateContent) throws IOException
      Converts the HTML content to its PDF/A representation, with a custom template.
      Parameters:
      subject - The document subject. It's inserted in a <meta name="subject"> tag.
      author - The document author. It's inserted in a <meta name="author"> tag.
      description - The document description. It's inserted in a <meta name="description"> tag.
      title - The document title.
      lang - The document language, as an ISO code.
      bookmarks - A list of bookmarks to interesting parts of the document. The keys are labels that are shown to the user, the values are HTML ID references (starting with '#').
      cssContent - The CSS content to inject.
      bodyContent - The HTML content to convert. It will be inserted in a <body> tag.
      templateContent - The custom Thymeleaf content.
      Returns:
      The content of the generated PDF/A.
      Throws:
      IOException - if a font cannot be read.