Printer independent way to preview and print generic text in Java - java

I examined the possibilities of previewing and printing generic text in Java. The requirements which I depend on are:
I should be able to specify font family and size of the font for both the preview component and for printed text.
The print preview must look exactly the same as the printed text.
Printing must be independend of printer device (no printer specific commands to define fonts etc.).
Printing of approx. 20 pages of generic text must start immediately (without any significant delay caused by data processing)
To meet the aformentioned requirements I first tried the Java Print Service API. I created the JTextPane which contained the text to preview and print. By using JTextPane I was able to specify the font so the result looked fancy. To print data from JTextPane I used the standard procedure, which is independend from printer device
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(myTextPane);
pj.print();
Everything would be fine if printing 20 pages of plain text wouldn't start in 15 seconds after the print() method was executed.
However printing starts immedialety when I print the same text as raw byte array ('application/octet-stream') with few PCL specific commands to set a proper font. But this approach is printer specific and there is also a problem with previewing the text so that the priview look exactly the same as printed text.
The problem with JTextPane is most likely caused by the fact that the data sent to printer are too large (pixel-by-pixel) while the second solution is a matter of few bytes. Unfortunately none of these solutions are sufficion for me because they don't meet all of the requirements.
Probably the solution would be if there is some 'facade' over printer control languages (PCL, ESC/P, ...) which would allow me to set the text font independently from the printer device. The problem with print preview would not be solved, but at least the printing would start immediately.
Any advice how to print the plain text not breaking the aforemention 4 criteria?

The problems above seems to be linked to Linux print driver and Cups.
I tried to print some text on Windows and everything works fine. Printing even starts immediately.

Related

Exclude / Block PDF Printer

I wanna know if it's possible to recognize printer in Java/C# as a pdf printer and block them.
The main reason behind this is, that i have a printing software with pictures which include copyrights. Within the web its easy for me to safe these copyrights with watermarks etc, but also the user is able to print out of the application.
If an user print the image to a pdf printer, he could cut the image out of the pdf f.e. .
Because in the printing result, the customer dont want a watermark
I dont think that this is possible by only checking a property. What you can do is first to get all the printers by
PrinterSettings.InstalledPrinters
for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++){
pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
}
after that you can write out the printer settings with PrintSystemObject.PropertiesCollection or directly the processor name with the PrintProcessorProperty Class.
Then you need to look at the property if you can specify the PDF Printers with any of these properties.
You could check the print processor of the printer and see if it's a known PDF print processor.
https://msdn.microsoft.com/en-us/library/system.printing.printsystemobject.propertiescollection%28v=vs.110%29.aspx

Where do you get zebra printer fonts for print preview?

I'm printing labels with a Zebra printer using Java by sending ZPL II commands. I want to show a preview of the label before sending it to the printer.
Rather than trying to send fonts to the printer, I'd like to use the built in fonts.
I can see a list of the fonts on page 60 of the programming guide volume 2. There are 15 of them, each labeled with a single letter and no reference to the name of an equivalent screen font.
I can generate an image to display of the barcode, but I'm having trouble figuring out how to display the text appropriately because outside of the OCR fonts, I don't know of an equivalent font to leverage on-screen.
I haven't found any documentation that lists them at Zebra's website, and my searching is only returning results on how to send screen fonts to the printer (which looks complex enough for me to want to avoid at this point).
Does anybody know where I can get the fonts, or would you be able to provide me with a list of (hopefully free) equivalents?
I took a screenshot of the fonts displayed in the manual for reference.
After much research, I discovered that the fonts Zebra uses are tightly protected because of licensing.
Contacting Zebra about obtaining a license for the fonts is your only option.
The alternative I'm using for now is to preview the label with a free-to-distribute monospaced true-type font (which I haven't yet selected). The document I linked in my question provides size and spacing information for the built-in fonts so I can emulate as close as possible.
The Zebra fonts, except 0, are all bit mapped, fixed width fonts.
Courier should give you a reasonable approximation.
Just scale them using the table in the Zebra manual.
zpl-zbl2-pm-en.pdf
In case anyone stumbles upon this question.
You can generate a label preview using http://labelary.com/ API.

How to simplify label printing alignment configuration?

