I am doing a project which will finally print a pdf file or doc file to the printer as "another user". But now I stuck on how to print document in Java.
I know there is a pdf renderer in java, developed by sun, which can convert pdf to pcl file.
After the conversion, I want to print the pcl file to remote printers.
My previous way is "copy /b filename \printserver\printer", however, this approach actually is too lowlevel and cannot even display the document name, and sometime is not working.
I wonder is there a better approach of java to send the PCL file to print server, where the server can actually detect the document name and host name(which I want to specify in the program, not the original one). This one is really driving me crazy...Thanks!
Have you looked into java print service?
You can find some useful code here
http://docs.oracle.com/javase/1.4.2/docs/guide/jps/spec/printing.fm2.html
Related
I have the following problem:
I've created an electron app which prints out receipt with a thermal printer, however, the print quality really seems to suffer when using any other formats that .txt, .rtf or .html.
The module I've been using so far is node-native-printer and although html is listed as a supported file type, it only prints out the unrendered html text.
I've also tried JTextComponent but I could not get it to work with RTF or HTML.
I am not familiar with C# so I do not know how I could play around with node-native-printer's .cs files to get it to work.
Also ideally there should not be any dialog popping up when printing and most importantly no extra user input required.
I'd appreciate any help!
I have a JAVA program that creates a PDF file.
However I need to send this PDF file to a printer via SDK for this printer that would only accept PRN file type …
I understand that a the PRN file is built by using the specific driver for the specific printer, so the java program should be able to pick the driver for use in order to convert the PDF to a PRN file
As for the question, why wouldn’t I send the PDF file directly to print via the driver, well, this is a zebra printer that prints and encode smart cards, performing printing and encoding is only available if approaching it from the SDK, if I were to sent in directly to the driver , it would only print without encoding the cards
The PDF will need to be rendered and set into the format desired by the printer.
GhostScript is what you want for this, the command would be:
gswin32c -dNOPAUSE -sDEVICE=PrinterName -sOutputFile="c:/out.prn" "file.pdf"
As i understood your printer manufactor is Zebra and you are searching vendor specific solution to the problem. Here is an open source project jZebra that is support many vendors and as i understood it has capability to print from PRN file. Check this thread if it is applicable for you or not.
if you are lucky and the file you are trying to open contains plain text you can try this:
Change extension of this file from prn to txt
Open new file in notepad or any other text editor
You may see exactly what you wanted plus some header that can be removed later.
Zebra printers use zpl language. You can design your zpl template and send it to your printer as a prn file.
^XA
^FX Top section with company logo, name and address.
^CF0,60
^FO50,50^GB100,100,100^FS
^FO75,75^FR^GB100,100,100^FS
^FO88,88^GB50,50,50^FS
^FO220,50^FDInternational Shipping, Inc.^FS
^CF0,40
^FO220,100^FD1000 Shipping Lane^FS
^FO220,135^FDShelbyville TN 38102^FS
^FO220,170^FDUnited States (USA)^FS
^FO50,250^GB700,1,3^FS
^XZ
Copy the text above and paste it into the notepad. Save it as abc.prn and send it to your printer.
You will see, it will print a label (I assume you are using a 4x6 printer).
So you can create your own zpl template using this website. http://labelary.com/viewer.html
and this guide
https://www.zebra.com/content/dam/zebra/manuals/en-us/software/zpl-zbi2-pm-en.pdf
I already tested window.print() command for this purpose but it is not fulfill my requirement.
I also used print content of iframe in which source is pdf file but it is only work in chrome not in other browser.
I want to print pdf files automatically using code instead of open file and print it.
For example there are two files such as 1.pdf and 2.pdf in any directory and source is given then how can print both files using either javascript or php or both.
I already tested window.print() command for this purpose but it is not fulfill my requirement.
My required as image as:
Million thanks in advance.
This is not possible since most browsers, unlike google chrome (where it works) don't have a built in pdf viewer.
The printing of a pdf document is up to the pdf reader, whether or not it is installed as a browser plugin, not the browser.
I fix this issue of merging multiple pdf or image or both by using imageMagick.
Using below command we can merge pdf and image as:
<?
$cmd = "test.pdf test.jpeg final.pdf";
exec("convert $cmd");
?>
After completed merging process, open final.pdf automatically using code then user can print it easily.
You can find more.
is there a way to print pdf files from a java webapplication on the local printer of the end user (connected via vpn)?
The simple lookup of a printer via Java Printing Service always returns printer which are not able to print pdfs. Are there other libs which can be used for printing in java?
By the way, just opening the pdf in the browser is not an option, though it must be possible to run scheduled batch printing without user interaction.
Thanks in advance
Since the Java web application can't connect to the client (the client connects to it), there is no way to do this.
The only solution is to send the PDF file to the client via a download link or similar, so that the browser on the client can offer the user to save or print it.
I currently have the same problem - having to find a way to print PDF and Word documents.
And the short answer is:
It's not as easy as you'd want it to be.
The problem is that "someone" has to do the interpretation of your document. And that someone is either the printer or you.
Not all printers support DocFlavor.x.PDF. We have four printers at my company (one was bought just last month) and none of them does.
If you find a printer that does accept that DocFlavor you're done.
But since chances are the printer doesn't know what to do with a PDF file, you have to render the document yourself. I can recommend trying PDFRenderer and PDFBox. For me PDFRenderer works great and PDFBox doesn't print text correctly, but other people report the opposite. So, you will have to try for yourself.
All that still doesn't help me with Word docs, but that's not your concern.
Our application is a client/server setup, where the client is a standalone Java application that always runs in Windows, and the server is written in C and can run on either a Windows or a Unix machine. Additionally, we use Perl for doing various reports. Generally, the way the reports work is that we generate either a text file or an xml file on the server in Perl and then send that to the client. The client then uses FOP or similar to convert the xml into a pdf. In either the case of the text file or the eventual pdf, the user select a printer via the java client and then the copied over file prints to the selected printer.
One of our "reports" is used for creating barcodes. This one is different in that it uses Perl to fetch/format some data from the database and then sends that to a C application that creates some Raw print data. This data is then sent directly to the printer (via a simple pipe in Unix or a custom application in Windows.
The problem is that this in no way respects the printer selected by the user in the Java client. Also, we are unable to show a preview in said client. Ideally, I'd like to be able convert the raw print data into a ps/pdf or similar on the server (or even on the client) and then send THAT to the printer from the client. This would allow me to show a preview as well as actually print to the selected printer.
If I can't generate a preview, even just copying over the raw data in a file to the Java client and then sending that to the printer would probably be "good enough." I've been unable to find anything that is quite what I'm trying to accomplish so any help would of course be appreciated.
Edit: The RAW data is in PCL format. I managed to reconcile the source with a PCL language reference guide.
Have you had a look at iText?
You willl need to find some way of interpreting the RAW format, which most likely is some printer language like PCL or HPGL into a format you can use. This is probably best done at serverside.
A java based PCL interpreter can be found at http://openpcl.sourceforge.net/ - I have no experience with it.
I figured out a way to generate the barcodes using XSL-FO directly. This is the "correct" answer based on our architecture and trying to do anything else would have been just a dirty hack.