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
Modifier and TypeClassDescriptionstatic final record
Record of a font declaration.static class
Implementation of a font cache. -
Constructor Summary
-
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[]
convert
(String subject, String author, String description, String title, NarrativeLanguage lang, Map<String, String> bookmarks, String cssContent, String bodyContent) Converts the HTML content to its PDF/A representation, with the default template.byte[]
convert
(String subject, String author, String description, String title, NarrativeLanguage lang, Map<String, String> bookmarks, String cssContent, String bodyContent, String templateContent) 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
Constructor.- Throws:
IOException
-
-
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(String subject, String author, String description, String title, NarrativeLanguage lang, Map<String, String> bookmarks, String cssContent, String bodyContent) throws IOExceptionConverts the HTML content to its PDF/A representation, with the default template.- Specified by:
convert
in interfaceHtmlToPdfAConverter
- 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 IOExceptionConverts 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.
-