B4J Library jPrint V 1.61

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 "".
 

Attachments

  • jPrintLib(V1.50 Beta).zip
    10.4 KB · Views: 659
  • jPrintTest(v1.50).zip
    2.2 KB · Views: 907
  • jPrintLib V1.60.zip
    10.6 KB · Views: 683
  • jPrintLibrary(1.61).zip
    10.7 KB · Views: 1,165
  • jPrintSource(1.61).zip
    3.2 KB · Views: 996
Last edited:

stevel05

Expert
Licensed User
Longtime User
Thanks for sharing,

Just tested Printfile, there is no option to select the destination printer, it printed to my default printer. Is this possible? I don't know the jPrint library.
 

stevel05

Expert
Licensed User
Longtime User
A bit more testing, it printed OK, but no form feed at the end of the Job. I had to turn off the printer to feed it through.

Changed my default printer to PDF and the document was empty. It could be the same thing causing it perhaps.

It's a very promising library. Nice work.
 

Daestrum

Expert
Licensed User
Longtime User
If the last line in a text file does not have a CRLF as it's last character, then it stalls the printer, I have searched for an equivalent 'flush' command, but I think I will have to write one.
I think I can re-write the filePrint so it displays the printer box - will look tomorrow.

Looking at the available outputs, it will be able to print images from ImageViews, but concentrating on the text based printing at the moment.

Also going to try and add a print preview option.
 

logemag

Member
Licensed User
Longtime User
a very nice news for the new year !!! Good job
 

Daestrum

Expert
Licensed User
Longtime User

Attachments

  • jPrintLibSource.zip
    2.3 KB · Views: 629

Daestrum

Expert
Licensed User
Longtime User
As I don't actually write things in B4J (other than test modules), can someone tell me what other data types can be in a TableView, as I only handle String and Label types at present for printing.
 

Daestrum

Expert
Licensed User
Longtime User
New version uploaded.

If anyone is using on Mac or Linux, I would be interested to know how it performs on them.
 

William Hunter

Active Member
Licensed User
Longtime User
Hello Daestrum – I today found your latest post re your new jPrint library. I tested printer.printFile(“mytextfile.txt”) and could not get the text file to print to a HP laser printer. The text file was sent to the printer queue, but was named “java printing”. The file size was 0 bytes, and the data type was RAW.

I also tried to print to two HP Inkjet printers. In each case paper was fed into the printer, then printing just stopped. Nothing was ever printed, and I had to push the printer cancel button to eject the blank page.

Your library looks very promising. Good luck with it. I would love to be able to use it. :D

Best regards
 

BPak

Active Member
Licensed User
Longtime User
New version uploaded.

If anyone is using on Mac or Linux, I would be interested to know how it performs on them.

Have Version 1.02 of jPrint installed on windows and compiled the jPrintTestExample to Release mode.

I have a Mac Lion and installed Epson XP-100 on both Windows (Bootcamp) and the OSX

The jPrintTest ran great on Windows and printed out two sheets.

The jPrintTest.jar file would not run on the Mac.

Do not know much about the Mac system but I have other JAR files made with B4J running ok on it.

Mac image for jPrintTest attached...

EDIT - Console.log file saved into Windows WordPad showing the output from Mac when trying to run the prog.
 

Attachments

  • jprinter.png
    jprinter.png
    20.3 KB · Views: 770
  • print-console.zip
    1.9 KB · Views: 546
Last edited:

Daestrum

Expert
Licensed User
Longtime User
Looking up the error it appears mac doesn't load the full awt library. There are various work arounds I will try and incorporate in jPrint.
 

William Hunter

Active Member
Licensed User
Longtime User
@ Daestrum – I have been trying to print a .txt file using Log(printer.printFile("C:\~jPrintTest\notes.txt")) with your jPrintTest, without success. I have been using a .txt file produced by B4J components for testing. I get no printer output as outlined in my previous post.

I have no problem in printing your two table pages, just when I try to print the contents of a .txt file. It would be helpful if you would include copies of your testFile.txt and testeval.js files in your jPrintTest.zip, so that we can see just what type of files you are having success in printing. No test .txt file that I try to print, using your jPrintTest, will produce printer output.

Further commentary regards usage would be greatly appreciated.

Regards
 

Daestrum

Expert
Licensed User
Longtime User
Sorry it never occurred to me to supply the files I was printing while testing.
 

Attachments

  • testfiles.zip
    762 bytes · Views: 606

Theera

Well-Known Member
Licensed User
Longtime User
Hi Daestrum,
I like your this library,but I 've problem to print out on paper. Please guide to me,Thank you in advance.
 

Attachments

  • TestPrinting.zip
    542 bytes · Views: 587

rapblack

Member
Licensed User
Longtime User
Dear All,
How to set Font name of Text file ? I would like set text file to mono space such as droidsans mono or etc.
Best Regard.
 

William Hunter

Active Member
Licensed User
Longtime User
@ Daestrum – Thank you for the test files. Your testFile.txt file is no different in type than those of my own that I have attempted to print (ANSI as UTF-8). I did try to print your test file, but got the same result as previously, no printer output.

This is the log:
Program started.
Printing to : HP LaserJet 1018
ok

The log indicates success, but this is not the case. Why you are able to print your test file, while I am not, is very odd. I am very interested in your library, and will continue to watch this thread. Perhaps as your work progresses, this problem will be resolved.

I’m quite surprised that this thread hasn’t had much commentary from others. I would have thought that the ability to print with B4J would be of great interest to many on this forum.

Best regards :)
 

agraham

Expert
Licensed User
Longtime User
I’m quite surprised that this thread hasn’t had much commentary from others. I would have thought that the ability to print with B4J would be of great interest to many on this forum.
Personally I'm waiting for the next iteration of JavaFX, due March sometime though it may take longer before B4J supports it, which will support printing for any node, including native print and page setup dialogs for user print configuration, and should also support Rich Text.
https://wiki.openjdk.java.net/display/OpenJFX/Printing+for+JavaFX
 

Daestrum

Expert
Licensed User
Longtime User
@William - it does seem odd as I print to an HP printer (photosmart) and the pages all come out. Did you try sending printer.print(" ") to the printer to see if it forces the page out ?

@agraham - That is the preferred solution waiting for java 8, but I am a person with too much time on their hands, and can't resist a challenge. ;)
 
Top