• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Print a document using java API

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The 0.8 version of http://incubator.apache.org/pdfbox/ is also worth a try.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic