aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Print a document using java API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Print a document using java API" Watch "Print a document using java API" New topic
Author

Print a document using java API

Latha Sree
Greenhorn

Joined: Apr 07, 2009
Posts: 17
Hi Friends,

Can anyone help me in how to print document using java program.
The file path and name will be given as input.
Program should read the content and print in the specified format.
The file can be of any format.

Please suggest any solution.

Thanks
Madhavi
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have a look at the Java Print Service API.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Latha Sree
Greenhorn

Joined: Apr 07, 2009
Posts: 17
Paul Sturrock wrote:Have a look at the Java Print Service API.


Thanks a lot Paul..
Using that documentation, I am able to print text files, jpeg,gif files..But unable to print PDF..Its printing in unreadable format..
Can you please suggest how to print PDF file correctly using DocPrintJob API...
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8715
    
    6

The last time I looked at the Java Print Service, it depended on your printer being able to print a PDF directly (not using Acrobat or other software). That topic also includes several options if your printer does not support PDF>


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Latha Sree
Greenhorn

Joined: Apr 07, 2009
Posts: 17
Thanku very much for your quick response.

I have a question..like how can a printer print a PDF file without any Adobe software or anything?

If I open PDF file and print it from there,its printing correctly..
But ..when i try to print using JPS API, it is printing junk data in severeal pages.

Or you have any other suggestion to print PDF file from java code other than JPS

Please help me out in solving this..

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Or you have any other suggestion to print PDF file from java code other than JPS

Here you go: print a PDF using PDFRenderer


Ping & DNS - updated with new look and Ping home screen widget
Latha Sree
Greenhorn

Joined: Apr 07, 2009
Posts: 17
Using PDFRenderer, I am getting this exception:

com.sun.pdfview.PDFParseException: Expected 'xref' at start of table
at com.sun.pdfview.PDFFile.readTrailer(PDFFile.java:974)
at com.sun.pdfview.PDFFile.parseFile(PDFFile.java:1175)
at com.sun.pdfview.PDFFile.<init>(PDFFile.java:126)
at com.sun.pdfview.PDFFile.<init>(PDFFile.java:102)
at view.Pdf2Image.main(Pdf2Image.java:31)

When searched in Google, it says that PDFRenderer works fine Java in 1.4 but not latest versions.
I have java 1.5

Can you suggest any way(Java code) to convert PDF files to image files?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Latha Sree wrote:When searched in Google, it says that PDFRenderer works fine Java in 1.4 but not latest versions. I have java 1.5

I think you misunderstood something. PDFRenderer doesn't work with Java 1.4 at all - it requires Java 5 (at least that's what its home page says). The "1.4" refers to the version of the PDF specification it supports.

Can you post the URL to an example PDF file that exhibits the problem?
Latha Sree
Greenhorn

Joined: Apr 07, 2009
Posts: 17
Sorry..I was mistaken..
It is PDF version only..It will not work for PDF versions greater than 1.4

please check this url:
https://issues.alfresco.com/jira/browse/ETHREEOH-3066
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Then you're most likely out of luck. PDF Renderer hasn't had a new build since September, and it has other basic problems.

But the link Joe posted shows how to print PDFs using jPedal; that's worth checking out.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
The 0.8 version of http://incubator.apache.org/pdfbox/ is also worth a try.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Print a document using java API
 
Similar Threads
Print MS Office documents using unix commands
Documents
Printing HTML page using Java Print Service API by converting to Postscript
java printing - printing a pdf
java program for pdf file to excel file conversion