Package com.openhtmltopdf.pdfboxout
Class PdfRendererBuilder
- java.lang.Object
-
- com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder<PdfRendererBuilder,PdfRendererBuilderState>
-
- com.openhtmltopdf.pdfboxout.PdfRendererBuilder
-
public class PdfRendererBuilder extends com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder<PdfRendererBuilder,PdfRendererBuilderState>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPdfRendererBuilder.CacheStoreList of caches available.static classPdfRendererBuilder.PdfAConformanceVarious level of PDF/A conformance: PDF/A-1, PDF/A-2 and PDF/A-3-
Nested classes/interfaces inherited from class com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder
com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.BaseRendererBuilderState, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.PageSizeUnits, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.TextDirection
-
-
Constructor Summary
Constructors Constructor Description PdfRendererBuilder()
-
Method Summary
Modifier and Type Method Description PdfBoxRendererbuildPdfRenderer()Build a PdfBoxRenderer for further customization.voidrun()Run the XHTML/XML to PDF conversion and output to an output stream set by toStream.PdfRendererBuildertoStream(OutputStream out)An output stream to output the resulting PDF.PdfRendererBuilderuseCacheStore(PdfRendererBuilder.CacheStore which, com.openhtmltopdf.extend.FSCacheEx<String,com.openhtmltopdf.extend.FSCacheValue> cache)Use a specific cache.PdfRendererBuilderuseColorProfile(byte[] colorProfile)Sets the color profile, needed for PDF/A conformance.PdfRendererBuilderuseFont(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamily)Simpler overload foruseFont(FSSupplier, String, Integer, FontStyle, boolean)PdfRendererBuilderuseFont(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamily, Integer fontWeight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle fontStyle, boolean subset)Add a font programmatically.PdfRendererBuilderuseFont(File fontFile, String fontFamily)Simpler overload foruseFont(File, String, Integer, FontStyle, boolean)PdfRendererBuilderuseFont(File fontFile, String fontFamily, Integer fontWeight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle fontStyle, boolean subset)LikeuseFont(FSSupplier, String, Integer, FontStyle, boolean), but allows to supply a font file.PdfRendererBuilderusePageSupplier(PageSupplier pageSupplier)Set a PageSupplier that is called whenever a new page is needed.PdfRendererBuilderusePDDocument(org.apache.pdfbox.pdmodel.PDDocument doc)By default, this project creates an entirely in-memoryPDDocument.PdfRendererBuilderusePdfAConformance(PdfRendererBuilder.PdfAConformance pdfAConformance)Set the PDF/A conformance, typically we use PDF/A-1 Note: PDF/A documents require fonts to be embedded.PdfRendererBuilderusePdfUaAccessbility(boolean pdfUaAccessibility)Whether to conform to PDF/UA or Accessible PDF.PdfRendererBuilderusePdfVersion(float version)Set the PDF version, typically we use 1.7.PdfRendererBuilderwithProducer(String producer)Set a producer on the output document-
Methods inherited from class com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder
addDOMMutator, defaultTextDirection, testMode, useDefaultPageSize, useDocumentBuilderFactoryImplementationClass, useFastMode, useHttpStreamImplementation, useMathMLDrawer, useObjectDrawerFactory, useProtocolsStreamImplementation, useProtocolsStreamImplementation, useReplacementText, useSVGDrawer, useTransformerFactoryImplementationClass, useUnicodeBidiReorderer, useUnicodeBidiSplitter, useUnicodeCharacterBreaker, useUnicodeLineBreaker, useUnicodeToLowerTransformer, useUnicodeToTitleTransformer, useUnicodeToUpperTransformer, useUriResolver, withFile, withHtmlContent, withUri, withW3cDocument
-
-
-
-
Method Detail
-
run
public void run() throws ExceptionRun the XHTML/XML to PDF conversion and output to an output stream set by toStream.- Throws:
Exception
-
buildPdfRenderer
public PdfBoxRenderer buildPdfRenderer()
Build a PdfBoxRenderer for further customization. Remember to callPdfBoxRenderer.cleanup()after use.- Returns:
-
toStream
public PdfRendererBuilder toStream(OutputStream out)
An output stream to output the resulting PDF. The caller is required to close the output stream after calling run.- Parameters:
out-- Returns:
-
usePdfVersion
public PdfRendererBuilder usePdfVersion(float version)
Set the PDF version, typically we use 1.7. If you set a lower version, it is your responsibility to make sure no more recent PDF features are used.- Parameters:
version-- Returns:
-
usePdfAConformance
public PdfRendererBuilder usePdfAConformance(PdfRendererBuilder.PdfAConformance pdfAConformance)
Set the PDF/A conformance, typically we use PDF/A-1 Note: PDF/A documents require fonts to be embedded. So if this is not set to NONE, the built-in fonts will not be available and currently any text without a specified and embedded font will cause the renderer to crash with an exception.- Parameters:
pdfAConformance-- Returns:
-
usePdfUaAccessbility
public PdfRendererBuilder usePdfUaAccessbility(boolean pdfUaAccessibility)
Whether to conform to PDF/UA or Accessible PDF. False by default.- Parameters:
pdfUaAccessibility-- Returns:
- this for method chaining
-
useColorProfile
public PdfRendererBuilder useColorProfile(byte[] colorProfile)
Sets the color profile, needed for PDF/A conformance. You can use the sRGB.icc from https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/resources/pdfa/- Parameters:
colorProfile-- Returns:
-
usePDDocument
public PdfRendererBuilder usePDDocument(org.apache.pdfbox.pdmodel.PDDocument doc)
By default, this project creates an entirely in-memoryPDDocument. The user can use this method to create a document either entirely on-disk or a mix of in-memory and on-disk using thePDDocumentconstructor that takes aMemoryUsageSetting.- Parameters:
doc- a (usually empty) PDDocument- Returns:
- this for method chaining
-
useFont
public PdfRendererBuilder useFont(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamily, Integer fontWeight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle fontStyle, boolean subset)
Add a font programmatically. If the font is NOT subset, it will be downloaded when the renderer is run, otherwise the font will only be downloaded if needed. Therefore, the user could add many fonts, confidant that only those that are used will be downloaded and processed. The InputStream returned by the supplier will be closed by the caller. Fonts should generally be subset, except when used in form controls. FSSupplier is a lambda compatible interface. Fonts can also be added using a font-face at-rule in the CSS.- Parameters:
supplier-fontFamily-fontWeight-fontStyle-subset-- Returns:
-
useFont
public PdfRendererBuilder useFont(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamily)
Simpler overload foruseFont(FSSupplier, String, Integer, FontStyle, boolean)- Parameters:
supplier-fontFamily-- Returns:
-
useFont
public PdfRendererBuilder useFont(File fontFile, String fontFamily, Integer fontWeight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle fontStyle, boolean subset)
LikeuseFont(FSSupplier, String, Integer, FontStyle, boolean), but allows to supply a font file. If the font file is a .ttc file it is handled as TrueTypeCollection. If you have the font in file form you should use this API.
-
useFont
public PdfRendererBuilder useFont(File fontFile, String fontFamily)
Simpler overload foruseFont(File, String, Integer, FontStyle, boolean)- Parameters:
fontFile-fontFamily-- Returns:
-
withProducer
public PdfRendererBuilder withProducer(String producer)
Set a producer on the output document- Parameters:
producer- the name of the producer to set defaults to openhtmltopdf.com- Returns:
- this for method chaining
-
useCacheStore
public PdfRendererBuilder useCacheStore(PdfRendererBuilder.CacheStore which, com.openhtmltopdf.extend.FSCacheEx<String,com.openhtmltopdf.extend.FSCacheValue> cache)
Use a specific cache. Cache values should be thread safe, so provided your cache store itself is thread safe can be used accross threads.- Returns:
- this for method chaining.
- See Also:
PdfRendererBuilder.CacheStore
-
usePageSupplier
public PdfRendererBuilder usePageSupplier(PageSupplier pageSupplier)
Set a PageSupplier that is called whenever a new page is needed.- Parameters:
pageSupplier-PageSupplierto use- Returns:
- this for method chaining.
-
-