Here is a library I am currently working on.
It allows you to print from your B4J program.
At present it can print TextArea, TextField, TableView and text type files.
I am open to suggestions as to what to add, and general feedback on how it is working for you.
A word of warning, don't try to print an HTML file, unless you have an unlimited supply of paper, it wants to print basically 1 character per page. I have tested with .txt and .js and they seem to work ok.
see jPrintTest for how to call the routines.
version V 1.10
1) Added two fields to jPrint - jPrint.startTabRow and jPrint.endTabRow, these control which rows are printed from the table.
eg, printer.startTabRow = 10
printer.endTabRow = 20
will print out rows 10 to 20 when ??.print(table) is called.
if not set entire table printed, they can be set separately ie printer.startTabRow=10 will print from row 10 onwards etc.
2) Can now print the following table datatypes String, Label, Int, Float and Double.
version V1.20
Can now specify which printer when printing a file.
Version V 1.30
Added limit checks on start and end rows. - rows start and end are inclusive now.
Added datatype boolean for tables.
Added header for table print - prints 'Table : tableID' as header for each page.
Version V 1.40
Added image to tableview - it can't print it but wont cause print to fail.(just prints "--Image--" in cell.)
Added ability to print Strings - printer.print("hello")) etc. probably best used in conjunction with a StringBuilder as once string is sent, will print.
Workaround for fileprint not ejecting page. - use printer.print(" ") to same printer, as it forces form feed after print.
Version V 1.50
Added printFile2(filename,header,font)
Added word wrap on long lines.
printFile2 written to use different method to print a file. Use printer dialog to change margins etc.
see jPrintTest(v1.50) for printfile2 parameters.
Version V 1.60
This has a new routine printer.printFileNoThreads(filename,header,font)
It does not use a separate thread to run the file print. That seemed to be the cause of the problem on the HP laserjet printer failing to print.(if only this were true)
printFile(...) does not print headers or allow choice of font.
printFile2(...) allows headers and font selection and prints on a separate thread.
printFileNoThreads(...) allows headers and font choice but will hang the B4J program while printing.
Version V 1.61
Minor change to printFileNoThreads(...) setting header to "" effectively removes headers and footers from output print. (Still trying to find cause of HP laser failing to print a page)
It appears the header/footer was the problem on the HP.
If you don't get a print out from a file try the above method printFileNoThreads(...) with header set to "".
It allows you to print from your B4J program.
At present it can print TextArea, TextField, TableView and text type files.
I am open to suggestions as to what to add, and general feedback on how it is working for you.
A word of warning, don't try to print an HTML file, unless you have an unlimited supply of paper, it wants to print basically 1 character per page. I have tested with .txt and .js and they seem to work ok.
see jPrintTest for how to call the routines.
1) Added two fields to jPrint - jPrint.startTabRow and jPrint.endTabRow, these control which rows are printed from the table.
eg, printer.startTabRow = 10
printer.endTabRow = 20
will print out rows 10 to 20 when ??.print(table) is called.
if not set entire table printed, they can be set separately ie printer.startTabRow=10 will print from row 10 onwards etc.
2) Can now print the following table datatypes String, Label, Int, Float and Double.
Can now specify which printer when printing a file.
Added limit checks on start and end rows. - rows start and end are inclusive now.
Added datatype boolean for tables.
Added header for table print - prints 'Table : tableID' as header for each page.
Added image to tableview - it can't print it but wont cause print to fail.(just prints "--Image--" in cell.)
Added ability to print Strings - printer.print("hello")) etc. probably best used in conjunction with a StringBuilder as once string is sent, will print.
Workaround for fileprint not ejecting page. - use printer.print(" ") to same printer, as it forces form feed after print.
Added printFile2(filename,header,font)
Added word wrap on long lines.
printFile2 written to use different method to print a file. Use printer dialog to change margins etc.
see jPrintTest(v1.50) for printfile2 parameters.
Version V 1.60
This has a new routine printer.printFileNoThreads(filename,header,font)
It does not use a separate thread to run the file print. That seemed to be the cause of the problem on the HP laserjet printer failing to print.(if only this were true)
printFile(...) does not print headers or allow choice of font.
printFile2(...) allows headers and font selection and prints on a separate thread.
printFileNoThreads(...) allows headers and font choice but will hang the B4J program while printing.
Version V 1.61
Minor change to printFileNoThreads(...) setting header to "" effectively removes headers and footers from output print. (Still trying to find cause of HP laser failing to print a page)
It appears the header/footer was the problem on the HP.
If you don't get a print out from a file try the above method printFileNoThreads(...) with header set to "".
Attachments
Last edited: