public class PD4ML extends PD4Constants
Modifier and Type | Class and Description |
---|---|
static class |
PD4ML.StatusMessage |
Modifier and Type | Field and Description |
---|---|
PD4ML |
pd4mlNew |
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_ENABLE_CANVAS_INTERPRETER, PD4ML_ENABLE_HTTP_ERRORS, PD4ML_EXTERNAL_CANVAS_HANDLER, PD4ML_EXTRA_RESOURCE_LOADERS, PD4ML_FAKE_BROWSER, PD4ML_FIX20130116, 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_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_STYLESHEETS_TO_OMIT, PD4ML_TOTAL_PAGES, PDF, PDFA, PDFUA, PNG24, PNG8, RTF, RTF_WMF, TABLOID, TIFF, TIFF_COMPRESSED, TRANSLATE_FACTOR
Constructor and Description |
---|
PD4ML()
PD4ML Constructor
Creates and initializes an instance of the rendering engine
|
Modifier and Type | Method and Description |
---|---|
void |
addDocumentActionHandler(String actionType,
String javaScript)
method defines JavaScript action handler for generated document.
|
void |
addMetadata(String key,
String value,
boolean hide)
The method defines custom properties for PDF document meta data.
|
void |
addStyle(String stylesheet,
boolean overrideDocumentStyles)
Apply additional stylesheet to the document
|
void |
addStyle(URL stylesheet,
boolean overrideDocumentStyles)
Apply additional stylesheet to the document
|
void |
adjustHtmlWidth()
sets htmlWidth to the most right margin of the HTML block content.
|
void |
applyKerning(boolean enable)
Forces PD4ML to align font glyphs to each other according to the font kerning hints (if available).
|
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()) |
void |
clearCache()
removes all objects (images, CSS, etc) from internal caches.
|
static void |
debug(String str)
debug() utility method
|
void |
disableHyperlinks()
if triggered, PD4ML does not generate active hyperlinks in
resulting PDF.
|
void |
enableDebugInfo()
enables an output of debug messages.
|
void |
enableImgSplit(boolean split)
allows to disable image splitting by page breaks.
|
void |
enableRenderingPatch(boolean patch)
Deprecated.
no patching is needed
|
void |
enableSmartTableBreaks(boolean enable)
The method switches on/off the experimental table break feature.
|
void |
enableTableBreaks(boolean enable)
Deprecated.
|
void |
fitPageVertically()
forces PD4ML to downscale entire HTML layout to fit a single PDF page vertically.
|
void |
generateMulticolumn(int columns,
int span,
boolean millimeters)
switches PD4ML into multicolumn mode.
|
void |
generateOutlines(boolean fromHeadings)
if triggered, than PD4ML generates PDF bookmarks (aka outlines).
|
void |
generatePdfa(boolean enable)
Forces PD4ML to output PDF compliant with PDF/A specification.
|
void |
generatePdfForms(boolean enable,
String useTtfFont)
forces PD4ML to convert HTML forms into PDF forms (Acroforms).
|
PD4Cache |
getCache() |
Object |
getLastRenderInfo(String key)
returns statistics for the last render() call
|
static String |
getVersion()
getVersion() returns current version number
|
void |
interpolateImages(boolean mode)
enables or disables image interpolation
|
static boolean |
isDemoMode() |
static boolean |
isPro() |
static String |
legacyHeaderToHtml(PD4PageMark pageMark,
boolean header) |
void |
merge(InputStream input,
int fromPage,
int toPage,
boolean append)
Merges conversion result with an already existing PDF document
|
void |
merge(Reader input,
int fromPage,
int toPage,
boolean append)
Merges conversion result with an already existing PDF document
|
void |
monitorProgress(PD4ProgressListener listener)
conversion progress callback support
|
void |
outputFormat(String format) |
void |
outputFormat(String format,
int width,
int height) |
void |
outputRange(String description) |
void |
overrideDocumentEncoding(String encoding)
sets default encoding for URL-addressed HTML documents
|
static int |
predictPageHeight(Insets pageInsets,
Dimension pageSize,
int userSpace) |
static float |
predictScale(Insets pageInsets,
Dimension pageSize,
int userSpace) |
void |
protectPhysicalUnitDimensions()
makes PD4ML to output PDF objects respecting dimensions/font sizes given in "in", "pt", "cm" etc.
|
void |
render(InputStreamReader isr,
OutputStream os)
converts input data to PDF
|
void |
render(InputStreamReader isr,
OutputStream os,
URL base)
converts input data to PDF.
|
void |
render(String textUrl,
OutputStream os)
input data referred by URL to PDF
|
void |
render(StringReader[] isrs,
OutputStream os,
URL base)
converts input data to PDF
|
void |
render(StringReader isr,
OutputStream os)
converts input data to PDF
|
void |
render(StringReader isr,
OutputStream os,
URL base)
converts input data to PDF
|
void |
render(StringReader isr,
OutputStream os,
URL base,
String encoding)
converts input data to PDF
|
void |
render(URL[] urls,
OutputStream os)
converts input data referred by URLs to PDF
|
void |
render(URL url,
OutputStream os)
converts input data referred by URL to PDF
|
BufferedImage[] |
renderAsImages(StringReader isr,
URL base,
int width,
int height) |
BufferedImage[] |
renderAsImages(URL url,
int width,
int height)
converts URL to image object(s)
|
void |
resetAddedStyles()
Reset all styles added with PD4ML.addStyle()
|
void |
setAuthorName(String name)
sets an author name for the document
|
void |
setCache(PD4Cache cacheWrapper)
lets PD4ML to reuse data, cached by another PD4ML instance.
|
void |
setCookie(String name,
String value)
makes PD4ML to add a cookie with given name and value to each URL connection request
|
void |
setDefaultTTFs(String serif,
String sansserif,
String monospace)
defines deafult TTF font faces to be used as substritutions for unknown fonts.
|
void |
setDocumentTitle(String title)
forces to override HTML title
|
void |
setDynamicParams(Map dynamicParams) |
void |
setHtmlWidth(int width)
defines desired HTML page width in screen pixels.
|
void |
setPageFooter(PD4PageMark mark)
defines page footer area
|
void |
setPageHeader(PD4PageMark mark)
defines page header area
|
void |
setPageInsets(Insets ii)
specifies page insets in points
|
void |
setPageInsetsMM(Insets ii)
specifies page insets in millimeters.
|
void |
setPageSize(Dimension d)
defines page size in points.
|
void |
setPageSizeMM(Dimension d)
defines page size in milimeters.
|
void |
setPermissions(String password,
int permissions,
boolean isStrong)
forces the resulting document to be encrypted with the given password
|
void |
setSessionID(String sessionID)
the method informs PD4ML about current session ID (in web application environments).
|
static int |
translate(int i)
converts from millimeters to points
|
void |
useAdobeFontMetrics(boolean use)
Deprecated.
always uses AFM
|
void |
useHttpRequest(javax.servlet.http.HttpServletRequest httpRequest,
javax.servlet.http.HttpServletResponse httpResponse)
method allows to inform PD4ML about actual HTTP request context (if any).
|
void |
useServletContext(javax.servlet.ServletContext ctx)
method allows to inform PD4ML about actual servlet context (if any).
|
void |
useTTF(String pathToFontDirs,
boolean embed)
enables TTF font embedding subsystem.
|
public PD4ML pd4mlNew
public PD4ML()
public static final boolean isDemoMode()
public static final boolean isPro()
public static String getVersion()
public void merge(InputStream input, int fromPage, int toPage, boolean append)
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.public void merge(Reader input, int fromPage, int toPage, boolean append)
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.public void render(InputStreamReader isr, OutputStream os) throws InvalidParameterException, IOException
isr
- input stream reader of formatted data. Relies to properly specified
encoding.os
- output stream to generate PDF toInvalidParameterException
- the input or output stream is nullIOException
- input/output problemspublic void render(StringReader isr, OutputStream os) throws InvalidParameterException, IOException
isr
- string reader of formatted data. Relies to properly specified
encoding.os
- output stream to generate PDF toInvalidParameterException
- the input or output stream is nullIOException
- input/output problemspublic void render(InputStreamReader isr, OutputStream os, URL base) throws InvalidParameterException, IOException
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="..."> tagInvalidParameterException
- the input or output stream is nullIOException
- input/output problemspublic void render(StringReader isr, OutputStream os, URL base, String encoding) throws InvalidParameterException, IOException
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 encodingInvalidParameterException
- the input or output stream is nullIOException
- input/output problemspublic void render(StringReader isr, OutputStream os, URL base) throws InvalidParameterException, IOException
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="..."> tagInvalidParameterException
- the input or output stream is nullIOException
- input/output problemspublic void render(StringReader[] isrs, OutputStream os, URL base) throws InvalidParameterException, IOException
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="..."> tagInvalidParameterException
- the input or output stream is nullIOException
- input/output problemspublic void render(String textUrl, OutputStream os) throws MalformedURLException, InvalidParameterException, IOException
textUrl
- text representation of the input data URLos
- output stream to generate PDF toMalformedURLException
- invalid URLInvalidParameterException
- the input or output stream is nullIOException
- input/output problemspublic void render(URL url, OutputStream os) throws InvalidParameterException, IOException
url
- input data URLos
- output stream to generate PDF toMalformedURLException
- invalid URLInvalidParameterException
- the input or output stream is nullIOException
- input/output problemspublic void render(URL[] urls, OutputStream os) throws InvalidParameterException, IOException
urls
- input data URLsos
- output stream to generate PDF toMalformedURLException
- invalid URLInvalidParameterException
- the input or output stream is nullIOException
- input/output problemspublic void enableDebugInfo()
public void useTTF(String pathToFontDirs, boolean embed) throws FileNotFoundException
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.
FileNotFoundException
- if pd4fonts.properties file is not found or the file
refers to missing font filespublic void applyKerning(boolean enable)
enable
- - enables the featurepublic void generatePdfForms(boolean enable, String useTtfFont)
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 featureuseTTF(String, boolean)
public void generateMulticolumn(int columns, int span, boolean millimeters)
columns
- - number of columns per pagespan
- - space between the columnsmillimeters
- - if 'true' the gap is in millimeters, otherwise in pointspublic void useServletContext(javax.servlet.ServletContext ctx)
ctx
- servlet contextpublic void useHttpRequest(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse)
httpRequest
- actual HTTP requesthttpResponse
- actual HTTP responsepublic void setDefaultTTFs(String serif, String sansserif, String monospace)
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)public void enableRenderingPatch(boolean patch)
patch
- boolean switchpublic void useAdobeFontMetrics(boolean use)
use
- boolean switchpublic void generateOutlines(boolean fromHeadings)
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.public void setSessionID(String sessionID)
sessionID
- actual session IDpublic void overrideDocumentEncoding(String encoding)
encoding
- namepublic void disableHyperlinks()
public void enableImgSplit(boolean split)
split
- boolean switchsetHtmlWidth(int)
public void enableTableBreaks(boolean enable)
enableSmartTableBreaks(boolean)
insteadenable
- true to enablepublic void enableSmartTableBreaks(boolean enable)
enable
- true to enablepublic void setPageHeader(PD4PageMark mark) throws InvalidParameterException
mark
- header configuration objectInvalidParameterException
- when the config is nullpublic void setPageFooter(PD4PageMark mark) throws InvalidParameterException
mark
- footer configuration objectInvalidParameterException
- when the config is null
or contains invalid datapublic void setPageSizeMM(Dimension d) throws InvalidParameterException
d
- page dimensions in mmInvalidParameterException
- when the specified page format is null or
does not fit to already defined page insetssetPageSize(Dimension)
public void setPermissions(String password, int permissions, boolean isStrong)
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)public void setCookie(String name, String value)
name
- namevalue
- valuepublic void addDocumentActionHandler(String actionType, String javaScript)
actionType
- "OpenAction", "DC" (document close), "WS" (will save), "DS" (did save), "WP" (will print) or "DP" (did print)javaScript
- handler codepublic void setPageSize(Dimension d) throws InvalidParameterException
d
- page dimensions in pointsInvalidParameterException
- when the specified page format is null or
does not fit to already defined page insetschangePageOrientation(Dimension)
public void setPageInsetsMM(Insets ii) throws InvalidParameterException
ii
- page insets in millimetersInvalidParameterException
- when the specified page insets object is null
or when it does not fit to already defined page sizesetPageInsets(Insets)
public void setPageInsets(Insets ii) throws InvalidParameterException
ii
- page insets in pointsInvalidParameterException
- when the specified page insets object is null
or when it does not fit to already defined page sizepublic void setHtmlWidth(int width) throws InvalidParameterException
width
- HTML width in screen pixelsInvalidParameterException
- when the width is not a positive value great that 0.public void adjustHtmlWidth()
public void fitPageVertically()
public final void generatePdfa(boolean enable)
enable
- if true enables PDF/A outputPD4Constants.PD4ML_PDFA_STATUS
,
getLastRenderInfo(String)
public void protectPhysicalUnitDimensions()
public final void interpolateImages(boolean mode)
mode
- true - enables interpolation. default is falsepublic final void setAuthorName(String name)
name
- author's namepublic final void setDocumentTitle(String title)
title
- document titlepublic final void addStyle(URL stylesheet, boolean overrideDocumentStyles) throws InvalidParameterException
stylesheet
- of css stylesheetoverrideDocumentStyles
- if true, applies the stylesheet after styles defined in the document header.InvalidParameterException
- too many styles addedpublic final void addStyle(String stylesheet, boolean overrideDocumentStyles) throws InvalidParameterException
stylesheet
- stylesheet contentoverrideDocumentStyles
- if true, applies the stylesheet after styles defined in the document header.InvalidParameterException
- too many styles addedpublic final void resetAddedStyles()
public BufferedImage[] renderAsImages(URL url, int width, int height) throws IOException
url
- input document URLwidth
- target image widthheight
- target image heightIOException
- by errorspublic BufferedImage[] renderAsImages(StringReader isr, URL base, int width, int height) throws IOException
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 heightIOException
- by errorspublic static String legacyHeaderToHtml(PD4PageMark pageMark, boolean header)
public static void debug(String str)
str
- debug messagepublic static final int translate(int i)
i
- value in millimeterspublic Dimension changePageOrientation(Dimension d)
d
- original page dimensionpublic static final float predictScale(Insets pageInsets, Dimension pageSize, int userSpace)
public static final int predictPageHeight(Insets pageInsets, Dimension pageSize, int userSpace)
public void setDynamicParams(Map dynamicParams)
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.public Object getLastRenderInfo(String key)
key
- - one of the currently supported keys: "pd4ml.document.height.px", "pd4ml.right.edge.px" or "pd4ml.total.pages".PD4Constants
public void outputRange(String description)
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"public void outputFormat(String format)
format
- file format to output. PD4Constants.PDF - default.public void outputFormat(String format, int width, int height)
format
- file format to output. PD4Constants.PDF - default.height
- - limits resulting document dimensions by height. relevant for HTML-to-image conversions onlywidth
- - limits resulting document dimensions by width. relevant for HTML-to-image conversions onlypublic void addMetadata(String key, String value, boolean hide)
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 Acroreadpublic void clearCache()
public PD4Cache getCache()
setCache(PD4Cache)
public void setCache(PD4Cache cacheWrapper)
cacheWrapper
- cache object to reusegetCache()
public void monitorProgress(PD4ProgressListener listener)
listener
- receiver of progress update messagesRevision 4.0.15 / 20220727-0149