B4J Tutorial Print with PrintHtml tool

Discussion in 'B4J Tutorials' started by Erel, Dec 9, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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.


    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.

    Attached Files:

  2. ValDog

    ValDog Active Member Licensed User

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

  3. ValDog

    ValDog Active Member Licensed User

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

    Theera Well-Known Member Licensed User

    Hi Erel,

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

    Erel Administrator Staff Member Licensed User

    Theera likes this.
  6. gezueb

    gezueb Member Licensed User

    Hi, has anybody tried to specify the font size, either in HTML or as command line arguments?
    Thanks for Help
  7. jemel

    jemel Member Licensed User

  8. Erel

    Erel Administrator Staff Member Licensed User

  9. jemel

    jemel Member Licensed User

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

    Erel Administrator Staff Member Licensed User

    I never worked with lpr and I'm not sure at all that it is supported on Raspberry Pi. If it is supported then you can use jShell to run it like you run any external program.
  11. tdocs2

    tdocs2 Well-Known Member Licensed User


    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.


    #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
    "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>"$


    End Sub

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

        btnPrint.Enabled = 
    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 = 
    End Sub
    Last edited: Nov 3, 2015
  12. Tayfur

    Tayfur Well-Known Member Licensed User

    can i use this way on Raspberry pi (linux)
  13. Erel

    Erel Administrator Staff Member Licensed User

    No. PrintHtml is a Windows program.
  14. Tayfur

    Tayfur Well-Known Member Licensed User

    thank you for feedback
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice