Search code examples
androidandroid-pdf-api

Convert HTML String to PDF with native PrintedPdfDocument


How can I convert HTML string (created on the fly) to PDF only using native PrintedPdfDocument (API 19 or higher)? I look for the solution in which I do not need to add any external libraries.


Solution

  • If the HTML is very limited, you can try TextView and some HTML-to-Spanned converter (e.g., Html.fromHtml()).

    Or, as I noted in comments, you can use WebView, though you indicate that it does not meet your business requirements, and I am not sure that you can get to the PDF anyway.

    Otherwise, your only library-free option is to send the HTML to a server, one that can return to you a PDF.