java.lang.Object | |
↳ | com.pspdfkit.document.html.HtmlToPdfConverter |
Converts HTML to PDF document.
Note: HTML-to-PDF conversion internally relies on the system WebView
implementation. This means that there are certain aspects of this conversion process that
PSPDFKit can't support. This includes, for example, any possible WebView
bugs.
Note: JavaScript execution is enabled by default. This could cause security and
performance issues. Please review your JavaScripts carefully. If you wish to disable JavaScript
execution while performing the HTML conversion, set setJavaScriptEnabled(boolean)
to
false
.
Note: This API requires HTML-to-PDF conversion feature in your license.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
interface | HtmlToPdfConverter.PageLoadingProgressListener | Listener for page loading progress updates used when loading HTML page in HtmlToPdfConverter . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Single<File> |
convertToPdfAsync()
Performs HTML-to-PDF conversion to a temporary file in application's cache directory.
| ||||||||||
Completable |
convertToPdfAsync(File outputFile)
Performs HTML-to-PDF conversion to specified file.
| ||||||||||
HtmlToPdfConverter |
density(int densityDpi)
Sets the density that should be used when converting HTML images to PDF.
| ||||||||||
static boolean |
doesDeviceSupportConversion(Context context)
Checks whether PSPDFKit can perform HTML-to-PDF conversion on this device.
| ||||||||||
static HtmlToPdfConverter |
fromHTMLString(Context context, String htmlString, String baseUrl)
Creates HTML-to-PDF converter from HTML string.
| ||||||||||
static HtmlToPdfConverter |
fromHTMLString(Context context, String htmlString)
Creates HTML-to-PDF converter from HTML string.
| ||||||||||
static HtmlToPdfConverter |
fromUri(Context context, Uri uri)
Creates HTML-to-PDF converter from
Uri . | ||||||||||
HtmlToPdfConverter |
pageSize(Size pageSize)
Sets the size of the created PDF.
| ||||||||||
HtmlToPdfConverter |
setJavaScriptEnabled(boolean isEnabled)
Enables or disables JavaScript processing.
| ||||||||||
HtmlToPdfConverter |
setPageLoadingProgressListener(HtmlToPdfConverter.PageLoadingProgressListener pageLoadingProgressListener)
Sets listener that will be called whenever page loading progress changes.
| ||||||||||
HtmlToPdfConverter |
setResourceInterceptor(ResourceInterceptor resourceInterceptor)
Sets resource interceptor that will be called whenever the HTML converter wants to load any
page resource (image, stylesheet, JavaScript etc.).
| ||||||||||
HtmlToPdfConverter |
timeout(long timeout)
Sets the timeout for loading the HTML document when converting.
| ||||||||||
HtmlToPdfConverter |
title(String title)
Sets the document title (set via
setTitle(String) ). |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Performs HTML-to-PDF conversion to a temporary file in application's cache directory.
This method operates asynchronously on the io()
scheduler.
Performs HTML-to-PDF conversion to specified file.
This method operates asynchronously on the io()
scheduler.
outputFile | Output file to write converted PDF. |
---|
Sets the density that should be used when converting HTML images to PDF. Defaults to 300 dpi.
densityDpi | Density to use in dots per inch. |
---|
Checks whether PSPDFKit can perform HTML-to-PDF conversion on this device. This checks for
availability of the WebView
system packages. This method returns false
, if
the WebView package is not installed or has been disabled by the user.
Note that this method must be called from the main thread.
context | Context used to check installed WebView packages. |
---|
true
if the conversion is available, false
if not.IllegalStateException | if not called from the main thread. |
---|
Creates HTML-to-PDF converter from HTML string.
You can provide any resources (images, stylesheets, JavaScript etc.) required by the HTML
by setting custom ResourceInterceptor
via setResourceInterceptor(ResourceInterceptor)
.
Configured baseUrl
will be used as the base URL for resolving any relative URLs
for any resources. Note that the ResourceInterceptor
set via setResourceInterceptor(ResourceInterceptor)
is called for relative URLs only when the
baseUrl
is set.
context | The context to use. |
---|---|
htmlString | String with HTML content to convert to PDF. |
baseUrl | Base url to use to load relative URLs in the HTML. May be null .
|
Creates HTML-to-PDF converter from HTML string.
You can provide any resources (images, stylesheets, JavaScript etc.) required by the HTML
by setting custom ResourceInterceptor
via setResourceInterceptor(ResourceInterceptor)
. In this case, you'll need to provide base URI
for resolving relative URIs of these resources via fromHTMLString(Context, String, String)
.
context | The context to use. |
---|---|
htmlString | String with HTML content to convert to PDF. |
Creates HTML-to-PDF converter from Uri
. Supported URIs are:
Converter will try to load all linked resources (images, stylesheets, JavaScript etc.), if
they are accessible. You can provide otherwise inaccessible resources or override default
ones by setting custom ResourceInterceptor
via setResourceInterceptor(ResourceInterceptor)
.
context | The context to use. |
---|---|
uri | Base URI for the HTML content that should be converted to PDF. |
Sets the size of the created PDF. Defaults to PAGE_SIZE_A4
.
pageSize | Page size in PDF points. |
---|
Enables or disables JavaScript processing. Defaults to true
.
Note: JavaScript execution could cause security and performance issues. Please review your JavaScripts carefully.
isEnabled | true to enable JavaScript processing for loaded HTML documents.
|
---|
Sets listener that will be called whenever page loading progress changes.
pageLoadingProgressListener | Listener to set or null to reset the listener.
|
---|
Sets resource interceptor that will be called whenever the HTML converter wants to load any page resource (image, stylesheet, JavaScript etc.). Use this if you want to inject custom resources that are otherwise not accessible from the base URL or when you want to override default resource resolution.
resourceInterceptor | Interceptor to use or null to reset the interceptor.
|
---|
Sets the timeout for loading the HTML document when converting. Defaults to 30000 ms.
timeout | Timeout in ms. |
---|
Sets the document title (set via setTitle(String)
). Defaults to
HTML title if present (i.e. contents of the <title>
tag); sets no title if the HTML
document has no title.
title | Title that should be set for the converted document, or null to set
default title.
|
---|