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 record
Record of a font declaration.static class
Implementation of a font cache. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFont
(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 String
Gets the producer name.void
setPdfRendererBuilderConsumer
(@Nullable Consumer<com.openhtmltopdf.pdfboxout.PdfRendererBuilder> pdfRendererBuilderConsumer) void
setProducerName
(@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. Usenull
to 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 fontInputStream
supplier. 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:HtmlToPdfAConverter
Converts the HTML content to its PDF/A representation, with a custom template.- Specified by:
convert
in 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 variablelang
is automatically added with the code value of the receivedlang
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 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 Treatments
that would point to the HTML element with idactive-treatments
in the processed template.
templateContent
- The custom Thymeleaf content.- Returns:
- The content of the generated PDF/A.
-