public class Pdf extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
TEMPORARY_FILE_PREFIX
The constant TEMPORARY_FILE_PREFIX.
|
| Constructor and Description |
|---|
Pdf()
Deprecated.
|
Pdf(WrapperConfig wrapperConfig)
Instantiates a new Pdf.
|
| Modifier and Type | Method and Description |
|---|---|
Cover |
addCoverFromFile(String source)
Add a cover from a file to the pdf
|
Cover |
addCoverFromString(String source)
Add a cover from a HTML-based string to the pdf
|
Cover |
addCoverFromUrl(String source)
Add a cover from an URL to the pdf
|
Page |
addPage(String source,
SourceType type)
Deprecated.
Use the specific type method to a better semantic
|
Page |
addPageFromFile(String source)
Add a page from a file to the pdf
|
Page |
addPageFromString(String source)
Add a page from a HTML-based string to the pdf
|
Page |
addPageFromUrl(String source)
Add a page from an URL to the pdf
|
void |
addParam(Param param,
Param... params)
Adds a global param
|
TableOfContents |
addToc()
Add a toc
|
void |
addTocParam(Param param,
Param... params)
Deprecated.
Use per-object params as this will add only to the last ToC
|
void |
cleanAllTempFiles()
Cleans up all the files generated by the library.
|
boolean |
getAllowMissingAssets()
Gets allow missing assets.
|
String |
getCommand()
Gets the final wkhtmltopdf command as string
|
protected String[] |
getCommandAsArray()
Get command as array string
Note: htmlAsString pages are first store into a temp file, then the location is used in the wkhtmltopdf command
this is a workaround to avoid huge commands
|
byte[] |
getPDF()
Generates a PDF file as byte array from the wkhtmltopdf output
|
File |
getTempDirectory()
Gets the temporary folder where files are stored during processing
|
File |
saveAs(String path)
Executes the wkhtmltopdf into standard out and captures the results.
|
File |
saveAsDirect(String path)
Executes the wkhtmltopdf saving the results directly to the specified file path.
|
void |
setAllowMissingAssets()
wkhtmltopdf often returns 1 to indicate some assets can't be found,
this can occur for protocol less links or in other cases.
|
void |
setSuccessValues(List<Integer> successValues)
In standard process returns 0 means "ok" and any other value is an error.
|
void |
setTempDirectory(File tempDirectory)
Sets the temporary folder to store files during the process
Default is provided by #File.createTempFile()
|
void |
setTimeout(int timeout)
Sets the timeout to wait while generating a PDF, in seconds
|
public static final String TEMPORARY_FILE_PREFIX
@Deprecated public Pdf()
public Pdf(WrapperConfig wrapperConfig)
wrapperConfig - the wrapper config@Deprecated public Page addPage(String source, SourceType type)
source - the sourcetype - the typepublic Cover addCoverFromUrl(String source)
source - the sourcepublic Cover addCoverFromString(String source)
source - the sourcepublic Cover addCoverFromFile(String source)
source - the sourcepublic Page addPageFromUrl(String source)
source - the sourcepublic Page addPageFromString(String source)
source - the sourcepublic Page addPageFromFile(String source)
source - the sourcepublic TableOfContents addToc()
public void addParam(Param param, Param... params)
param - the global paramparams - the global params@Deprecated public void addTocParam(Param param, Param... params)
param - the paramparams - the paramspublic void setTimeout(int timeout)
timeout - the timeoutpublic void setAllowMissingAssets()
public boolean getAllowMissingAssets()
public void setSuccessValues(List<Integer> successValues)
successValues - The full list of process return values you will accept as a 'success'.public void setTempDirectory(File tempDirectory)
tempDirectory - the temp directorypublic File getTempDirectory()
public File saveAs(String path) throws IOException, InterruptedException
path - The path to the file where the PDF will be savedIOException - when not able to save the fileInterruptedException - when the PDF generation process got interruptedpublic File saveAsDirect(String path) throws IOException, InterruptedException
path - The path to the file where the PDF will be saved.IOException - when not able to save the fileInterruptedException - when the PDF generation process got interruptedpublic byte[] getPDF()
throws IOException,
InterruptedException,
PDFExportException
IOException - when not able to save the fileInterruptedException - when the PDF generation process got interruptedPDFExportException - when the wkhtmltopdf process failsprotected String[] getCommandAsArray() throws IOException
IOException - when not able to save temporary files from htmlAsStringpublic void cleanAllTempFiles()
public String getCommand() throws IOException
IOException - when not able to save temporary files from htmlAsStringCopyright © 2023. All rights reserved.