📄
PDF Creator Android
  • Introduction
  • Docs
  • Installation
  • Getting Started
  • Available Views
    • PDFVerticalView
    • PDFHorizontalView
    • PDFTextView
    • PDFImageView
    • PDFLineSeparatorView
    • PDFPageBreakView
    • PDFTableView
      • PDFTableRowView
  • Generate Pdf From HTML
    • Html To Pdf
    • WebView To Pdf
Powered by GitBook
On this page
  1. Generate Pdf From HTML

Html To Pdf

You can create a Pdf from Html using Utility function PDFUtil.generatePDFFromHTML(getApplicationContext(), pdfFileToSave, "<html string />", callback);

Example:

// Create Temp File to save Pdf To
final File savedPDFFile = FileManager.getInstance().createTempFile(getApplicationContext(), "pdf", false);
// Generate Pdf From Html
PDFUtil.generatePDFFromHTML(getApplicationContext(), savedPDFFile, " <!DOCTYPE html>\n" +
    "<html>\n" +
    "<body>\n" +
    "\n" +
    "<h1>My First Heading</h1>\n" +
    "<p>My first paragraph.</p>\n" +
    " <a href='https://www.example.com'>This is a link</a>" +
    "\n" +
    "</body>\n" +
    "</html> ", new PDFPrint.OnPDFPrintListener() {
        @Override
        public void onSuccess(File file) {
            // Open Pdf Viewer
            Uri pdfUri = Uri.fromFile(savedPDFFile);

            Intent intentPdfViewer = new Intent(MainActivity.this, PdfViewerActivity.class);
            intentPdfViewer.putExtra(PdfViewerActivity.PDF_FILE_URI, pdfUri);

            startActivity(intentPdfViewer);
        }

        @Override
        public void onError(Exception exception) {
            exception.printStackTrace();
        }
});
PreviousPDFTableRowViewNextWebView To Pdf

Last updated 4 years ago