Class PD4ML
- java.lang.Object
-
- org.zefer.pd4ml.PD4Constants
-
- org.zefer.pd4ml.PD4ML
-
public class PD4ML extends PD4Constants
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPD4ML.StatusMessage
-
Field Summary
Fields Modifier and Type Field Description booleanadjustHtmlWidthFlagbooleandebugbooleandisableHyperlinksFlagstatic StringFILE_ENCODINGbooleanfitPageVerticallybooleanfitPageVerticallyAndCenterstatic StringISO8859_1-
Fields inherited from class org.zefer.pd4ml.PD4Constants
A0, A1, A10, A2, A3, A4, A5, A6, A7, A8, A9, AllowAnnotate, AllowAssembly, AllowContentExtraction, AllowCopy, AllowDegradedPrint, AllowFillingForms, AllowModify, AllowPrint, ArchA, ArchB, ArchC, ArchD, ArchE, ArchE1, DefaultPermissions, HALFLETTER, ISOB0, ISOB1, ISOB2, ISOB3, ISOB4, ISOB5, LEDGER, LEGAL, LETTER, NOTE, PD4ML_ABSOLUTE_ADDRESS_SPACE, PD4ML_ALLOWED_RESOURCE_LOCATION, PD4ML_BACKGROUND_AS_PATTERNS, PD4ML_BASIC_AUTHENTICATION, PD4ML_CACHE_ENABLE, PD4ML_CACHE_IMAGES_IN_TMP_DIR, PD4ML_CONFIG_FILE, PD4ML_CONFIG_HANDLER_CLASS, PD4ML_CSS_IMPORT_DIRECTIVE, PD4ML_DISABLE_EXTERNAL_ATTACHMENTS, PD4ML_DOCUMENT_DATE, PD4ML_DOCUMENT_HEIGHT_PX, PD4ML_DOCUMENT_VIEW_MODE, PD4ML_DOCUMENT_XMP_DATE, PD4ML_ENABLE_CANVAS_INTERPRETER, PD4ML_ENABLE_HTTP_ERRORS, PD4ML_EXTERNAL_CANVAS_HANDLER, PD4ML_EXTRA_RESOURCE_LOADERS, PD4ML_FAKE_BROWSER, PD4ML_FIX20130116, PD4ML_FIX20150816, PD4ML_FORCE_RTL, PD4ML_GENERATE_TOOLTIPS, PD4ML_HEADER_HEIGHT_LIMIT, PD4ML_HTTP_PROXY, PD4ML_HTTP_REQUEST_DISPATCHER, PD4ML_IDS_AS_DESTINATIONS, PD4ML_IMAGE_REPOSITORY, PD4ML_INFO_AUTHOR, PD4ML_INFO_TITLE, PD4ML_INITIAL_PAGE_NUMBER, PD4ML_LEGACY_RTL_MODE, PD4ML_LEGACY_TEXT_BASELINE_COMPUTATION, PD4ML_MEDIA_TYPE_PRINT, PD4ML_MOBILE_DEVICE_OPTIMIZE, PD4ML_MOBILE_DEVICE_WIDTH, PD4ML_PDFA_STATUS, PD4ML_PRINT_DIALOG_POPUP, PD4ML_RIGHT_EDGE_PX, PD4ML_SESSIONID_APPEND, PD4ML_SESSIONID_VARNAME, PD4ML_SOCKET_TIMEOUT, PD4ML_STYLESHEETS_TO_OMIT, PD4ML_SUPPRESS_BLANK_PAGES, PD4ML_TOTAL_PAGES, PDF, PDFA, PNG24, PNG8, RTF, RTF_WMF, TABLOID, TIFF, TIFF_COMPRESSED, TRANSLATE_FACTOR
-
-
Constructor Summary
Constructors Constructor Description PD4ML()PD4ML Constructor Creates and initializes an instance of the rendering engine
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddDocumentActionHandler(String actionType, String javaScript)method defines JavaScript action handler for generated document.voidaddMetadata(String key, String value, boolean hide)The method defines custom properties for PDF document meta data.voidaddStyle(String stylesheet, boolean overrideDocumentStyles)Apply additional stylesheet to the documentvoidaddStyle(URL stylesheet, boolean overrideDocumentStyles)Apply additional stylesheet to the documentvoidadjustHtmlWidth()sets htmlWidth to the most right margin of the HTML block content.voidapplyKerning(boolean enable)Forces PD4ML to align font glyphs to each other according to the font kerning hints (if available).DimensionchangePageOrientation(Dimension d)rotates given page format by 90 degrees.
Make sure that after rotating of standard page formats from PD4Constants you pass the new dimensions to setPageSize() (not setPageSizeMM())voidclearCache()removes all objects (images, CSS, etc) from internal caches.static voiddebug(String str)debug() utility methodvoiddisableHyperlinks()if triggered, PD4ML does not generate active hyperlinks in resulting PDF.voidenableDebugInfo()enables an output of debug messages.voidenableImgSplit(boolean split)allows to disable image splitting by page breaks.voidenableLigatures(boolean enable)Forces PD4ML to load TTF/OTF glyph susbstitution tables, to apply ligature replacements and to build compound glyphs.voidenableRenderingPatch(boolean patch)Deprecated.no patching is neededvoidenableSmartTableBreaks(boolean enable)The method switches on/off the experimental table break feature.voidenableTableBreaks(boolean enable)Deprecated.voidfitPageVertically()forces PD4ML to downscale entire HTML layout to fit a single PDF page vertically.voidfitPageVertically(boolean center)voidgenerateMulticolumn(int columns, int span, boolean millimeters)switches PD4ML into multicolumn mode.voidgenerateOutlines(boolean fromHeadings)if triggered, than PD4ML generates PDF bookmarks (aka outlines).voidgeneratePdfa(boolean enable)Forces PD4ML to output PDF compliant with PDF/A specification.voidgeneratePdfForms(boolean enable, String useTtfFont)forces PD4ML to convert HTML forms into PDF forms (Acroforms).PD4CachegetCache()ObjectgetLastRenderInfo(String key)returns statistics for the last render() callstatic StringgetVersion()getVersion() returns current version numbervoidinterpolateImages(boolean mode)enables or disables image interpolationstatic booleanisDemoMode()returns true if the library is used in evaluation modestatic booleanisPro()returns true if it is Pro version of the libraryvoidmerge(InputStream input, int fromPage, int toPage, boolean append)Merges conversion result with an already existing PDF documentvoidmerge(Reader input, int fromPage, int toPage, boolean append)Merges conversion result with an already existing PDF documentvoidmonitorProgress(PD4ProgressListener listener)conversion progress callback supportvoidoutputFormat(String format)voidoutputFormat(String format, int width, int height)voidoutputRange(String description)voidoverrideDocumentEncoding(String encoding)sets default encoding for URL-addressed HTML documentsstatic intpredictPageHeight(Insets pageInsets, Dimension pageSize, int userSpace)static floatpredictScale(Insets pageInsets, Dimension pageSize, int userSpace)voidprotectPhysicalUnitDimensions()makes PD4ML to output PDF objects respecting dimensions/font sizes given in "in", "pt", "cm" etc.voidrender(InputStreamReader isr, OutputStream os)converts input data to PDFvoidrender(InputStreamReader isr, OutputStream os, URL base)converts input data to PDF.voidrender(StringReader[] isrs, OutputStream os, URL base)converts input data to PDFvoidrender(StringReader isr, OutputStream os)converts input data to PDFvoidrender(StringReader isr, OutputStream os, URL base)converts input data to PDFvoidrender(StringReader isr, OutputStream os, URL base, String encoding)converts input data to PDFvoidrender(String textUrl, OutputStream os)input data referred by URL to PDFvoidrender(URL[] urls, OutputStream os)converts input data referred by URLs to PDFvoidrender(URL url, OutputStream os)converts input data referred by URL to PDFBufferedImage[]renderAsImages(StringReader isr, URL base, int width, int height)BufferedImage[]renderAsImages(URL url, int width, int height)converts URL to image object(s)voidresetAddedStyles()Reset all styles added with PD4ML.addStyle()voidsetAuthorName(String name)sets an author name for the documentvoidsetCache(PD4Cache cacheWrapper)lets PD4ML to reuse data, cached by another PD4ML instance.voidsetCookie(String name, String value)makes PD4ML to add a cookie with given name and value to each URL connection requestvoidsetDefaultTTFs(String serif, String sansserif, String monospace)defines deafult TTF font faces to be used as substritutions for unknown fonts.voidsetDocumentTitle(String title)forces to override HTML titlevoidsetDynamicParams(Map dynamicParams)voidsetHtmlWidth(int width)defines desired HTML page width in screen pixels.voidsetPageFooter(PD4PageMark mark)defines page footer areavoidsetPageHeader(PD4PageMark mark)defines page header areavoidsetPageInsets(Insets ii)specifies page insets in pointsvoidsetPageInsetsMM(Insets ii)specifies page insets in millimeters.voidsetPageSize(Dimension d)defines page size in points.voidsetPageSizeMM(Dimension d)defines page size in milimeters.voidsetPermissions(String password, int permissions, boolean isStrong)forces the resulting document to be encrypted with the given passwordvoidsetSessionID(String sessionID)the method informs PD4ML about current session ID (in web application environments).static inttranslate(int i)converts from millimeters to pointsvoiduseAdobeFontMetrics(boolean use)Deprecated.always uses AFMvoiduseHttpRequest(Object httpRequest, Object httpResponse)method allows to inform PD4ML about actual HTTP request context (if any).voiduseHttpRequest(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse)Deprecated.binary compatibility with code compiled against earlier PD4ML versions only; the build marks it synthetic, so compilers do not see it.voiduseServletContext(Object ctx)method allows to inform PD4ML about actual servlet context (if any).voiduseServletContext(javax.servlet.ServletContext ctx)Deprecated.binary compatibility with code compiled against earlier PD4ML versions only; the build marks it synthetic, so compilers do not see it.voiduseTTF(String pathToFontDirs, boolean embed)enables TTF font embedding subsystem.voidutility(StringBuffer diags)Utility method used for testing
-
-
-
Field Detail
-
ISO8859_1
public static final String ISO8859_1
- See Also:
- Constant Field Values
-
FILE_ENCODING
public static final String FILE_ENCODING
- See Also:
- Constant Field Values
-
adjustHtmlWidthFlag
public boolean adjustHtmlWidthFlag
-
fitPageVertically
public boolean fitPageVertically
-
fitPageVerticallyAndCenter
public boolean fitPageVerticallyAndCenter
-
debug
public boolean debug
-
disableHyperlinksFlag
public boolean disableHyperlinksFlag
-
-
Method Detail
-
isDemoMode
public static final boolean isDemoMode()
returns true if the library is used in evaluation mode- Since:
- v1.1.0
-
isPro
public static final boolean isPro()
returns true if it is Pro version of the library- Since:
- v3.8.1
-
getVersion
public static String getVersion()
getVersion() returns current version number- Returns:
- version number formatted as a string
-
merge
public void merge(InputStream input, int fromPage, int toPage, boolean append)
Merges conversion result with an already existing PDF document- Parameters:
input- PDF document input streamfromPage- start page of the existing document (1 or greater)toPage- end page of the existing document (-1 means all pages)append- 'true' forces to append the existing PDF to the conversion result. Otherwise the existing document will lead the conversion result.- Since:
- v3.8 *Pro*
-
merge
public void merge(Reader input, int fromPage, int toPage, boolean append)
Merges conversion result with an already existing PDF document- Parameters:
input- PDF document readerfromPage- start page of the existing document (1 or greater)toPage- end page of the existing document (-1 means all pages)append- 'true' forces to append the existing PDF to the conversion result. Otherwise the existing document will lead the conversion result.- Since:
- v3.8 *Pro*
-
render
public void render(InputStreamReader isr, OutputStream os) throws InvalidParameterException, IOException
converts input data to PDF- Parameters:
isr- input stream reader of formatted data. Relies to properly specified encoding.os- output stream to generate PDF to- Throws:
InvalidParameterException- the input or output stream is nullIOException- input/output problems
-
render
public void render(StringReader isr, OutputStream os) throws InvalidParameterException, IOException
converts input data to PDF- Parameters:
isr- string reader of formatted data. Relies to properly specified encoding.os- output stream to generate PDF to- Throws:
InvalidParameterException- the input or output stream is nullIOException- input/output problems
-
render
public void render(InputStreamReader isr, OutputStream os, URL base) throws InvalidParameterException, IOException
converts input data to PDF.- Parameters:
isr- input stream reader of formatted data. Relies to properly specified encoding.os- output stream to generate PDF tobase- base URL to lookup referred resources like images or CSS. Can be specified in HTML body with <base href="..."> tag- Throws:
InvalidParameterException- the input or output stream is nullIOException- input/output problems
-
render
public void render(StringReader isr, OutputStream os, URL base, String encoding) throws InvalidParameterException, IOException
converts input data to PDF- Parameters:
isr- string reader of formatted data. Take care for proper encodingos- output stream to generate PDF tobase- base URL to lookup referred resources like images or CSS. Can be specified in HTML body with <base href="..."> tagencoding- content encoding- Throws:
InvalidParameterException- the input or output stream is nullIOException- input/output problems
-
render
public void render(StringReader isr, OutputStream os, URL base) throws InvalidParameterException, IOException
converts input data to PDF- Parameters:
isr- string reader of formatted data. Take care for proper encodingos- output stream to generate PDF tobase- base URL to lookup referred resources like images or CSS. Can be specified in HTML body with <base href="..."> tag- Throws:
InvalidParameterException- the input or output stream is nullIOException- input/output problems
-
render
public void render(StringReader[] isrs, OutputStream os, URL base) throws InvalidParameterException, IOException
converts input data to PDF- Parameters:
isrs- array of string readers wrap formatted data. Take care for proper encodingos- output stream to generate PDF tobase- base URL to lookup referred resources like images or CSS. Can be specified in HTML body with <base href="..."> tag- Throws:
InvalidParameterException- the input or output stream is nullIOException- input/output problems
-
render
public void render(String textUrl, OutputStream os) throws MalformedURLException, InvalidParameterException, IOException
input data referred by URL to PDF- Parameters:
textUrl- text representation of the input data URLos- output stream to generate PDF to- Throws:
MalformedURLException- invalid URLInvalidParameterException- the input or output stream is nullIOException- input/output problems
-
render
public void render(URL url, OutputStream os) throws InvalidParameterException, IOException
converts input data referred by URL to PDF- Parameters:
url- input data URLos- output stream to generate PDF to- Throws:
MalformedURLException- invalid URLInvalidParameterException- the input or output stream is nullIOException- input/output problems
-
render
public void render(URL[] urls, OutputStream os) throws InvalidParameterException, IOException
converts input data referred by URLs to PDF- Parameters:
urls- input data URLsos- output stream to generate PDF to- Throws:
MalformedURLException- invalid URLInvalidParameterException- the input or output stream is nullIOException- input/output problems
-
enableDebugInfo
public void enableDebugInfo()
enables an output of debug messages. (absolute paths to loaded images and TTF)- Since:
- v1.2.0
-
useTTF
public void useTTF(String pathToFontDirs, boolean embed) throws FileNotFoundException
enables TTF font embedding subsystem. Available only in professional version of PD4ML.- Parameters:
embed- if true forces PD4ML to include used font glyphs to the resulting PDFpathToFontDirs- URL of a font directory.The font directory should contain pd4fonts.properties mapping file. The file records have the following format:
In order to support J2EE deployments a PD4ML-specific protocol "java:" is supported to load font resources via ClassLoader.
font_name=file_name
- font_name - font name used in the source HTML.
- file_name - font file name (should exist in the font directory)
Example:
Book\ Antiqua=BKANT.TTF
To generate the file automatically you may use the command line call:
java -jar pd4ml.jar -configure.fonts <fontdir>
After the generation, please edit the file and remove manually all references to the fonts, that are not allowed to be redistributed. Contact your TTF fonts provider for the info.Example: useTTF( "java:myfonts", true );
In that case the runtime looks for a fonts folder named "/myfonts" in all JAR files available for the application class loaders. The content of the folder should correspond to the rules described above: pd4fonts.properties + *.ttf
Example: useTTF( "java:", true );
The simpliest case. The runtime looks for a JAR file which contains pd4fonts.properties + *.ttf in the root directory.
- Throws:
FileNotFoundException- if pd4fonts.properties file is not found or the file refers to missing font files
-
applyKerning
public void applyKerning(boolean enable)
Forces PD4ML to align font glyphs to each other according to the font kerning hints (if available). The API call takes effect only by PDF generation.- Parameters:
enable- - enables the feature
-
enableLigatures
public void enableLigatures(boolean enable)
Forces PD4ML to load TTF/OTF glyph susbstitution tables, to apply ligature replacements and to build compound glyphs. The feature requires pd4ml_fonttool.jar- Parameters:
enable- - enables the feature
-
generatePdfForms
public void generatePdfForms(boolean enable, String useTtfFont)forces PD4ML to convert HTML forms into PDF forms (Acroforms). Note: The feature is at a very early stage now (v3.2.3).- Parameters:
useTtfFont- (not implemented yet) - UNICODE TTF font name to be used for form input. The name must appear in pd4fonts.propertiesenable- enables or disables the feature- Since:
- v3.2.3 Pro
- See Also:
useTTF(String, boolean)
-
generateMulticolumn
public void generateMulticolumn(int columns, int span, boolean millimeters)switches PD4ML into multicolumn mode. The mode in not compatible with adjustHtmlWidth() and fitPageVertically() calls.- Parameters:
columns- - number of columns per pagespan- - space between the columnsmillimeters- - if 'true' the gap is in millimeters, otherwise in points
-
useServletContext
public void useServletContext(Object ctx)
method allows to inform PD4ML about actual servlet context (if any). An access to servlet context allows to resolve absolute resource paths.- Parameters:
ctx- servlet context: a javax.servlet.ServletContext (Java EE) or a jakarta.servlet.ServletContext (Jakarta EE 9 and newer)
-
useServletContext
public void useServletContext(javax.servlet.ServletContext ctx)
Deprecated.binary compatibility with code compiled against earlier PD4ML versions only; the build marks it synthetic, so compilers do not see it. UseuseServletContext(Object).
-
useHttpRequest
public void useHttpRequest(Object httpRequest, Object httpResponse)
method allows to inform PD4ML about actual HTTP request context (if any). HTTP request/response allows to get output of dynamic webapp resources. Takes the javax.servlet (Java EE) or the jakarta.servlet (Jakarta EE 9 and newer) request and response.- Parameters:
httpRequest- actual HTTP request: javax.servlet.http.HttpServletRequest or jakarta.servlet.http.HttpServletRequesthttpResponse- actual HTTP response: javax.servlet.http.HttpServletResponse or jakarta.servlet.http.HttpServletResponse
-
useHttpRequest
public void useHttpRequest(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse)Deprecated.binary compatibility with code compiled against earlier PD4ML versions only; the build marks it synthetic, so compilers do not see it. UseuseHttpRequest(Object, Object).
-
setDefaultTTFs
public void setDefaultTTFs(String serif, String sansserif, String monospace)
defines deafult TTF font faces to be used as substritutions for unknown fonts.- Parameters:
serif- - plain font face for serif fonts (like Times New Roman)sansserif- - plain font face for sansserif fonts (like Helvetica or Arial)monospace- - plain font face for monospace fonts (like Courier New)- Since:
- 3.0.2
-
enableRenderingPatch
public void enableRenderingPatch(boolean patch)
Deprecated.no patching is neededenables or disables a patch of the Swing HTML rendering engine. The patch solves some visual problems with unknown tags and corrupted representation of XHTML files. By default the patch is enabled.- Parameters:
patch- boolean switch
-
useAdobeFontMetrics
public void useAdobeFontMetrics(boolean use)
Deprecated.always uses AFMif set to true, it forces PD4ML to use Adobe font glyph widths instead of the font metrics provided by Java graphical environment. As a result HTML page layout can look broken in GUI (in PD4ML Browser/Converter; for instance, text strings can overlap each other), but resulting PDF is rendered usually more correctly.- Parameters:
use- boolean switch- Since:
- v1.1.0
-
generateOutlines
public void generateOutlines(boolean fromHeadings)
if triggered, than PD4ML generates PDF bookmarks (aka outlines).- Parameters:
fromHeadings- if set to false, PD4ML creates PDF bookmarks taken from <a name="destination">Label</a> tags. If a label is not defined, it uses destination string as visible label.
if set to true, than PD4ML creates PDF bookmark tree structure derived from <H1>-<H6> structure.- Since:
- v1.2.0
-
setSessionID
public void setSessionID(String sessionID)
the method informs PD4ML about current session ID (in web application environments). The session ID is implicitely added by PD4ML to resource references (CSS, image etc). The addition is done in the following form: "resource.jpg;jsessionid=<sessionID>?other_args". "jsessionid" reserved name can be overriden by a setting of "pd4ml.sessionid.varname" environment variable- Parameters:
sessionID- actual session ID- Since:
- v3.0.0.b1
-
overrideDocumentEncoding
public void overrideDocumentEncoding(String encoding)
sets default encoding for URL-addressed HTML documents- Parameters:
encoding- name- Since:
- v3.7.1
-
disableHyperlinks
public void disableHyperlinks()
if triggered, PD4ML does not generate active hyperlinks in resulting PDF.- Since:
- v1.2.0
-
enableImgSplit
public void enableImgSplit(boolean split)
allows to disable image splitting by page breaks. By default the option is true (splitting enabled). If the option is set to false, than PD4ML tries to put page breaks protecting the images. If an image height (in screen pixels) is bigger than computed page height (in screen pixels), than it will be splitted regardless the option.- Parameters:
split- boolean switch- See Also:
setHtmlWidth(int)
-
enableTableBreaks
public void enableTableBreaks(boolean enable)
Deprecated.UseenableSmartTableBreaks(boolean)instead- Since:
- v2.2.0b1/1.2.6/3.1.0
-
enableSmartTableBreaks
public void enableSmartTableBreaks(boolean enable)
The method switches on/off the experimental table break feature. If it set to true, PD4ML tries to insert page breaks inbetween table rows to make the table portions fit PDF page height. If the table has a header (the first row with <th> cells only) it replicates the row to each table section. In order avoid multi-pass re-layouting of source HTML, the feature is implemented by simple way and has its limitations: it does not support nested tables, multi-page rowspans etc. As long as the feature experimental please use it in production only with extensively tested HTML templates.- Since:
- v3.6.1b2
-
setPageHeader
public void setPageHeader(PD4PageMark mark) throws InvalidParameterException
defines page header area- Parameters:
mark- header configuration object- Throws:
InvalidParameterException- when the config is null- Since:
- v1.0.5
-
setPageFooter
public void setPageFooter(PD4PageMark mark) throws InvalidParameterException
defines page footer area- Parameters:
mark- footer configuration object- Throws:
InvalidParameterException- when the config is null or contains invalid data- Since:
- v1.0.5
-
setPageSizeMM
public void setPageSizeMM(Dimension d) throws InvalidParameterException
defines page size in milimeters. The method internally converts sizes to points and calls setPageSize()- Parameters:
d- page dimensions in mm- Throws:
InvalidParameterException- See Also:
setPageSize(Dimension)
-
setPermissions
public void setPermissions(String password, int permissions, boolean isStrong)
forces the resulting document to be encrypted with the given password- Parameters:
password- password. If is set to "empty", than no password assigned to document, only permissions.permissions- an integer value according to PDF encryption specificationisStrong- selects between two type of PDF encryption: type2 (false) and type3 (true)- Since:
- v1.1.0
-
setCookie
public void setCookie(String name, String value)
makes PD4ML to add a cookie with given name and value to each URL connection request- Parameters:
name- namevalue- value- Since:
- v3.0.2
-
addDocumentActionHandler
public void addDocumentActionHandler(String actionType, String javaScript)
method defines JavaScript action handler for generated document.- Parameters:
actionType- "OpenAction", "DC" (document close), "WS" (will save), "DS" (did save), "WP" (will print) or "DP" (did print)javaScript- handler code
-
setPageSize
public void setPageSize(Dimension d) throws InvalidParameterException
defines page size in points. A set of predefined page format constants is available in the PD4Constants interface.
To get "Landscape" page orientation of of the constant page sizes use changePageOrientation() method call to landscape convert the- Parameters:
d- page dimensions in points- Throws:
InvalidParameterException- See Also:
changePageOrientation(Dimension)
-
setPageInsetsMM
public void setPageInsetsMM(Insets ii) throws InvalidParameterException
specifies page insets in millimeters. The method internally converts sizes to points and calls setPageInsets()- Parameters:
ii- page insets in millimeters- Throws:
InvalidParameterException- See Also:
setPageInsets(Insets)
-
setPageInsets
public void setPageInsets(Insets ii) throws InvalidParameterException
specifies page insets in points- Parameters:
ii- page insets in points- Throws:
InvalidParameterException
-
setHtmlWidth
public void setHtmlWidth(int width) throws InvalidParameterExceptiondefines desired HTML page width in screen pixels. Virtually it can be seen as a web browser window horizonltal resize.
In the resulting PDF the HTML width is mapped to the paper page width (minus insets). There is no way to specify HTML page height. The height in screen pixels is set automatically depending on the width and the paper page proportions.- Parameters:
width- HTML width in screen pixels- Throws:
InvalidParameterException- when the width is not a positive value great that 0.
-
adjustHtmlWidth
public void adjustHtmlWidth()
sets htmlWidth to the most right margin of the HTML block content. Calling the method would force PD4ML to build HTML layout with htmlWidth set by setHtmlWidth(int), to determine the most right edge of rendered content and to use the value for PDF mapping. Notes:- The method takes no effect for multi-URL PD4ML call: render(URL[],OutputStream)
- In order to use the method efficiently, it is important to call setHtmlWidth(int) with a parameter value, which is greater than the expected right edge offset.
- If the source document has HTML objects, whose width is set to 100%, than the method call is meaningless.
- As long as htmlWidth affects HTML-to-PDF scale factor, usage of the method causes inconstancy of font/object sizes in the resulting PDF from document to document.
- Since:
- 3.0.2
-
fitPageVertically
public void fitPageVertically()
forces PD4ML to downscale entire HTML layout to fit a single PDF page vertically.- Since:
- v3.0.4
-
fitPageVertically
public void fitPageVertically(boolean center)
-
generatePdfa
public final void generatePdfa(boolean enable)
Forces PD4ML to output PDF compliant with PDF/A specification. PDF/A specification requires all used fonts to be embedded to the resulting document. So the method call cannot guarantee the resulting doc is PDF/A, for example, if TTF embedding is disabled or not configured. To make sure a resulting document matches PDF/A requirements, request the last rendering status.- Since:
- v3.6.0
- See Also:
PD4Constants.PD4ML_PDFA_STATUS,getLastRenderInfo(String)
-
protectPhysicalUnitDimensions
public void protectPhysicalUnitDimensions()
makes PD4ML to output PDF objects respecting dimensions/font sizes given in "in", "pt", "cm" etc. Use the method carefully: as long as it triggered, there is no single HTML-to-PDF scale factor for all HTML objects. The resulting PDF layout may appear visually corrupted. If the method is not triggered, all sizes given in physical measurement units are converted to their screen pixel equivalents (using 72dpi) before HTML layouting. The method call can not be combined with adjustHtmlWidth() and fitPageVertically() calls, which affect HTML-to-PDF scale factor their own way.- Since:
- v3.0.4
-
interpolateImages
public final void interpolateImages(boolean mode)
enables or disables image interpolation- Parameters:
mode- true - enables interpolation. default is false- Since:
- v1.0.5
-
setAuthorName
public final void setAuthorName(String name)
sets an author name for the document- Parameters:
name- author's name- Since:
- v1.0.5
-
setDocumentTitle
public final void setDocumentTitle(String title)
forces to override HTML title- Parameters:
title- document title- Since:
- v1.0.5
-
addStyle
public final void addStyle(URL stylesheet, boolean overrideDocumentStyles) throws InvalidParameterException
Apply additional stylesheet to the document- Parameters:
stylesheet- of css stylesheetoverrideDocumentStyles- if true, applies the stylesheet after styles defined in the document header.- Throws:
InvalidParameterException- too many styles added- Since:
- v3.1.0 Pro
-
addStyle
public final void addStyle(String stylesheet, boolean overrideDocumentStyles) throws InvalidParameterException
Apply additional stylesheet to the document- Parameters:
stylesheet- stylesheet contentoverrideDocumentStyles- if true, applies the stylesheet after styles defined in the document header.- Throws:
InvalidParameterException- too many styles added- Since:
- v3.1.0 Pro
-
resetAddedStyles
public final void resetAddedStyles()
Reset all styles added with PD4ML.addStyle()- Since:
- v3.1.0 Pro
-
renderAsImages
public BufferedImage[] renderAsImages(URL url, int width, int height) throws IOException
converts URL to image object(s)- Parameters:
width- target image widthheight- target image height- Returns:
- an array of buffered images, represent a page.
- Throws:
IOException
-
renderAsImages
public BufferedImage[] renderAsImages(StringReader isr, URL base, int width, int height) throws IOException
- Parameters:
isr- string reader of formatted data. Take care for proper encodingbase- base URL to lookup referred resources like images or CSS. Can be specified in HTML body with <base href="..."> tagwidth- target image widthheight- target image height- Returns:
- an array of buffered images, represent a page.
- Throws:
IOException
-
debug
public static void debug(String str)
debug() utility method- Parameters:
str- debug message
-
translate
public static final int translate(int i)
converts from millimeters to points- Parameters:
i- value in millimeters
-
changePageOrientation
public Dimension changePageOrientation(Dimension d)
rotates given page format by 90 degrees.
Make sure that after rotating of standard page formats from PD4Constants you pass the new dimensions to setPageSize() (not setPageSizeMM())- Parameters:
d- original page dimension- Returns:
- modified page dimensions
-
predictScale
public static final float predictScale(Insets pageInsets, Dimension pageSize, int userSpace)
-
predictPageHeight
public static final int predictPageHeight(Insets pageInsets, Dimension pageSize, int userSpace)
-
setDynamicParams
public void setDynamicParams(Map dynamicParams)
- Parameters:
dynamicParams- a set of key/value (String/String) pairs to dynamically substitute placeholders in HTML template (like "$[key]"). Key names "page", "total" and "title" are reserved for PDF headers and footers.
-
getLastRenderInfo
public Object getLastRenderInfo(String key)
returns statistics for the last render() call- Parameters:
key- - one of the currently supported keys: "pd4ml.document.height.px", "pd4ml.right.edge.px" or "pd4ml.total.pages".- Returns:
- Long object (for the currently implemented keys; other types expected in the future)
- Since:
- 3.5.1
- See Also:
PD4Constants
-
outputRange
public void outputRange(String description)
- Parameters:
description- a string with output rules. Currently allows to limit a scope of generated pages. Examples: "2+" - skip the first page, "1-2" - output only the first and the second pages, "even" or "odd" - it is obvious. The rules may be combined: "3-7,odd"- Since:
- v3.5.5
-
outputFormat
public void outputFormat(String format)
- Parameters:
format- file format to output. PD4Constants.PDF - default.- Since:
- v3.7.0
-
outputFormat
public void outputFormat(String format, int width, int height)
- Parameters:
format- file format to output. PD4Constants.PDF - default.height- - limits resulting document simentions by height. relevant for HTML-to-image conversions onlywidth- - limits resulting document simentions by width. relevant for HTML-to-image conversions only- Since:
- v3.7.1
-
addMetadata
public void addMetadata(String key, String value, boolean hide)
The method defines custom properties for PDF document meta data. The method takes effect only in PD4ML Volume DMS and PD4ML SRC license binaries.- Parameters:
key- a unique name, which must not be one of the standard property names Title, Author, Subject, Keywords, Creator, Producer, CreationDate, ModDate and Trappedvalue- data itselfhide- makes the metadata not appear in the PDF document properties dialog of Acroread
-
clearCache
public void clearCache()
removes all objects (images, CSS, etc) from internal caches.- Since:
- v3.6.0fx1
-
getCache
public PD4Cache getCache()
- Returns:
- wrapped PD4ML cache to be reused
- Since:
- v3.6.1b2
- See Also:
setCache(PD4Cache)
-
setCache
public void setCache(PD4Cache cacheWrapper)
lets PD4ML to reuse data, cached by another PD4ML instance. PD4ML caches data in static hash tables, which implicitly share the cached data amonth PD4ML instances. The method call makes only sence if the tables are garbage collected for some reasons.- Since:
- v3.6.1b2
- See Also:
getCache()
-
utility
public void utility(StringBuffer diags)
Utility method used for testing- Parameters:
diags- string buffer to write to
-
monitorProgress
public void monitorProgress(PD4ProgressListener listener)
conversion progress callback support- Parameters:
listener- receiver of progress update messages
-
-