Some test text!

menu
Web/HTML to PDFkeyboard_arrow_down

Convert HTML to PDF in Android

HTML to PDF conversion is available for Android API 19 and above.

The HTML to PDF conversion API accepts different sources, such as HTTP/HTTPS URLs, HTML strings, and everything that can be loaded in a WebView.

linkFrom link

To convert a link URL to PDF, simply:

public void convertFromUrl(Context context, String url, Uri folder, String outputFileName) {
    HTML2PDF.fromUrl(context, url, folder, outputFileName, new HTML2PDF.HTML2PDFListener() {
        @Override
        public void onConversionFinished(String pdfOutput, boolean isLocal) {
            // Handle callback when conversion finished
        }

        @Override
        public void onConversionFailed(String error) {
            // Handle callback if conversion failed
        }
    });
}

linkFrom HTML string

To convert an HTML string to PDF, simply:

public void convertFromHtml(Context context, String baseUrl, String htmlSting) {
    HTML2PDF.fromHTMLDocument(context, baseUrl, htmlSting, new HTML2PDF.HTML2PDFListener() {
        @Override
        public void onConversionFinished(String pdfOutput, boolean isLocal) {
            // Handle callback when conversion finished
        }

        @Override
        public void onConversionFailed(String error) {
            // Handle callback if conversion failed
        }
    });
}

where myBaseUrl is the URL to use as the page's base URL. If null defaults to about:blank and myHtmlData is a String of data in the UTF-8 encoding. Click here for more info.

linkFrom other sources

If none of the above fit your needs, you can also pass in a WebView directly for conversion:

public void convertFromWebView(WebView myWebview) {
    HTML2PDF.fromWebView(myWebview, new HTML2PDF.HTML2PDFListener() {
        @Override
        public void onConversionFinished(String pdfOutput, boolean isLocal) {
            // do something with the PDF output
        }

        @Override
        public void onConversionFailed(String error) {
            // handle error
        }
    });
}

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more
close