• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Print a document using java API

 
Latha Sree
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the Java Print Service API.
 
Latha Sree
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Latha Sree
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you have any other suggestion to print PDF file from java code other than JPS

Here you go: print a PDF using PDFRenderer
 
Latha Sree
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 0.8 version of http://incubator.apache.org/pdfbox/ is also worth a try.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic