B4J Question Html script to pdf document

le_toubib

Active Member
Licensed User
Longtime User
Hi all
Is there a way to programmatically convert html script to a pdf document ?
I.e :
Html2pdf("<p>hello</p>", "1.pdf")

Thanks
 

Didier9

Well-Known Member
Licensed User
Longtime User
Just a thought:
Maybe you can do it by using a WebView to render the html and print the resulting page as pdf?
It looks like if you can output the webview on a canvas, you can print the canvas as pdf with this:
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Upvote 0

MegatenFreak

Active Member
Licensed User
I've handled this situation in two different ways, depending on my needs:
1. Create the HTML, write it into a file, and then open it with Word (directly from you B4J app). Word supports HTML and from there you can edit or convert to PDF or anything.
2. Load the HTML string into a WebView. You can make it invisible if the user doesn't need to see it, and then send it to the printer. You can then choose a PDF printer. There're lots of them. The function I use to print a WebView:

B4X:
Sub PrintWebView(w As WebView)
    Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob
    PJ.ShowPageSetupDialog(Null)
    PJ.ShowPrintDialog(Null)
    Dim WVJO As JavaObject = w
    WVJO.RunMethodJO("getEngine",Null).RunMethod("print",Array(PJ.GetObject))
    PJ.EndJob
End Sub
 
Upvote 0
Top