Package com.selectpdf
Class HtmlToPdfClient
java.lang.Object
com.selectpdf.ApiClient
com.selectpdf.HtmlToPdfClient
public class HtmlToPdfClient extends ApiClient
Html To Pdf Conversion with SelectPdf Online API.
package com.selectpdf;
public class HtmlToPdfMain {
public static void main(String[] args) throws Exception {
String url = "https://selectpdf.com";
String localFile = "Test.pdf";
String apiKey = "Your API key here";
System.out.println(String.format("This is SelectPdf-%s.", ApiClient.CLIENT_VERSION));
try {
HtmlToPdfClient client = new HtmlToPdfClient(apiKey);
// set parameters - see full list at https://selectpdf.com/html-to-pdf-api/
client
// main properties
.setPageSize(ApiEnums.PageSize.A4) // PDF page size
.setPageOrientation(ApiEnums.PageOrientation.Portrait) // PDF page orientation
.setMargins(0) // PDF page margins
.setRenderingEngine(ApiEnums.RenderingEngine.WebKit) // rendering engine
.setConversionDelay(1) // conversion delay
.setNavigationTimeout(30) // navigation timeout
.setShowPageNumbers(false) // page numbers
.setPageBreaksEnhancedAlgorithm(true) // enhanced page break algorithm
// additional properties
// .setUseCssPrint(true) // enable CSS media print
// .setDisableJavascript(true) // disable javascript
// .setDisableInternalLinks(true) // disable internal links
// .setDisableExternalLinks(true) // disable external links
// .setKeepImagesTogether(true) // keep images together
// .setScaleImages(true) // scale images to create smaller pdfs
// .setSinglePagePdf(true) // generate a single page PDF
// .setUserPassword("password") // secure the PDF with a password
// generate automatic bookmarks
// .setPdfBookmarksSelectors("H1, H2") // create outlines (bookmarks) for the specified elements
// .setViewerPageMode(ApiEnums.PageMode.UseOutlines) // display outlines (bookmarks) in viewer
;
System.out.println("Starting conversion...");
// convert url to file
client.convertUrlToFile(url, localFile);
// convert url to memory
// byte[] pdf = client.convertUrl(url);
// convert html string to file
// client.convertHtmlStringToFile("This is some <b>html</b>.", localFile);
// convert html string to memory
// byte[] pdf = client.convertHtmlString("This is some <b>html</b>.");
System.out.println(String.format("Finished! Number of pages: %d.", client.getNumberOfPages()));
// get API usage
UsageClient usageClient = new UsageClient(apiKey);
String usage = usageClient.getUsage(false);
System.out.printf("Usage details: %s.\r\n", usage);
// org.json.JSONObject usageObject = new org.json.JSONObject(usage);
// int available = usageObject.getInt("available");
// System.out.printf("Conversions remained this month: %d.\r\n", available);
}
catch (Exception ex) {
System.out.println("An error occured: " + ex.getMessage());
}
}
}
-
Field Summary
Fields inherited from class com.selectpdf.ApiClient
apiAsyncEndpoint, apiEndpoint, apiWebElementsEndpoint, AsyncCallsMaxPings, AsyncCallsPingInterval, binaryData, CLIENT_VERSION, files, headers, jobId, lastHTTPCode, MULTIPART_FORM_DATA_BOUNDARY, NEW_LINE, numberOfPages, parameters
-
Constructor Summary
Constructors Constructor Description HtmlToPdfClient(java.lang.String apiKey)
Construct the Html To Pdf Client. -
Method Summary
Modifier and Type Method Description byte[]
convertHtmlString(java.lang.String htmlString)
Convert the specified HTML string to PDF.byte[]
convertHtmlString(java.lang.String htmlString, java.lang.String baseUrl)
Convert the specified HTML string to PDF.byte[]
convertHtmlStringAsync(java.lang.String htmlString)
Convert the specified HTML string to PDF with an asynchronous call.byte[]
convertHtmlStringAsync(java.lang.String htmlString, java.lang.String baseUrl)
Convert the specified HTML string to PDF with an asynchronous call.void
convertHtmlStringToFile(java.lang.String htmlString, java.lang.String filePath)
Convert the specified HTML string to PDF and writes the resulted PDF to a local file.void
convertHtmlStringToFile(java.lang.String htmlString, java.lang.String baseUrl, java.lang.String filePath)
Convert the specified HTML string to PDF and writes the resulted PDF to a local file.void
convertHtmlStringToFileAsync(java.lang.String htmlString, java.lang.String filePath)
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file.void
convertHtmlStringToFileAsync(java.lang.String htmlString, java.lang.String baseUrl, java.lang.String filePath)
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file.void
convertHtmlStringToStream(java.lang.String htmlString, java.io.OutputStream stream)
Convert the specified HTML string to PDF and writes the resulted PDF to an output stream.void
convertHtmlStringToStream(java.lang.String htmlString, java.lang.String baseUrl, java.io.OutputStream stream)
Convert the specified HTML string to PDF and writes the resulted PDF to an output stream.void
convertHtmlStringToStreamAsync(java.lang.String htmlString, java.io.OutputStream stream)
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to an output stream.void
convertHtmlStringToStreamAsync(java.lang.String htmlString, java.lang.String baseUrl, java.io.OutputStream stream)
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to an output stream.byte[]
convertUrl(java.lang.String url)
Convert the specified url to PDF.byte[]
convertUrlAsync(java.lang.String url)
Convert the specified url to PDF using an asynchronous call.void
convertUrlToFile(java.lang.String url, java.lang.String filePath)
Convert the specified url to PDF and writes the resulted PDF to a local file.void
convertUrlToFileAsync(java.lang.String url, java.lang.String filePath)
Convert the specified url to PDF using an asynchronous call and writes the resulted PDF to a local file.void
convertUrlToStream(java.lang.String url, java.io.OutputStream stream)
Convert the specified url to PDF and writes the resulted PDF to an output stream.void
convertUrlToStreamAsync(java.lang.String url, java.io.OutputStream stream)
Convert the specified url to PDF using an asynchronous call and writes the resulted PDF to an output stream.java.lang.String
getWebElements()
Get the locations of certain web elements.HtmlToPdfClient
setBackgroundColor(java.lang.String backgroundColor)
Specify the background color of the PDF page in RGB html format.HtmlToPdfClient
setConversionDelay(int delay)
Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load.HtmlToPdfClient
setCookies(java.util.HashMap<java.lang.String,java.lang.String> cookies)
Set HTTP cookies for the web page being converted.HtmlToPdfClient
setCustomParameter(java.lang.String parameterName, java.lang.String parameterValue)
Set a custom parameter.HtmlToPdfClient
setDisableExternalLinks(java.lang.Boolean disableExternalLinks)
Do not create external links in the PDF.HtmlToPdfClient
setDisableInternalLinks(java.lang.Boolean disableInternalLinks)
Do not create internal links in the PDF.HtmlToPdfClient
setDisableJavascript(java.lang.Boolean disableJavascript)
Do not run JavaScript in web pages.HtmlToPdfClient
setDocAddCreationDate(java.lang.Boolean docAddCreationDate)
Add the date and time when the PDF document was created to the PDF document information.HtmlToPdfClient
setDocAuthor(java.lang.String docAuthor)
Set the name of the PDF document author.HtmlToPdfClient
setDocKeywords(java.lang.String docKeywords)
Set the PDF document keywords.HtmlToPdfClient
setDocSubject(java.lang.String docSubject)
Set the subject of the PDF document.HtmlToPdfClient
setDocTitle(java.lang.String docTitle)
Set the PDF document title.HtmlToPdfClient
setDrawHtmlBackground(java.lang.Boolean drawHtmlBackground)
Set a flag indicating if the web page background is rendered in PDF.HtmlToPdfClient
setFooterBaseUrl(java.lang.String baseUrl)
Set an optional base url parameter can be used together with the footer HTML to resolve relative paths from the html string.HtmlToPdfClient
setFooterDisplayOnEvenPages(java.lang.Boolean displayOnEvenPages)
Control the visibility of the footer on the even numbered pages of the generated pdf document.HtmlToPdfClient
setFooterDisplayOnFirstPage(java.lang.Boolean displayOnFirstPage)
Control the visibility of the footer on the first page of the generated pdf document.HtmlToPdfClient
setFooterDisplayOnLastPage(java.lang.Boolean displayOnLastPage)
Add a special footer on the last page of the generated pdf document only.HtmlToPdfClient
setFooterDisplayOnOddPages(java.lang.Boolean displayOnOddPages)
Control the visibility of the footer on the odd numbered pages of the generated pdf document.HtmlToPdfClient
setFooterHeight(int height)
The height of the pdf document footer.HtmlToPdfClient
setFooterHtml(java.lang.String html)
Set the raw html that is converted and rendered in the pdf document footer.HtmlToPdfClient
setFooterUrl(java.lang.String url)
Set the url of the web page that is converted and rendered in the PDF document footer.HtmlToPdfClient
setFooterWebPageHeight(int footerWebPageHeight)
Set the height in pixels used by the converter's internal browser window during the conversion of the footer content.HtmlToPdfClient
setFooterWebPageWidth(int footerWebPageWidth)
Set the width in pixels used by the converter's internal browser window during the conversion of the footer content.HtmlToPdfClient
setHeaderBaseUrl(java.lang.String baseUrl)
Set an optional base url parameter can be used together with the header HTML to resolve relative paths from the html string.HtmlToPdfClient
setHeaderDisplayOnEvenPages(java.lang.Boolean displayOnEvenPages)
Control the visibility of the header on the even numbered pages of the generated pdf document.HtmlToPdfClient
setHeaderDisplayOnFirstPage(java.lang.Boolean displayOnFirstPage)
Control the visibility of the header on the first page of the generated pdf document.HtmlToPdfClient
setHeaderDisplayOnOddPages(java.lang.Boolean displayOnOddPages)
Control the visibility of the header on the odd numbered pages of the generated pdf document.HtmlToPdfClient
setHeaderHeight(int height)
The height of the pdf document header.HtmlToPdfClient
setHeaderHtml(java.lang.String html)
Set the raw html that is converted and rendered in the pdf document header.HtmlToPdfClient
setHeaderUrl(java.lang.String url)
Set the url of the web page that is converted and rendered in the PDF document header.HtmlToPdfClient
setHeaderWebPageHeight(int headerWebPageHeight)
Set the height in pixels used by the converter's internal browser window during the conversion of the header content.HtmlToPdfClient
setHeaderWebPageWidth(int headerWebPageWidth)
Set the width in pixels used by the converter's internal browser window during the conversion of the header content.HtmlToPdfClient
setKeepImagesTogether(java.lang.Boolean keepImagesTogether)
Avoid breaking images between PDF pages.HtmlToPdfClient
setMarginBottom(int marginBottom)
Set bottom margin of the PDF pages.HtmlToPdfClient
setMarginLeft(int marginLeft)
Set left margin of the PDF pages.HtmlToPdfClient
setMarginRight(int marginRight)
Set right margin of the PDF pages.HtmlToPdfClient
setMargins(int margin)
Set all margins of the PDF pages to the same value.HtmlToPdfClient
setMarginTop(int marginTop)
Set top margin of the PDF pages.HtmlToPdfClient
setMaxLoadTime(int maxLoadTime)
Set the maximum amount of time (in seconds) that the convert will wait for the page to load.HtmlToPdfClient
setMinLoadTime(int minLoadTime)
Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load.HtmlToPdfClient
setNavigationTimeout(int timeout)
Set the maximum amount of time (in seconds) that the convert will wait for the page to load.HtmlToPdfClient
setOwnerPassword(java.lang.String ownerPassword)
Set PDF owner password.HtmlToPdfClient
setPageBreaksEnhancedAlgorithm(java.lang.Boolean enableEnhancedPageBreaksAlgorithm)
Get or set a flag indicating if an enhanced custom page breaks algorithm is used.HtmlToPdfClient
setPageHeight(int pageHeight)
Set PDF page height in points.HtmlToPdfClient
setPageNumbersAlignment(ApiEnums.PageNumbersAlignment alignment)
Set the alignment of the page numbers text.HtmlToPdfClient
setPageNumbersColor(java.lang.String color)
Specify the color of the page numbers text in #RRGGBB html format.HtmlToPdfClient
setPageNumbersFirst(int firstPageNumber)
Control the page number for the first page being rendered.HtmlToPdfClient
setPageNumbersFontName(java.lang.String fontName)
Set the font used to display the page numbers text.HtmlToPdfClient
setPageNumbersFontSize(int fontSize)
Set the size of the font used to display the page numbers.HtmlToPdfClient
setPageNumbersOffset(int totalPagesOffset)
Control the total number of pages offset in the generated pdf document.HtmlToPdfClient
setPageNumbersTemplate(java.lang.String template)
Set the text that is used to display the page numbers.HtmlToPdfClient
setPageNumbersVerticalPosition(int position)
Specify the position in points on the vertical where the page numbers text is displayed in the footer.HtmlToPdfClient
setPageOrientation(ApiEnums.PageOrientation pageOrientation)
Set PDF page orientation.HtmlToPdfClient
setPageSize(ApiEnums.PageSize pageSize)
Set PDF page size.HtmlToPdfClient
setPageWidth(int pageWidth)
Set PDF page width in points.HtmlToPdfClient
setPdfBookmarksSelectors(java.lang.String selectors)
Generate automatic bookmarks in pdf.HtmlToPdfClient
setPdfHideElements(java.lang.String selectors)
Exclude page elements from the conversion.HtmlToPdfClient
setPdfName(java.lang.String pdfName)
Specify the name of the pdf document that will be created.HtmlToPdfClient
setPdfShowOnlyElementID(java.lang.String elementID)
Convert only a specific section of the web page to pdf.HtmlToPdfClient
setPdfWebElementsSelectors(java.lang.String selectors)
Get the locations of page elements from the conversion.HtmlToPdfClient
setRenderingEngine(ApiEnums.RenderingEngine renderingEngine)
Set the rendering engine used for the HTML to PDF conversion.HtmlToPdfClient
setRenderOnTimeout(java.lang.Boolean renderOnTimeout)
Try to render the PDF even in case of the web page loading timeout.HtmlToPdfClient
setScaleImages(java.lang.Boolean scaleImages)
Set a flag indicating if the images from the page are scaled during the conversion process.HtmlToPdfClient
setSecureProtocol(ApiEnums.SecureProtocol secureProtocol)
Set the protocol used for secure (HTTPS) connections.HtmlToPdfClient
setShowFooter(java.lang.Boolean showFooter)
Control if a custom footer is displayed in the generated PDF document.HtmlToPdfClient
setShowHeader(java.lang.Boolean showHeader)
Control if a custom header is displayed in the generated PDF document.HtmlToPdfClient
setShowPageNumbers(java.lang.Boolean showPageNumbers)
Show page numbers.HtmlToPdfClient
setSinglePagePdf(java.lang.Boolean generateSinglePagePdf)
Generate a single page PDF.HtmlToPdfClient
setSkipDecoding(java.lang.Boolean skipDecoding)
Internal use only.HtmlToPdfClient
setStartupMode(ApiEnums.StartupMode startupMode)
Set converter startup mode.HtmlToPdfClient
setUseCssPrint(java.lang.Boolean useCssPrint)
Specify if the CSS Print media type is used instead of the Screen media type.HtmlToPdfClient
setUserPassword(java.lang.String userPassword)
Set PDF user password.HtmlToPdfClient
setViewerCenterWindow(java.lang.Boolean viewerCenterWindow)
Set a flag specifying whether to position the document's window in the center of the screen.HtmlToPdfClient
setViewerDisplayDocTitle(java.lang.Boolean viewerDisplayDocTitle)
Set a flag specifying whether the window's title bar should display the document title taken from document information.HtmlToPdfClient
setViewerFitWindow(java.lang.Boolean viewerFitWindow)
Set a flag specifying whether to resize the document's window to fit the size of the first displayed page.HtmlToPdfClient
setViewerHideMenuBar(java.lang.Boolean viewerHideMenuBar)
Set a flag specifying whether to hide the pdf viewer application's menu bar when the document is active.HtmlToPdfClient
setViewerHideToolbar(java.lang.Boolean viewerHideToolbar)
Set a flag specifying whether to hide the pdf viewer application's tool bars when the document is active.HtmlToPdfClient
setViewerHideWindowUI(java.lang.Boolean viewerHideWindowUI)
Set a flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.HtmlToPdfClient
setViewerPageLayout(ApiEnums.PageLayout pageLayout)
Set the page layout to be used when the document is opened in a PDF viewer.HtmlToPdfClient
setViewerPageMode(ApiEnums.PageMode pageMode)
Set the document page mode when the pdf document is opened in a PDF viewer.HtmlToPdfClient
setWebPageHeight(int webPageHeight)
Set the height used by the converter's internal browser window in pixels.HtmlToPdfClient
setWebPageWidth(int webPageWidth)
Set the width used by the converter's internal browser window in pixels.Methods inherited from class com.selectpdf.ApiClient
getNumberOfPages, performPost, performPostAsMultipartFormData, serializeDictionary, serializeParameters, setApiAsyncEndpoint, setApiEndpoint, setApiWebElementsEndpoint, startAsyncJob, startAsyncJobMultipartFormData
-
Constructor Details
-
HtmlToPdfClient
public HtmlToPdfClient(java.lang.String apiKey)Construct the Html To Pdf Client.- Parameters:
apiKey
- API key.
-
-
Method Details
-
convertUrl
public byte[] convertUrl(java.lang.String url)Convert the specified url to PDF. SelectPdf online API can convert http:// and https:// publicly available urls.- Parameters:
url
- Address of the web page being converted.- Returns:
- Byte array containing the resulted PDF.
-
convertUrlToStream
public void convertUrlToStream(java.lang.String url, java.io.OutputStream stream)Convert the specified url to PDF and writes the resulted PDF to an output stream. SelectPdf online API can convert http:// and https:// publicly available urls.- Parameters:
url
- Address of the web page being converted.stream
- The output stream where the resulted PDF will be written.
-
convertUrlToFile
public void convertUrlToFile(java.lang.String url, java.lang.String filePath) throws java.io.IOExceptionConvert the specified url to PDF and writes the resulted PDF to a local file. SelectPdf online API can convert http:// and https:// publicly available urls.- Parameters:
url
- Address of the web page being converted.filePath
- Local file including path if necessary.- Throws:
java.io.IOException
-
convertUrlAsync
public byte[] convertUrlAsync(java.lang.String url)Convert the specified url to PDF using an asynchronous call. SelectPdf online API can convert http:// and https:// publicly available urls.- Parameters:
url
- Address of the web page being converted.- Returns:
- Byte array containing the resulted PDF.
-
convertUrlToStreamAsync
public void convertUrlToStreamAsync(java.lang.String url, java.io.OutputStream stream) throws java.io.IOExceptionConvert the specified url to PDF using an asynchronous call and writes the resulted PDF to an output stream. SelectPdf online API can convert http:// and https:// publicly available urls.- Parameters:
url
- Address of the web page being converted.stream
- The output stream where the resulted PDF will be written.- Throws:
java.io.IOException
-
convertUrlToFileAsync
public void convertUrlToFileAsync(java.lang.String url, java.lang.String filePath) throws java.io.IOExceptionConvert the specified url to PDF using an asynchronous call and writes the resulted PDF to a local file. SelectPdf online API can convert http:// and https:// publicly available urls.- Parameters:
url
- Address of the web page being converted.filePath
- Local file including path if necessary.- Throws:
java.io.IOException
-
convertHtmlString
public byte[] convertHtmlString(java.lang.String htmlString)Convert the specified HTML string to PDF.- Parameters:
htmlString
- HTML string with the content being converted.- Returns:
- Byte array containing the resulted PDF.
-
convertHtmlString
public byte[] convertHtmlString(java.lang.String htmlString, java.lang.String baseUrl)Convert the specified HTML string to PDF. Use a base url to resolve relative paths to resources.- Parameters:
htmlString
- HTML string with the content being converted.baseUrl
- Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.- Returns:
- Byte array containing the resulted PDF.
-
convertHtmlStringToStream
public void convertHtmlStringToStream(java.lang.String htmlString, java.io.OutputStream stream)Convert the specified HTML string to PDF and writes the resulted PDF to an output stream.- Parameters:
htmlString
- HTML string with the content being converted.stream
- The output stream where the resulted PDF will be written.
-
convertHtmlStringToStream
public void convertHtmlStringToStream(java.lang.String htmlString, java.lang.String baseUrl, java.io.OutputStream stream)Convert the specified HTML string to PDF and writes the resulted PDF to an output stream. Use a base url to resolve relative paths to resources.- Parameters:
htmlString
- HTML string with the content being converted.baseUrl
- Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.stream
- The output stream where the resulted PDF will be written.
-
convertHtmlStringToFile
public void convertHtmlStringToFile(java.lang.String htmlString, java.lang.String filePath) throws java.io.IOExceptionConvert the specified HTML string to PDF and writes the resulted PDF to a local file.- Parameters:
htmlString
- HTML string with the content being converted.filePath
- Local file including path if necessary.- Throws:
java.io.IOException
-
convertHtmlStringToFile
public void convertHtmlStringToFile(java.lang.String htmlString, java.lang.String baseUrl, java.lang.String filePath) throws java.io.IOExceptionConvert the specified HTML string to PDF and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources.- Parameters:
htmlString
- HTML string with the content being converted.baseUrl
- Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.filePath
- Local file including path if necessary.- Throws:
java.io.IOException
-
convertHtmlStringAsync
public byte[] convertHtmlStringAsync(java.lang.String htmlString)Convert the specified HTML string to PDF with an asynchronous call.- Parameters:
htmlString
- HTML string with the content being converted.- Returns:
- Byte array containing the resulted PDF.
-
convertHtmlStringAsync
public byte[] convertHtmlStringAsync(java.lang.String htmlString, java.lang.String baseUrl)Convert the specified HTML string to PDF with an asynchronous call. Use a base url to resolve relative paths to resources.- Parameters:
htmlString
- HTML string with the content being converted.baseUrl
- Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.- Returns:
- Byte array containing the resulted PDF.
-
convertHtmlStringToStreamAsync
public void convertHtmlStringToStreamAsync(java.lang.String htmlString, java.io.OutputStream stream) throws java.io.IOExceptionConvert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to an output stream.- Parameters:
htmlString
- HTML string with the content being converted.stream
- The output stream where the resulted PDF will be written.- Throws:
java.io.IOException
-
convertHtmlStringToStreamAsync
public void convertHtmlStringToStreamAsync(java.lang.String htmlString, java.lang.String baseUrl, java.io.OutputStream stream) throws java.io.IOExceptionConvert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to an output stream. Use a base url to resolve relative paths to resources.- Parameters:
htmlString
- HTML string with the content being converted.baseUrl
- Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.stream
- The output stream where the resulted PDF will be written.- Throws:
java.io.IOException
-
convertHtmlStringToFileAsync
public void convertHtmlStringToFileAsync(java.lang.String htmlString, java.lang.String filePath) throws java.io.IOExceptionConvert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file.- Parameters:
htmlString
- HTML string with the content being converted.filePath
- Local file including path if necessary.- Throws:
java.io.IOException
-
convertHtmlStringToFileAsync
public void convertHtmlStringToFileAsync(java.lang.String htmlString, java.lang.String baseUrl, java.lang.String filePath) throws java.io.IOExceptionConvert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources.- Parameters:
htmlString
- HTML string with the content being converted.baseUrl
- Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.filePath
- Local file including path if necessary.- Throws:
java.io.IOException
-
setPageSize
Set PDF page size. Default value is A4. If page size is set to Custom, use setPageWidth and setPageHeight methods to set the custom width/height of the PDF pages.- Parameters:
pageSize
- PDF page size.- Returns:
- Reference to the current object.
-
setPageWidth
Set PDF page width in points. Default value is 595pt (A4 page width in points). 1pt = 1/72 inch. This is taken into account only if page size is set to Custom using setPageSize method.- Parameters:
pageWidth
- Page width in points.- Returns:
- Reference to the current object.
-
setPageHeight
Set PDF page height in points. Default value is 842pt (A4 page height in points). 1pt = 1/72 inch. This is taken into account only if page size is set to Custom using setPageSize method.- Parameters:
pageHeight
- Page height in points.- Returns:
- Reference to the current object.
-
setPageOrientation
Set PDF page orientation. Default value is Portrait.- Parameters:
pageOrientation
- PDF page orientation.- Returns:
- Reference to the current object.
-
setMarginTop
Set top margin of the PDF pages. Default value is 5pt.- Parameters:
marginTop
- Margin value in points. 1pt = 1/72 inch.- Returns:
- Reference to the current object.
-
setMarginRight
Set right margin of the PDF pages. Default value is 5pt.- Parameters:
marginRight
- Margin value in points. 1pt = 1/72 inch.- Returns:
- Reference to the current object.
-
setMarginBottom
Set bottom margin of the PDF pages. Default value is 5pt.- Parameters:
marginBottom
- Margin value in points. 1pt = 1/72 inch.- Returns:
- Reference to the current object.
-
setMarginLeft
Set left margin of the PDF pages. Default value is 5pt.- Parameters:
marginLeft
- Margin value in points. 1pt = 1/72 inch.- Returns:
- Reference to the current object.
-
setMargins
Set all margins of the PDF pages to the same value. Default value is 5pt.- Parameters:
margin
- Margin value in points. 1pt = 1/72 inch.- Returns:
- Reference to the current object.
-
setPdfName
Specify the name of the pdf document that will be created. The default value is Document.pdf.- Parameters:
pdfName
- Name of the generated PDF document.- Returns:
- Reference to the current object.
-
setRenderingEngine
Set the rendering engine used for the HTML to PDF conversion. Default value is WebKit.- Parameters:
renderingEngine
- HTML rendering engine.- Returns:
- Reference to the current object.
-
setUserPassword
Set PDF user password.- Parameters:
userPassword
- PDF user password.- Returns:
- Reference to the current object.
-
setOwnerPassword
Set PDF owner password.- Parameters:
ownerPassword
- PDF owner password.- Returns:
- Reference to the current object.
-
setWebPageWidth
Set the width used by the converter's internal browser window in pixels. The default value is 1024px.- Parameters:
webPageWidth
- Browser window width in pixels.- Returns:
- Reference to the current object.
-
setWebPageHeight
Set the height used by the converter's internal browser window in pixels. The default value is 0px and it means that the page height is automatically calculated by the converter.- Parameters:
webPageHeight
- Browser window height in pixels. Set it to 0px to automatically calculate page height.- Returns:
- Reference to the current object.
-
setMinLoadTime
Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load. This method is an alias for setConversionDelay. The default value is 1 second. Use a larger value if the web page has content that takes time to render when it is displayed in the browser.- Parameters:
minLoadTime
- Delay in seconds.- Returns:
- Reference to the current object.
-
setConversionDelay
Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load. This method is an alias for setMinLoadTime. The default value is 1 second. Use a larger value if the web page has content that takes time to render when it is displayed in the browser.- Parameters:
delay
- Delay in seconds.- Returns:
- Reference to the current object.
-
setMaxLoadTime
Set the maximum amount of time (in seconds) that the convert will wait for the page to load. This method is an alias for setNavigationTimeout. A timeout error is displayed when this time elapses. The default value is 30 seconds. Use a larger value (up to 120 seconds allowed) for pages that take a long time to load.- Parameters:
maxLoadTime
- Timeout in seconds.- Returns:
- Reference to the current object.
-
setNavigationTimeout
Set the maximum amount of time (in seconds) that the convert will wait for the page to load. This method is an alias for setMaxLoadTime. A timeout error is displayed when this time elapses. The default value is 30 seconds. Use a larger value (up to 120 seconds allowed) for pages that take a long time to load.- Parameters:
timeout
- Timeout in seconds.- Returns:
- Reference to the current object.
-
setSecureProtocol
Set the protocol used for secure (HTTPS) connections. Set this only if you have an older server that only works with older SSL connections.- Parameters:
secureProtocol
- Secure protocol.- Returns:
- Reference to the current object.
-
setUseCssPrint
Specify if the CSS Print media type is used instead of the Screen media type. The default value is False.- Parameters:
useCssPrint
- Use CSS Print media or not.- Returns:
- Reference to the current object.
-
setBackgroundColor
Specify the background color of the PDF page in RGB html format. The default is #FFFFFF.- Parameters:
backgroundColor
- Background color in #RRGGBB format.- Returns:
- Reference to the current object.
-
setDrawHtmlBackground
Set a flag indicating if the web page background is rendered in PDF. The default value is True.- Parameters:
drawHtmlBackground
- Draw the HTML background or not.- Returns:
- Reference to the current object.
-
setDisableJavascript
Do not run JavaScript in web pages. The default value is False and javascript is executed.- Parameters:
disableJavascript
- Disable javascript or not.- Returns:
- Reference to the current object.
-
setDisableInternalLinks
Do not create internal links in the PDF. The default value is False and internal links are created.- Parameters:
disableInternalLinks
- Disable internal links or not.- Returns:
- Reference to the current object.
-
setDisableExternalLinks
Do not create external links in the PDF. The default value is False and external links are created.- Parameters:
disableExternalLinks
- Disable external links or not.- Returns:
- Reference to the current object.
-
setRenderOnTimeout
Try to render the PDF even in case of the web page loading timeout. The default value is False and an exception is raised in case of web page navigation timeout.- Parameters:
renderOnTimeout
- Render in case of timeout or not.- Returns:
- Reference to the current object.
-
setKeepImagesTogether
Avoid breaking images between PDF pages. The default value is False and images are split between pages if larger.- Parameters:
keepImagesTogether
- Try to keep images on same page or not.- Returns:
- Reference to the current object.
-
setDocTitle
Set the PDF document title.- Parameters:
docTitle
- Document title.- Returns:
- Reference to the current object.
-
setDocSubject
Set the subject of the PDF document.- Parameters:
docSubject
- Document subject.- Returns:
- Reference to the current object.
-
setDocKeywords
Set the PDF document keywords.- Parameters:
docKeywords
- Document keywords.- Returns:
- Reference to the current object.
-
setDocAuthor
Set the name of the PDF document author.- Parameters:
docAuthor
- Document author.- Returns:
- Reference to the current object.
-
setDocAddCreationDate
Add the date and time when the PDF document was created to the PDF document information. The default value is False.- Parameters:
docAddCreationDate
- Add creation date to the document metadata or not.- Returns:
- Reference to the current object.
-
setViewerPageLayout
Set the page layout to be used when the document is opened in a PDF viewer. The default value is PageLayout.OneColumn.- Parameters:
pageLayout
- Page layout.- Returns:
- Reference to the current object.
-
setViewerPageMode
Set the document page mode when the pdf document is opened in a PDF viewer. The default value is PageMode.UseNone.- Parameters:
pageMode
- Page mode.- Returns:
- Reference to the current object.
-
setViewerCenterWindow
Set a flag specifying whether to position the document's window in the center of the screen. The default value is False.- Parameters:
viewerCenterWindow
- Center window or not.- Returns:
- Reference to the current object.
-
setViewerDisplayDocTitle
Set a flag specifying whether the window's title bar should display the document title taken from document information. The default value is False.- Parameters:
viewerDisplayDocTitle
- Display title or not.- Returns:
- Reference to the current object.
-
setViewerFitWindow
Set a flag specifying whether to resize the document's window to fit the size of the first displayed page. The default value is False.- Parameters:
viewerFitWindow
- Fit window or not.- Returns:
- Reference to the current object.
-
setViewerHideMenuBar
Set a flag specifying whether to hide the pdf viewer application's menu bar when the document is active. The default value is False.- Parameters:
viewerHideMenuBar
- Hide menu bar or not.- Returns:
- Reference to the current object.
-
setViewerHideToolbar
Set a flag specifying whether to hide the pdf viewer application's tool bars when the document is active. The default value is False.- Parameters:
viewerHideToolbar
- Hide tool bars or not.- Returns:
- Reference to the current object.
-
setViewerHideWindowUI
Set a flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed. The default value is False.- Parameters:
viewerHideWindowUI
- Hide window UI or not.- Returns:
- Reference to the current object.
-
setShowHeader
Control if a custom header is displayed in the generated PDF document. The default value is False.- Parameters:
showHeader
- Show header or not.- Returns:
- Reference to the current object.
-
setHeaderHeight
The height of the pdf document header. This height is specified in points. 1 point is 1/72 inch. The default value is 50.- Parameters:
height
- Header height.- Returns:
- Reference to the current object.
-
setHeaderUrl
Set the url of the web page that is converted and rendered in the PDF document header.- Parameters:
url
- The url of the web page that is converted and rendered in the pdf document header.- Returns:
- Reference to the current object.
-
setHeaderHtml
Set the raw html that is converted and rendered in the pdf document header.- Parameters:
html
- The raw html that is converted and rendered in the pdf document header.- Returns:
- Reference to the current object.
-
setHeaderBaseUrl
Set an optional base url parameter can be used together with the header HTML to resolve relative paths from the html string.- Parameters:
baseUrl
- Header base url.- Returns:
- Reference to the current object.
-
setHeaderDisplayOnFirstPage
Control the visibility of the header on the first page of the generated pdf document. The default value is True.- Parameters:
displayOnFirstPage
- Display header on the first page or not.- Returns:
- Reference to the current object.
-
setHeaderDisplayOnOddPages
Control the visibility of the header on the odd numbered pages of the generated pdf document. The default value is True.- Parameters:
displayOnOddPages
- Display header on odd pages or not.- Returns:
- Reference to the current object.
-
setHeaderDisplayOnEvenPages
Control the visibility of the header on the even numbered pages of the generated pdf document. The default value is True.- Parameters:
displayOnEvenPages
- Display header on even pages or not.- Returns:
- Reference to the current object.
-
setHeaderWebPageWidth
Set the width in pixels used by the converter's internal browser window during the conversion of the header content. The default value is 1024px.- Parameters:
headerWebPageWidth
- Browser window width in pixels.- Returns:
- Reference to the current object.
-
setHeaderWebPageHeight
Set the height in pixels used by the converter's internal browser window during the conversion of the header content. The default value is 0px and it means that the page height is automatically calculated by the converter.- Parameters:
headerWebPageHeight
- Browser window height in pixels. Set it to 0px to automatically calculate page height.- Returns:
- Reference to the current object.
-
setShowFooter
Control if a custom footer is displayed in the generated PDF document. The default value is False.- Parameters:
showFooter
- Show footer or not.- Returns:
- Reference to the current object.
-
setFooterHeight
The height of the pdf document footer. This height is specified in points. 1 point is 1/72 inch. The default value is 50.- Parameters:
height
- Footer height.- Returns:
- Reference to the current object.
-
setFooterUrl
Set the url of the web page that is converted and rendered in the PDF document footer.- Parameters:
url
- The url of the web page that is converted and rendered in the pdf document footer.- Returns:
- Reference to the current object.
-
setFooterHtml
Set the raw html that is converted and rendered in the pdf document footer.- Parameters:
html
- The raw html that is converted and rendered in the pdf document footer.- Returns:
- Reference to the current object.
-
setFooterBaseUrl
Set an optional base url parameter can be used together with the footer HTML to resolve relative paths from the html string.- Parameters:
baseUrl
- Footer base url.- Returns:
- Reference to the current object.
-
setFooterDisplayOnFirstPage
Control the visibility of the footer on the first page of the generated pdf document. The default value is True.- Parameters:
displayOnFirstPage
- Display footer on the first page or not.- Returns:
- Reference to the current object.
-
setFooterDisplayOnOddPages
Control the visibility of the footer on the odd numbered pages of the generated pdf document. The default value is True.- Parameters:
displayOnOddPages
- Display footer on odd pages or not.- Returns:
- Reference to the current object.
-
setFooterDisplayOnEvenPages
Control the visibility of the footer on the even numbered pages of the generated pdf document. The default value is True.- Parameters:
displayOnEvenPages
- Display footer on even pages or not.- Returns:
- Reference to the current object.
-
setFooterDisplayOnLastPage
Add a special footer on the last page of the generated pdf document only. The default value is False. Use setFooterUrl or setFooterHtml and setFooterBaseUrl to specify the content of the last page footer. Use setFooterHeight to specify the height of the special last page footer.- Parameters:
displayOnLastPage
- Display special footer on the last page or not.- Returns:
- Reference to the current object.
-
setFooterWebPageWidth
Set the width in pixels used by the converter's internal browser window during the conversion of the footer content. The default value is 1024px.- Parameters:
footerWebPageWidth
- Browser window width in pixels.- Returns:
- Reference to the current object.
-
setFooterWebPageHeight
Set the height in pixels used by the converter's internal browser window during the conversion of the footer content. The default value is 0px and it means that the page height is automatically calculated by the converter.- Parameters:
footerWebPageHeight
- Browser window height in pixels. Set it to 0px to automatically calculate page height.- Returns:
- Reference to the current object.
-
setShowPageNumbers
Show page numbers. Default value is True. Page numbers will be displayed in the footer of the PDF document.- Parameters:
showPageNumbers
- Show page numbers or not.- Returns:
- Reference to the current object.
-
setPageNumbersFirst
Control the page number for the first page being rendered. The default value is 1.- Parameters:
firstPageNumber
- First page number.- Returns:
- Reference to the current object.
-
setPageNumbersOffset
Control the total number of pages offset in the generated pdf document. The default value is 0.- Parameters:
totalPagesOffset
- Offset for the total number of pages in the generated pdf document.- Returns:
- Reference to the current object.
-
setPageNumbersTemplate
Set the text that is used to display the page numbers. It can contain the placeholder {page_number} for the current page number and {total_pages} for the total number of pages. The default value is "Page: {page_number} of {total_pages}".- Parameters:
template
- Page numbers template.- Returns:
- Reference to the current object.
-
setPageNumbersFontName
Set the font used to display the page numbers text. The default value is "Helvetica".- Parameters:
fontName
- The font used to display the page numbers text.- Returns:
- Reference to the current object.
-
setPageNumbersFontSize
Set the size of the font used to display the page numbers. The default value is 10 points.- Parameters:
fontSize
- The size in points of the font used to display the page numbers.- Returns:
- Reference to the current object.
-
setPageNumbersAlignment
Set the alignment of the page numbers text. The default value is PageNumbersAlignment.Right.- Parameters:
alignment
- The alignment of the page numbers text.- Returns:
- Reference to the current object.
-
setPageNumbersColor
Specify the color of the page numbers text in #RRGGBB html format. The default value is #333333.- Parameters:
color
- Page numbers color.- Returns:
- Reference to the current object.
-
setPageNumbersVerticalPosition
Specify the position in points on the vertical where the page numbers text is displayed in the footer. The default value is 10 points.- Parameters:
position
- Page numbers Y position in points.- Returns:
- Reference to the current object.
-
setPdfBookmarksSelectors
Generate automatic bookmarks in pdf. The elements that will be bookmarked are defined using CSS selectors. For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors here.- Parameters:
selectors
- CSS selectors used to identify HTML elements, comma separated..- Returns:
- Reference to the current object.
-
setPdfHideElements
Exclude page elements from the conversion. The elements that will be excluded are defined using CSS selectors. For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors here.- Parameters:
selectors
- CSS selectors used to identify HTML elements, comma separated..- Returns:
- Reference to the current object.
-
setPdfShowOnlyElementID
Convert only a specific section of the web page to pdf. The section that will be converted to pdf is specified by the html element ID. The element can be anything (image, table, table row, div, text, etc).- Parameters:
elementID
- HTML element ID.- Returns:
- Reference to the current object.
-
setPdfWebElementsSelectors
Get the locations of page elements from the conversion. The elements that will have their locations retrieved are defined using CSS selectors. For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors here.- Parameters:
selectors
- CSS selectors used to identify HTML elements, comma separated..- Returns:
- Reference to the current object.
-
setStartupMode
Set converter startup mode. The default value is StartupMode.Automatic and the conversion is started immediately. By default this is set to StartupMode.Automatic and the conversion is started as soon as the page loads (and conversion delay set with setConversionDelay elapses). If set to StartupMode.Manual, the conversion is started only by a javascript call to SelectPdf.startConversion() from within the web page.- Parameters:
startupMode
- Converter startup mode.- Returns:
- Reference to the current object.
-
setSkipDecoding
Internal use only.- Parameters:
skipDecoding
- The default value is True.- Returns:
- Reference to the current object.
-
setScaleImages
Set a flag indicating if the images from the page are scaled during the conversion process. The default value is False and images are not scaled.- Parameters:
scaleImages
- Scale images or not.- Returns:
- Reference to the current object.
-
setSinglePagePdf
Generate a single page PDF. The converter will automatically resize the PDF page to fit all the content in a single page. The default value of this property is False and the PDF will contain several pages if the content is large.- Parameters:
generateSinglePagePdf
- Generate a single page PDF or not.- Returns:
- Reference to the current object.
-
setPageBreaksEnhancedAlgorithm
public HtmlToPdfClient setPageBreaksEnhancedAlgorithm(java.lang.Boolean enableEnhancedPageBreaksAlgorithm)Get or set a flag indicating if an enhanced custom page breaks algorithm is used. The enhanced algorithm is a little bit slower but it will prevent the appearance of hidden text in the PDF when custom page breaks are used. The default value for this property is False.- Parameters:
enableEnhancedPageBreaksAlgorithm
- Enable enhanced page breaks algorithm or not.- Returns:
- Reference to the current object.
-
setCookies
Set HTTP cookies for the web page being converted.- Parameters:
cookies
- HTTP cookies that will be sent to the page being converted.- Returns:
- Reference to the current object.
-
setCustomParameter
public HtmlToPdfClient setCustomParameter(java.lang.String parameterName, java.lang.String parameterValue)Set a custom parameter. Do not use this method unless advised by SelectPdf.- Parameters:
parameterName
- Parameter name.parameterValue
- Parameter value.- Returns:
- Reference to the current object.
-
getWebElements
public java.lang.String getWebElements()Get the locations of certain web elements. This is retrieved if pdf_web_elements_selectors parameter is set and elements were found to match the selectors.- Returns:
- List of web elements locations.
-