Using JSP and Jasper Reports, I made an application for printing A4 label pages.
I have to configure my application (set alignment on the PDF page to be generated) according to different pages (2×5, 2×7, 3×10 and 3×11 grids), different printers (Kyocera, OKI and HP) and different PDF viewers (Adobe, Foxit and Nitro).
Example: I set in Jasper Reports an A4 page with a grid of 2×5 and an user who has Foxit Reader will print it on a Kyocera. If another user has Kyocera too but is using Adobe Reader, the space between the columns gets smaller. But if the user has Foxit Reader but will print on an OKI, the whole document goes left and even gets cut.
To configure each individual label page is unavoidable, but can it be possible for me not have to set the page alignment for specific PDF viewer or printer (at least one of those)? It can be a way to skip the PDF generation or some conventional configuration that all printers would interpret - to get my page printed exactly the same, regardless of PDF viewer or printer.
Are you sure this is not a setting in Foxit Reader and/or Adobe reader that is causing the issue?
I know in Adobe reader there is a setting in the print dialog under Page Sizing & Handling. They should use Actual Size so as to not do any scaling or manipulation of the image.
In Foxit Reader it is under Print Handling. You need to set Scaling Type to None. The default seems to be Fit to Printer Margins.
You should not have to do anything different for each PDF reader and/or each version and combination of printer. That is a maintenance nightmare you should not try to take this on. You would have to make changes every time they bought a new printer, and potentially when an upgrade to their reader comes out.
Best bet is to figure out why they are producing different results, and tackle that issue, instead of brute forcing the problem. I am pretty sure this is more a training issue with your users, and telling them about these settings should clear up the problem.
UPDATE: After some more digging it seems to be possible to set the value of the Print Scaling while exporting. After you create your JRPdfExporter you need to set JRPdfExporterParameter.PRINT_SCALING to JRPdfExporterParameter.PRINT_SCALING_NONE:
exporter.setParameter(JRPdfExporterParameter.PRINT_SCALING, JRPdfExporterParameter.PRINT_SCALING_NONE);
I do not know if this will work for Foxit Reader also, but I would assume it would.

Printing data to a pre printed form/stationery

We have a requirement where we already have pre printed stationery and want user to put data in a HTML form and be able to print data on that form. Alignment/text size etc are very important since the pre-printed stationery already has boxes for each character. What could be a good way to achieve this in java? I have thinking of using jasper reports. Any other options? May be overlay image with text or something?
Also we might need to capability to print on plain paper in which case the boxes needs to be printed by our application and the form should match after the printed with the already printed blank stationery containing data.
Do we have some open source framework to do such stuff?
Jaspersoft reports -- http://sourceforge.net/projects/jasperreports/
You will then create XML templates, then you will be able to produce a report in PDF, HTML, CSV, XLS, TXT, RTF, and more. It has all the necessary options to customize the report. Used it before and recommend it.
You will create the templates with iReport then write the code for the engine to pass the data in different possible ways.
check http://www.jaspersoft.com/jasperreports
Edit:
You can have background images and overlay the boxes over it and set a limit on the max character size ... and many more
It is very powerful and gives you plenty of options
Here is one of iReport's tutorial for a background image http://ireport-tutorial.blogspot.com/2008/12/background-image-in-ireport.html
The big problem when printing form content that has been filled in electronically, is aligning it correctly on the pre-printed form. You may get content to align for one printer, but when you use another it is completely misaligned.
Fly Software have a form design product called InForm Designer that gets around the problem nicely by allowing users to specify and save vertical and horizontal offsets for printers. This ensures filled in form content is always aligned. I've tried it and it works perfectly. Take a look for yourself here...
http://www.flysoftware.com/products/inform_designer/overview.asp
It might be worth implementing a printer offset similar to InForm's in your own application (if possible).
Some things to think about.
First in terms of the web page, do you want use the stationery as the form layout?
Does it have to be exact?
Combed boxes (one for each character)
Do you want to show it like that on the web page, or deal with the combing later.
How are you going to deal with say a combed 6 digit number. Is this right aligned. What if they enter 7 digits. Same for text. what if it won't fit.
Font choices, we had a lot of fun with W...
How aligned do you want the character within the box, what font limitations does that imply, some of the auto magic software we looked at did crap like change the size of each character.
Combed editing is a nightmare, we display combed, but raise an edit surface the size of the full box on selection.
Another thing that might drive you barking mad, you find find small differences in the size and layout of the boxes, so they look okay from a distance but a column of boxes sort of shifts about by a pixel. Some of testing guys had to lend us their electron microscopes, so we could see how many ink molecules we were out by. :(
Expect to spend a lot of time in the UI side of things, and remember printed stationery changes, so giving yourself some sort of meta description of the form to start with will save you loads of trouble later on.

Syntax for generating Barcode using PCL syntax

Iam searching for a PCL syntax to generate and print the BARCODE. If anyone having any information about the same, please help me. I have tried googling it, but didnt find anything.
First you need a barcode font. Once you have this simply move the cursor to the spot you want (in the example 300 x 300 in whatever unit of measure you've defined), and then call the barocde and put your text down. A simple exmample might look like htis:
<ESC>*p300x300Y<ESC>*c100D1234567890
This assumes that you have embedded the barcode as part of the print job and assigned the numeric 1000 to the font call. Just search the web for "pcl barcode font" and you will find many sites that sell these fonts and provide instructions on how to call. If the printer has barcode fonts embedded, try printing a font list and it should provide the escape sequence you need to call.

Categories

Resources