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
 
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
Upvote 0
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:

Code:
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
Back
Top