participate


Java Programming - Printing in Java
<<   Back to Forum  |   Give us Feedback
This topic has 13 replies on 1 page.
navi01
Posts:25
Registered: 8/24/06
Printing in Java   
Oct 22, 2009 5:56 PM

 
Hi All,

I've gone through a lot of existing Printing threads e.g.

Printing HTML with Java Printing Service(JDK1.4 beta)
javax.print and binary formats
Converting JFrame to a .pdf file
Any one uses javax.print API and works?
setting printer options like LEGAL,landscape programatically.

but I could not find a solution to my problem.

I want to print different file formats (pdf, tif, jpg, gif, doc, xls etc.) using Java Printing API. I want printer to decide the paper size that will fit content prperly. Orientation and Number of copies should be provided by the user. I used following but it does not work
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(OrientationRequested.LANDSCAPE);
pras.add(new Copies(2));
Doc doc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
DocPrintJob pj = pservices.createPrintJob();
pj.print(doc, pras);

But it does not work. Please help!!!!
 
amuamu
Posts:48
Registered: 11/26/08
Re: Printing in Java   
Oct 22, 2009 10:35 PM (reply 1 of 13)  (In reply to original post )

 
 
georgemc
Posts:16,804
Registered: 5/8/06
Re: Printing in Java   
Oct 23, 2009 1:43 AM (reply 2 of 13)  (In reply to #1 )

 
amuamu wrote:
Use PrintStream class

Nothing to do with printing in the context the OP means printing. You know, with printers and stuff
 
georgemc
Posts:16,804
Registered: 5/8/06
Re: Printing in Java   
Oct 23, 2009 1:44 AM (reply 3 of 13)  (In reply to original post )

 
navi01 wrote:
But it does not work. Please help!!!!

What does "not work" entail?
 
navi01
Posts:25
Registered: 8/24/06
Re: Printing in Java   
Oct 25, 2009 2:57 PM (reply 4 of 13)  (In reply to #3 )

 
Orientation and the Paper size. Even if I write orientation for PDF document following
pras.add(OrientationRequested.LANDSCAPE);

Printer prints it as Portrait.
Even if I write that printing job should be "DUPLEX"
pras.add(Sides.DUPLEX);

I get one sided prints.
Even if I write code to have printing on A3 size paper I get it on A4.
pras.add(MediaSizeName.ISO_A3);
 
where pras is 
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();


Thanks.
 
navi01
Posts:25
Registered: 8/24/06
Re: Printing in Java   
Oct 25, 2009 7:19 PM (reply 5 of 13)  (In reply to #4 )

 
Hi all,
I am also unable to print multiple copies. The following line of code should allow me to print two copies but printer only prints one copy.
pras.add(new Copies(2));

Can some one suggest me a solution. Am I missing something here or doing something wrong.

Thanks.
 
andrew_malcolm
Posts:2,120
Registered: 11/12/01
Re: Printing in Java   
Oct 26, 2009 1:09 AM (reply 6 of 13)  (In reply to #5 )

 
It's been while since I worked on printing, but looking at your code and comparing it with mine, the only difference I can see is where you create the print job:

This is what I do

docPrintJob.print(new SimpleDoc(printable,DocFlavor.SERVICE_FORMATTED.PRINTABLE,null),m_printRequestAttributeSet);


Hope ths helps
 
DanKiernan
Posts:1
Registered: 10/22/09
Re: Printing in Java   
Oct 26, 2009 3:52 AM (reply 7 of 13)  (In reply to #6 )

 
I think this is one of the many solutions. Thanks, it definitely helped!

plavix75mg.com
 
navi01
Posts:25
Registered: 8/24/06
Re: Printing in Java   
Oct 26, 2009 4:00 PM (reply 8 of 13)  (In reply to #6 )

 
DocFlavor.SERVICE_FORMATTED.PRINTABLE


Does not work for me as I am printing pdf, xls, doc, gif, dwg etc files.
 
navi01
Posts:25
Registered: 8/24/06
Re: Printing in Java   
Oct 27, 2009 3:41 PM (reply 9 of 13)  (In reply to #8 )

 
Hi,
Can someone help me with printing request I made before. I also need to send document to printer that has most of the pages A4 size but some pages are A3 size (diagram). Printer should automatically use most appropriate paper size to print the document. How do we code this? Any example.

Thanks.
 
navi01
Posts:25
Registered: 8/24/06
Re: Printing in Java   
Oct 28, 2009 5:53 PM (reply 10 of 13)  (In reply to #9 )

 
Hi,
I'm still waiting for a solution for this printing problem.

I need to print different file formats (e.g. pdf, xls, doc, dwg, gif, tif etc.)
Orientation support e.g. Landscape or Portrait
Page sizes (A4, A3 etc.). Also printer should detect the most appropriate paper size in case a multi page document has mix size pages e.g A4, A3 etc.
Multiple copies should also be supported.

My code (see previous posts) works fine with gif file using DocFlavor.INPUT_STREAM.GIF. But pdf printout are not in desired form. Is it because it is not supported as DocFlavor.INPUT_STREAM.PDF. I am using DocFlavor.INPUT_STREAM.AUTOSENSE for pdf.

Thanks.
 
navi01
Posts:25
Registered: 8/24/06
Re: Printing in Java   
Nov 3, 2009 6:59 PM (reply 11 of 13)  (In reply to #10 )

 
Hi all,

Still waiting for some good solution for the printing problem.

Thanks.
 
georgemc
Posts:16,804
Registered: 5/8/06
Re: Printing in Java   
Nov 4, 2009 12:58 AM (reply 12 of 13)  (In reply to #11 )

 
navi01 wrote:
Hi all,

Still waiting for some good solution for the printing problem.

Thanks for the update. Are you doing anything else to resolve the problem, or is it all down to us now?
 
deepak_c3
Posts:7
Registered: 11/2/09
Re: Printing in Java   
Nov 5, 2009 2:23 AM (reply 13 of 13)  (In reply to #12 )

 
You can use PDFRendere for printing pdf files

https://pdf-renderer.dev.java.net/examples.html
 
This topic has 13 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums