Have done some research into this topic, but found no relevant answers. What I need is to print a number of PDF files on one of three forms, which are loaded into different trays of a particular printer. I need to specify which printer to use and it's not the default printer. Additionally, I need to specify which tray to use based upon an attribute of each PDF file and be able to switch between them at run time. Java PrintService seems to only be interested in the local default printer. I'd appreciate any suggestions on how to accomplish this task. Thanks.
The Printer API does allow for talking to different printers other than the default. That being said it is limited. What we did in our shop is to write a JNI layer that talks directly to the Print Queue of Windows and we use that. If you want finer control than the PrintService API provides you will need to write a JNI layer and access that from Java.
You could configure a different printer for each tray in your OS, Then print to that printer depending on the properties of your file.
Thanks for all the suggestions, but I think I have worked this out now. I'm using LPR for the printing and org.apache.commons.net.ftp.FTPClient for the tray switching commands. The actual tray commands are in text files. My tests (so far) have been successful and I did not have to install the printer on my workstation.
Related
I am preparing an acceptance testing tool for java web start application. That app autoprints pdfs to system-installed printers and I want to verify if produced pdfs are correct. To do this I am looking for a way to mock printing.
I found a way to register a custom printing service before the test:
PrintServiceLookup.registerServiceProvider(fakePrinterService);
And I know how to select that fake printer service in my tested application.
Unfortuately I found no implementations of javax.print.StreamPrintService that I can use to print to a file except of sun.print.PSStreamPrintService, which prints to postscript. It also seems to be a part of internals of the JDK, not a public API. Works but leaves some doubts.
Are there any other java printers implementations? It would be best if it could print a pdf.
If not I guess I will go with PSStreamPrintService and ps2pdf conversion.
I want to give print options in our web application..We are using technologies like spring 3.0,hibernate3.0 and mysql database..What i want is single file ,multiple file print options..When i select check box perticular file after click print button it should go to the printer...Please give some example related to this print options using technologies like Spring,hibernate and mysql database..
Thanks in advance
There are many ways you can go with this, so I'll give you some options to consider:
If you don't care too much about the pixel-perfect formatting, the easiest way is to display a new html document with all the files combined and specify #media print in your CSS for that document. Launch the printer dialog for that document using window.print().
If formatting is very important you may consider rendering a PDF document. iText is a good choice since you're using a Java stack.
If you are in an enterprise environment and know which printers a user can access then you can send Postscript or PDF commands directly to the printer. This is probably the most work but also the most transparent to the user since it can be automated completely.
I need to implement a custom printer driver which does the following in the backgroud:
Create a PDF document of the document to print
Send the created PDF document to a predefined email address OR
call a web service and transmit the document there
The pinterdriver should be available for windows and mac osx. My prefered implementation language is Java.
Is this possible with Java?
Are there frameworks available which reduce the coding effort to a minimum?
Are you sure "driver" is really the word you are looking for here? Usually when one says a print driver they actually mean something that translates document data into commands for a printer. I think you are really looking for something of a pre-processor.
In any case, if you want it to look like a printer to the OS, it will be almost impossible to do purely in Java. Your best bet would be to create drivers for each of the platforms that use JNI(or just invoke a JVM), do your processing, then forward it on to the printer.
Although I do not know if a similar approach will work on Windows, what you want to do is almost trivial to do on OS X. Apple already provides a cups-pdf service that converts any printable document into a pdf, all you have to do is take that output, forward it to where it needs to go, then forward it to a printer, no need to do anything in Java.
For an example of how to do this, check out the following project:
https://bitbucket.org/codepoet/cups-pdf-for-mac-os-x/downloads
Windows can be configured to send printer output to a file. You can create a printer in Windows that uses a PostScript driver, and writes it to c:\myfile.txt
In Windows: Add a Printer, Select Local printer, Select Create a new port, and type the file name (Full path) you want to use. Then pick the driver you want, which your Java program will have to parse. Generic text could be useful in some cases, or Postscript if you need all that formatting, and can handle parsing it.
Unlike the "File:" option under existing ports, it will not ask the user for a filename. It will just automatically save to the specified file every time.
Your Java program can monitor this file for changes, and then process the data it receives.
I have a generated post script file and want to print using it. How can it be achieved in java either using javax print API or AWT. Is it possible?
Complicated. Does your printer(s) support PostScript? Is it networked? If so, most networked printers can talk LPR and you can shove the file over as-is. On Windows, you could also stream the file as-is to the lpt1: mapped port via something like NET USE LPT1: \\[Computer Name]\Printer /PERSISTENT:YES.
If you're on a server and you do lots of PostScript handling and your printer infrastructure supports it, I would very much look into the LPR protocol. I've written several LPR/LPD management functions in Java to handle printer jobs, so definetely know it can be done with some relative ease.
http://tools.ietf.org/pdf/rfc1179.pdf
I'm trying to figure out a way to programmatically determine a printers inputslot tray to number definitions for use in generating postscript.
I have gathered a collection of PPD files and collated information that way but it seems stupid to be limited to only the printers i have the PPD's for - would be better to interrogate the printers installed in windows, cant see it being a problem for unix installs. Would this be possible in Java or .NET?
edit:
I've since found out that postscript level 2 uses the actual tray names instead of the numbers. Since i know its possible to query the printers (or it could just be retrieving the information in windows) in .NET for the tray names i figure when the decision to change this in postscript 3 was made, they must of had a way to get the id's...
Anyone that can point me in the right direction? Google cant seem to help. Or at least i cant find the right search terms
Try with DeviceCapabilities and DC_BINNAMES.
Tje java print system allows interrogating the printers ón the current system and determne such functionality.