public class Prince
extends Object
Modifier and Type | Field and Description |
---|---|
protected String |
mBaseURL |
protected boolean |
mCompress |
protected boolean |
mDisallowAnnotate |
protected boolean |
mDisallowCopy |
protected boolean |
mDisallowModify |
protected boolean |
mDisallowPrint |
protected boolean |
mEmbedFonts |
protected boolean |
mEncrypt |
protected String |
mFallbackCMYKProfile |
protected String |
mFileRoot |
protected boolean |
mForceIdentityEncoding |
protected String |
mInputType |
protected boolean |
mJavaScript |
protected int |
mKeyBits |
protected String |
mOwnerPassword |
protected String |
mPDFOutputIntent |
protected String |
mPDFProfile |
protected String |
mPDFXMP |
protected ArrayList<String> |
mScripts |
protected ArrayList<String> |
mStyleSheets |
protected boolean |
mSubsetFonts |
protected String |
mUserPassword |
protected boolean |
mXInclude |
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.
|
boolean |
convertString(String html,
OutputStream pdfOutput)
Convert an XML or HTML file to a PDF file.
|
boolean |
convertString(String html,
String pdfPath)
Convert an XML or HTML file to a PDF file.
|
protected List<String> |
getBaseCommandLine()
Get the command line used to call Prince.
|
protected List<String> |
getJobCommandLine()
Get the command line used to call Prince.
|
protected boolean |
readMessages(BufferedReader reader) |
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 |
setFallbackCMYKProfile(String fallbackProfile)
Specify the fallback CMYK ICC color profile.
|
void |
setFileRoot(String fileRoot)
Specify the root directory for absolute filenames.
|
void |
setForceIdentityEncoding(boolean forceIdentityEncoding)
Specify whether fonts should be forced to use identity encoding.
|
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 option)
Specify additional Prince command-line options.
|
void |
setOptions(String[] options)
Specify additional Prince command-line options.
|
void |
setPDFOutputIntent(String outputIntent)
Specify the PDF output intent ICC color profile.
|
void |
setPDFProfile(String profile)
Specify the PDF profile.
|
void |
setPDFXMP(String xmpFile)
Specify a PDF XMP metadata file.
|
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.
|
protected ArrayList<String> mStyleSheets
protected ArrayList<String> mScripts
protected String mInputType
protected String mBaseURL
protected String mFileRoot
protected boolean mJavaScript
protected boolean mXInclude
protected String mPDFProfile
protected String mPDFOutputIntent
protected String mFallbackCMYKProfile
protected String mPDFXMP
protected boolean mEmbedFonts
protected boolean mSubsetFonts
protected boolean mForceIdentityEncoding
protected boolean mCompress
protected boolean mEncrypt
protected int mKeyBits
protected String mUserPassword
protected String mOwnerPassword
protected boolean mDisallowPrint
protected boolean mDisallowModify
protected boolean mDisallowCopy
protected boolean mDisallowAnnotate
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 setPDFProfile(String profile)
profile
- The PDF profile name, for example "PDF/A-1a", "PDF/X-4",
or null if no specific PDF profile is required.public void setPDFOutputIntent(String outputIntent)
outputIntent
- The ICC color profile to use for the PDF output
intent, or null if no specific output intent ICC profile is required.public void setFallbackCMYKProfile(String fallbackProfile)
fallbackProfile
- The ICC color profile to use as a fallback for
uncalibrated CMYK colors, or null if no specific fallback profile is
required.public void setPDFXMP(String xmpFile)
xmpFile
- The filename of the PDF XMP metadata file, or null if no
PDF XMP metadata is required.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 setForceIdentityEncoding(boolean forceIdentityEncoding)
forceIdentityEncoding
- True to force identity encoding.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 option)
option
- Additional command-line option, or null.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.IOException
public 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.IOException
public 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.IOException
public 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.IOException
public 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
public boolean convertString(String html, String pdfPath) throws IOException
html
- The HTML to convert, in the form of a String.pdfPath
- The filename of the output PDF file.IOException
public boolean convertString(String html, 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.
html
- The HTML to convert, in the form of a String.pdfOutput
- The OutputStream to which Prince will write the PDF
output.IOException
protected List<String> getBaseCommandLine()
protected List<String> getJobCommandLine()
protected boolean readMessages(BufferedReader reader) throws IOException
IOException