Class OpenHtmlToPdfAConverter
java.lang.Object
org.projecthusky.fhir.emed.ch.epr.narrative.pdf.OpenHtmlToPdfAConverter
- All Implemented Interfaces:
HtmlToPdfAConverter
The implementation of
HtmlToPdfAConverter with the Open HTML to PDF converter library.- Author:
- Quentin Ligier
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRecord of a font declaration.static classImplementation of a font cache. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFont(String family, int weight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle style, Callable<InputStream> inputStream) Declares a new font.byte[]Converts the HTML content to its PDF/A representation, with a custom template.List<@NonNull OpenHtmlToPdfAConverter.Font>getFonts()Gets the declared fonts.@Nullable Consumer<com.openhtmltopdf.pdfboxout.PdfRendererBuilder>@Nullable StringGets the producer name.voidsetPdfRendererBuilderConsumer(@Nullable Consumer<com.openhtmltopdf.pdfboxout.PdfRendererBuilder> pdfRendererBuilderConsumer) voidsetProducerName(@Nullable String producerName) Sets the producer name that will be included in generated PDF documents.
-
Constructor Details
-
OpenHtmlToPdfAConverter
public OpenHtmlToPdfAConverter()Constructor.
-
-
Method Details
-
getProducerName
Gets the producer name. -
setProducerName
Sets the producer name that will be included in generated PDF documents. Usenullto disable.- Parameters:
producerName- The producer name ornull.
-
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 fontInputStreamsupplier. It shall not returnnull.
-
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:HtmlToPdfAConverterConverts the HTML content to its PDF/A representation, with a custom template.- Specified by:
convertin interfaceHtmlToPdfAConverter- Parameters:
lang- The document language, as an ISO code.contextVariables- The context variables to be added to the template processing. Note that a context variablelangis automatically added with the code value of the receivedlangparameter. 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 subjectauthor- a string with the document's authordescription- a string with the document's descriptionbookmarks- 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.
("Active Treatments", "#active-treatments")should be used to produce a bookmark to be rendered asActive Treatmentsthat would point to the HTML element with idactive-treatmentsin the processed template.
templateContent- The custom Thymeleaf content.- Returns:
- The content of the generated PDF/A.
-