I think, the question is "How do I *print* PDF files using Java (e.g. java.print)" - not "How do I *create* PDF files" or "How do I print *to a PDF* file",
So - what's the answer ? I have the same problem - can create PDF files with Java, but just can print graphic or text files .... please help!
Thanx!
Just quote the above answer:
prepare your document to print in Java and then simply print to this printer.
I think what that means is that you print the thing to the printer, and the output would be paper. The assumption is that the printer will take whatever pdf stream, understand them and just print them.
Hello,
Take a look at http://www.cs.wisc.edu/~ghost/gsview.
The GSview can view/print PostScript and PDF file to your windows printer. For non-Windows environment, like Linux, HP-UX, Solaris, pre-compiled binaries is available too.
Note: The GhostScript is pre-requisite to GSView.
I hope this can help you.
I tried the AUTOSENSE DovFlavor and it seems to work. But, the fonts in my doc doesn't match. I guess the printer tries to match the fonts in the document to what fonts it has installed.
PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob printerJob = defaultPrintService.createPrintJob();
File pdfFile = new File("myPdfFile.pdf");
SimpleDoc simpleDoc = new SimpleDoc(pdfFile.toURL(), DocFlavor.URL.AUTOSENSE, null);
printerJob.print(simpleDoc, null);
/ Jrgen
I use the code posted for this topic to print pdf:
PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob printerJob = defaultPrintService.createPrintJob();
File pdfFile = new File("myPdfFile.pdf");
SimpleDoc simpleDoc = new SimpleDoc(pdfFile.toURL(), DocFlavor.URL.AUTOSENSE, null);
printerJob.print(simpleDoc, null);
Pdf is not printed, the following sentence is printed on the paper:
Pdf Print failed, in order to enable the print job, 128 M memory is needed.
Actually, my computer memory is very big. Any idea?
> Pdf is not printed, the following sentence is printed
> on the paper:
> Pdf Print failed, in order to enable the print job,
> 128 M memory is needed.
>
> Actually, my computer memory is very big. Any idea?
It's probably the printer that needs 128M.
/ Jrgen
If printer need 128M memory, this means I need to find specific printer to do the test. I want to know whether you really use java print api to print pdf successfully. If yes, what kind of printer did you use? The thing is that I research a lot related to this topic, lots of people mentioned java print api still not support pdf printing. So I'm surprised that you can print pdf successfully.
hi when i am trying to use DocFlavor.BYTE_ARRAY.AUTOSENSE;
i am getting following exception
java.lang.IllegalArgumentException: data is not of declared type
at javax.print.SimpleDoc.<init>(SimpleDoc.java:82)
at com.print.PrintDocument.main(PrintDocument.java:41)
can you please help me out
Thanks in advance
Regards
Ramu
Hello
i try the same code that u got by someone for printing
code is
PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob printerJob = defaultPrintService.createPrintJob();
File pdfFile = new File("c:\\temp1.pdf");
SimpleDoc simpleDoc = new SimpleDoc(pdfFile.toURL(), DocFlavor.URL.AUTOSENSE, null);
printerJob.print(simpleDoc, null);
code will print notprintable character
that means pdf printting is not supported by this code
so did u get any other solution reply me soon
The DocFlavor is just for detecting if a printer supports a flavor. So if you have a printer that can directly print PDF code (that I not know of), you could directly print PDF files with the Java print API. But most printers just understand their own code, PCL, many also PostScript and perhaps some other bitmap protocol.
We use GhostScript to print our PDF files through Java (not GSView, but directly GhostScript). GhostScript transforms the PDF to PostScript as PDF is very similar to PostScript (but not the same).
Hi there
We develop a (commercial) PDF library which enables printing PDFs from Java (amongst other things). You can get more information and a free trial at http://big.faceless.org/products/pdf - there's an example included called "PrintPDF.java" which should get you started.
Cheers... Mike
Mike,
Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
boolean showPrintDialog=true;
PrinterJob printJob = PrinterJob.getPrinterJob ();
printJob.setJobName ("Contract.pdf");
try {
if (showPrintDialog) {
if (printJob.printDialog()) {
printJob.print();
}
}
else
printJob.print ();
} catch (Exception PrintException) {
PrintException.printStackTrace();
}
Thank you and a happy new year.
Cheers,
Chris