B4J Tutorial Print with PrintHtml tool

PrintHtml is a small Windows utility that you can use to print from your app.

First you should download PrintHtml.exe and also the DHTML Editing Control: http://www.printhtml.com/download.php

Copy PrintHtml.exe to the Objects folder of your app.

SS-2013-12-09_14.45.11.png


Using jShell library we call this utility to print the html string. You can use HTML language to format the output.

In the above screenshot I used a PDF printer to create a PDF document.
 

Attachments

  • Print.zip
    1.4 KB · Views: 1,853

ValDog

Active Member
Licensed User
Longtime User
Can this be used with B4A? If not, is there a B4A alternative for printing from an application - other than the B4AServer?



PrintHtml is a small Windows utility that you can use to print from your app.

First you should download PrintHtml.exe and also the DHTML Editing Control: http://www.printhtml.com/download.php

Copy PrintHtml.exe to the Objects folder of your app.

SS-2013-12-09_14.45.11.png


Using jShell library we call this utility to print the html string. You can use HTML language to format the output.

In the above screenshot I used a PDF printer to create a PDF document.
PrintHtml is a small Windows utility that you can use to print from your app.

First you should download PrintHtml.exe and also the DHTML Editing Control: http://www.printhtml.com/download.php

Copy PrintHtml.exe to the Objects folder of your app.

SS-2013-12-09_14.45.11.png


Using jShell library we call this utility to print the html string. You can use HTML language to format the output.

In the above screenshot I used a PDF printer to create a PDF document.
 

ValDog

Active Member
Licensed User
Longtime User
Can this be used with B4A? If not, is there a B4A alternative for printing from an application - other than the B4AServer?


Never mind my last - as I read it I realize it is a stupid question - sorry!
 

Theera

Well-Known Member
Licensed User
Longtime User
Hi Erel,

PrintHtml is a small Windows utility that you can use to print from your app.

In words of the line, I could PrintHtml utility only Windows OS,What utility do Linux OS and Mac OS has used for printing?
 

gezueb

Active Member
Licensed User
Longtime User
Hi, has anybody tried to specify the font size, either in HTML or as command line arguments?
Thanks for Help
Georg
 

jemel

Member
Licensed User
Longtime User
@Erel I already tried the jPrint and JavaFX8 library but it seems like it is incompatible with the Raspberry Pi.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

I tested PrintHTML.exe and it is quite easy to implement. Thank you, Erel, for the example.

I found problems with it.

1. Program causes an exception if the text contains an apostrophe (htm file).
2. Horizontally cuts half of the last line in a page. (is there a parm to reduce the height of the printable area? - Answer: all parameters (not perfectly clear) can be found in www.printhtml.com)

I could not upload project because of the size of PrintHTML.exe, so code is included below. If you remove the apostrophe or single quote - it works.

Any responses will be appreciated.

Sandy

PS: To use commercially, you need to contact Bullzip.com for a license agreement. This is the EULA statement concerning distribution commercially:
If you include it with your own commercial product a redistribution agreement with PrintHTML is required.
This somewhat conflicts with the printhtml.com website:
License
This program is freeware. You may use it without paying for it. In case you want to distribute it with your own application then you must make on a small payment to support the development.

B4X:
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private HTMLEditor1 As HTMLEditor
    Private temp As JavaObject
    '***
    'HTMLEditor1 when Enter is pressed, it is a new paragraph and it inserts a line.
    '***

    Private Button1 As Button
    Private btnPrint As Button
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.

    Dim INITIAL_TEXT As String
    INITIAL_TEXT = $"<html><body>Lorem ipsum dolor sit
    amet, consectetur adipiscing elit. Nam tortor felis, pulvinar
    in scelerisque cursus, pulvinar at ante. Nulla consequat
    congue lectus in sodales. Nullam eu est a felis ornare
    bibendum et nec tellus.
    <br /> <b>
    Vivamus non metus tempus augue auctor
    ornare. Duis pulvinar justo ac purus adipiscing pulvinar.
    Integer congue faucibus dapibus. Integer id nisl ut elit
    aliquam sagittis gravida eu dolor. Etiam sit amet ipsum
    SEE APOSTROPHE  ' </b>
    <br />
    Special Notes: $Date{DateTime.now} </body></html>"$

    HTMLEditor1.HtmlText=INITIAL_TEXT
    MainForm.Show

End Sub

Sub btnPrint_Action
    Dim js As Shell
    Dim params As List
    params.Initialize
    'save the text to a file. New lines characters are replaced with <br/>.
    File.WriteString(File.DirApp,"TestHTML.htm",HTMLEditor1.HtmlText)
    Log("1")
    params.Add("printername=" & HTMLEditor1.HtmlText) '.Replace("'","*"))
    params.Add("file=TestHTML.htm")
    js.Initialize("js", "printhtml.exe", params)
    js.WorkingDirectory = File.DirApp
    js.Run(-1) 'run with no timeout
    Log("2")

    btnPrint.Enabled = False
End Sub

Sub js_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log("Success=" & Success & ", StdOut=" & StdOut & ", StdErr=" & StdErr)
    btnPrint.Enabled = True
End Sub
 
Last edited:
Top