com.princexml
public class Prince extends Object
| Constructor and Description |
|---|
Prince(String exePath)
Constructor for Prince.
|
Prince(String exePath,
PrinceEvents events)
Constructor for Prince.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addScript(String jsPath)
Add a JavaScript script that will be executed before conversion.
|
void |
addStyleSheet(String cssPath)
Add a CSS style sheet that will be applied to each document.
|
void |
clearScripts()
Clear all of the JavaScript scripts.
|
void |
clearStyleSheets()
Clear all of the CSS style sheets.
|
boolean |
convert(InputStream xmlInput,
OutputStream pdfOutput)
Convert an XML or HTML file to a PDF file.
|
boolean |
convert(String xmlPath)
Convert an XML or HTML file to a PDF file.
|
boolean |
convert(String xmlPath,
OutputStream pdfOutput)
Convert an XML or HTML file to a PDF file.
|
boolean |
convert(String xmlPath,
String pdfPath)
Convert an XML or HTML file to a PDF file.
|
boolean |
convertMultiple(List xmlPaths,
String pdfPath)
Convert multiple XML or HTML files to a PDF file.
|
void |
setBaseURL(String baseurl)
Specify the base URL of the input document.
|
void |
setCompress(boolean compress)
Specify whether compression should be applied to the output PDF file.
|
void |
setDebug(boolean debug)
Enable logging of debug messages.
|
void |
setEmbedFonts(boolean embedFonts)
Specify whether fonts should be embedded in the output PDF file.
|
void |
setEncrypt(boolean encrypt)
Specify whether encryption should be applied to the output PDF file.
|
void |
setEncryptInfo(int keyBits,
String userPassword,
String ownerPassword,
boolean disallowPrint,
boolean disallowModify,
boolean disallowCopy,
boolean disallowAnnotate)
Set the parameters used for PDF encryption.
|
void |
setFileRoot(String fileRoot)
Specify the root directory for absolute filenames.
|
void |
setHTML(boolean html)
Specify whether documents should be parsed as HTML or XML/XHTML.
|
void |
setHttpPassword(String password)
Specify the password for HTTP basic authentication.
|
void |
setHttpProxy(String proxy)
Specify the URL for the HTTP proxy server, if needed.
|
void |
setHttpUsername(String username)
Specify the username for HTTP basic authentication.
|
void |
setInputType(String inputType)
Specify whether documents should be parsed as HTML or XML/XHTML.
|
void |
setJavaScript(boolean javascript)
Specify whether JavaScript scripts found in the document should be
executed during document conversion.
|
void |
setLog(String logfile)
Specify a file that Prince should use to log error/warning messages.
|
void |
setNetwork(boolean network)
Specify whether network access is allowed for downloading HTTP
resources.
|
void |
setOptions(String options)
Specify additional Prince command-line options.
|
void |
setSubsetFonts(boolean subsetFonts)
Specify whether embedded fonts should be subset to only include the
glyphs that are actually used in the PDF file.
|
void |
setVerbose(boolean verbose)
Enable verbose logging of informative messages.
|
void |
setXInclude(boolean xinclude)
Specify whether XML Inclusions (XInclude) processing should be applied
to input documents.
|
public Prince(String exePath)
exePath - The path of the Prince executable. (For example, this
may be C:\Program Files\Prince\engine\bin\prince.exe
on Windows or /usr/bin/prince on Linux).public Prince(String exePath,
PrinceEvents events)
exePath - The path of the Prince executable. (For example, this
may be C:\Program Files\Prince\engine\bin\prince.exe
on Windows or /usr/bin/prince on Linux).events - An instance of the PrinceEvents interface that will
receive error/warning messages returned from Prince.public void addStyleSheet(String cssPath)
cssPath - The filename of the CSS style sheet.public void clearStyleSheets()
public void addScript(String jsPath)
jsPath - The filename of the JavaScript script.public void clearScripts()
public void setHTML(boolean html)
This is also necessary if a HTML document is passed to Prince from an InputStream, as this has no filename and hence Prince will not check the extension and will always treat it as XML/XHTML unless this method has been called.
html - True if all documents should be treated as HTML, false
otherwise.public void setInputType(String inputType)
This is also necessary if a HTML document is passed to Prince from an InputStream, as this has no filename and hence Prince will not check the extension and will always treat it as XML/XHTML unless this method has been called.
inputType - "auto", "html", or "xml"public void setLog(String logfile)
logfile - The filename that Prince should use to log error/warning
messages, or null to disable logging.public void setVerbose(boolean verbose)
verbose - True to enable verbose logging.public void setDebug(boolean debug)
debug - True to enable debug logging.public void setBaseURL(String baseurl)
baseurl - The base URL or path of the input document.public void setFileRoot(String fileRoot)
fileRoot - The path to prepend to absolute filenames.public void setJavaScript(boolean javascript)
javascript - True to enable JavaScript script execution.public void setXInclude(boolean xinclude)
xinclude - False to disable XInclude processing.public void setNetwork(boolean network)
network - False to disable network access.public void setHttpUsername(String username)
username - The username for HTTP basic authentication.public void setHttpPassword(String password)
password - The password for HTTP basic authentication.public void setHttpProxy(String proxy)
proxy - The URL for the HTTP proxy server.public void setEmbedFonts(boolean embedFonts)
embedFonts - False to disable PDF font embedding.public void setSubsetFonts(boolean subsetFonts)
subsetFonts - False to disable subsetting of embedded fonts.public void setCompress(boolean compress)
compress - False to disable PDF compression.public void setEncrypt(boolean encrypt)
encrypt - True to enable PDF encryption.public void setEncryptInfo(int keyBits,
String userPassword,
String ownerPassword,
boolean disallowPrint,
boolean disallowModify,
boolean disallowCopy,
boolean disallowAnnotate)
setEncrypt(true).keyBits - The size of the encryption key in bits (must be 40 or
128).userPassword - The user password for the encrypted PDF file.ownerPassword - The owner password for the encrypted PDF file.disallowPrint - True to disallow printing of the encrypted PDF
file.disallowModify - True to disallow modification of the encrypted
PDF file.disallowCopy - True to disallow copying from the encrypted PDF
file.disallowAnnotate - True to disallow annotation of the encrypted
PDF file.IllegalArgumentException - if keyBits is not 40 or 128.public void setOptions(String options)
options - Additional command-line options, or null.public boolean convert(String xmlPath)
throws IOException
xmlPath - The filename of the input XML or HTML document.IOExceptionpublic boolean convert(String xmlPath,
String pdfPath)
throws IOException
xmlPath - The filename of the input XML or HTML document.pdfPath - The filename of the output PDF file.IOExceptionpublic boolean convertMultiple(List xmlPaths,
String pdfPath)
throws IOException
xmlPaths - The filenames of the input XML or HTML documents.pdfPath - The filename of the output PDF file.IOExceptionpublic boolean convert(String xmlPath,
OutputStream pdfOutput)
throws IOException
xmlPath - The filename of the input XML or HTML document.pdfOutput - The OutputStream to which Prince will write the PDF
output.IOExceptionpublic boolean convert(InputStream xmlInput,
OutputStream pdfOutput)
throws IOException
Note that it may be helpful to specify a base URL or path for the input document using the setBaseURL() method. This allows relative URLs and paths in the document (eg. for images) to be resolved correctly.
xmlInput - The InputStream from which Prince will read the XML or
HTML document.pdfOutput - The OutputStream to which Prince will write the PDF
output.IOException