You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by stephen smith <sm...@hotmail.com> on 2011/07/15 23:50:51 UTC

pdDocument.print(); prints to server not browser

Hello,
 
When we use:
pdDocument.print();
it actually opens up the print dialog box on the server, not the client.
 
Has anyone seen this before?
 
Thanks. 		 	   		  

RE: pdDocument.print(); prints to server not browser

Posted by Eric Douglas <ed...@blockhouse.com>.
If you've streamed the pdf to the client and the pdfbox print method is
generating a print dialog on the server, what you need to try is
creating a PrinterJob on the client.  print() should not be called
directly.  The print() method in the PDDocument class is called
automatically if you pass the PDDocument (Pageable) object into
PrinterJob and call it's print method.  PrinterJob can create a print
dialog, or assign the printer if you already know the name.
http://download.oracle.com/javase/6/docs/api/java/awt/print/PrinterJob.h
tml

 

-----Original Message-----
From: stephen smith [mailto:smithsf22@hotmail.com] 
Sent: Monday, July 18, 2011 12:08 PM
To: users@pdfbox.apache.org
Subject: RE: pdDocument.print(); prints to server not browser


Thanks for not giving up on me yet.
 
I can generate the pdf and render it to a browser with this code:
 
 
final ByteArrayOutputStream pdfout = PDFHelper.generatePDF(); 

final Response response = getRequestCycle().getResponse();
response.setContentType("application/pdf");
response.setContentLength(pdfout.size());
getRequestCycle().setRequestTarget(new IRequestTarget(){ 

public void detach(RequestCycle requestCycle) { } 

public void respond(RequestCycle requestCycle) { try{ OutputStream
stream = response.getOutputStream(); stream.write(pdfout.toByteArray());
stream.flush();
pdfout.close();
}catch(IOException ex){
throw new RuntimeException(ex);
}
} 

}); 
 
 
 
 
Thanks
 
 

 

> Subject: RE: pdDocument.print(); prints to server not browser
> Date: Mon, 18 Jul 2011 09:51:34 -0400
> From: edouglas@blockhouse.com
> To: users@pdfbox.apache.org
> 
> I don't know wicket but it sounds like you're missing a step.
> How does it normally communicate, like to generate a file on the 
> server and save it to the client?
> 
> 
> -----Original Message-----
> From: stephen smith [mailto:smithsf22@hotmail.com]
> Sent: Monday, July 18, 2011 9:43 AM
> To: users@pdfbox.apache.org
> Subject: RE: pdDocument.print(); prints to server not browser
> 
> 
> Hello and thanks.
> 
> I am using wicket to "serve" the pdf to the printer. My code is like
> this:
> 
> //component
> public class BPPdfGeneration extends Panel { public 
> BPPdfGeneration(String id) throws IOException, DocumentException, 
> PrinterException { super(id); PDDocument pdDocument; pdDocument = 
> PDDocument.load(PDFGen.generatePDF());
> pdDocument.print();
> 
> //I assume that the pdDocument.print(); should be added to the html 
> somehow such as:
> // add(new ?("pdf", pdDocument.print()); } }
> 
> Help would be greatly appreciated
> 
> 
> 
> > Subject: RE: pdDocument.print(); prints to server not browser
> > Date: Mon, 18 Jul 2011 09:21:20 -0400
> > From: edouglas@blockhouse.com
> > To: users@pdfbox.apache.org
> > 
> > If your document is on the server it sounds like it does what it's 
> > supposed to.
> > How is your server talking to your client?
> > Try streaming the pdf to the client first?
> > 
> > 
> > -----Original Message-----
> > From: stephen smith [mailto:smithsf22@hotmail.com]
> > Sent: Friday, July 15, 2011 5:51 PM
> > To: users@pdfbox.apache.org
> > Subject: pdDocument.print(); prints to server not browser
> > 
> > 
> > Hello,
> > 
> > When we use:
> > pdDocument.print();
> > it actually opens up the print dialog box on the server, not the
> client.
> > 
> > Has anyone seen this before?
> > 
> > Thanks. 
> 
 		 	   		  

RE: pdDocument.print(); prints to server not browser

Posted by stephen smith <sm...@hotmail.com>.
Thanks for not giving up on me yet.
 
I can generate the pdf and render it to a browser with this code:
 
 
final ByteArrayOutputStream pdfout = PDFHelper.generatePDF(); 

final Response response = getRequestCycle().getResponse(); 
response.setContentType("application/pdf"); 
response.setContentLength(pdfout.size()); 
getRequestCycle().setRequestTarget(new IRequestTarget(){ 

public void detach(RequestCycle requestCycle) { 
} 

public void respond(RequestCycle requestCycle) { 
try{ 
OutputStream stream = response.getOutputStream(); 
stream.write(pdfout.toByteArray()); 
stream.flush(); 
pdfout.close(); 
}catch(IOException ex){ 
throw new RuntimeException(ex); 
} 
} 

}); 
 
 
 
 
Thanks
 
 

 

> Subject: RE: pdDocument.print(); prints to server not browser
> Date: Mon, 18 Jul 2011 09:51:34 -0400
> From: edouglas@blockhouse.com
> To: users@pdfbox.apache.org
> 
> I don't know wicket but it sounds like you're missing a step.
> How does it normally communicate, like to generate a file on the server
> and save it to the client?
> 
> 
> -----Original Message-----
> From: stephen smith [mailto:smithsf22@hotmail.com] 
> Sent: Monday, July 18, 2011 9:43 AM
> To: users@pdfbox.apache.org
> Subject: RE: pdDocument.print(); prints to server not browser
> 
> 
> Hello and thanks.
> 
> I am using wicket to "serve" the pdf to the printer. My code is like
> this:
> 
> //component
> public class BPPdfGeneration extends Panel { 
> public BPPdfGeneration(String id) throws IOException,
> DocumentException, PrinterException 
> { 
> super(id); 
> PDDocument pdDocument; 
> pdDocument = PDDocument.load(PDFGen.generatePDF()); 
> pdDocument.print(); 
> 
> //I assume that the pdDocument.print(); should be added to the html
> somehow such as: 
> // add(new ?("pdf", pdDocument.print()); 
> }
> } 
> 
> Help would be greatly appreciated 
> 
> 
> 
> > Subject: RE: pdDocument.print(); prints to server not browser
> > Date: Mon, 18 Jul 2011 09:21:20 -0400
> > From: edouglas@blockhouse.com
> > To: users@pdfbox.apache.org
> > 
> > If your document is on the server it sounds like it does what it's 
> > supposed to.
> > How is your server talking to your client?
> > Try streaming the pdf to the client first?
> > 
> > 
> > -----Original Message-----
> > From: stephen smith [mailto:smithsf22@hotmail.com]
> > Sent: Friday, July 15, 2011 5:51 PM
> > To: users@pdfbox.apache.org
> > Subject: pdDocument.print(); prints to server not browser
> > 
> > 
> > Hello,
> > 
> > When we use:
> > pdDocument.print();
> > it actually opens up the print dialog box on the server, not the
> client.
> > 
> > Has anyone seen this before?
> > 
> > Thanks. 
> 
 		 	   		  

RE: pdDocument.print(); prints to server not browser

Posted by Eric Douglas <ed...@blockhouse.com>.
I don't know wicket but it sounds like you're missing a step.
How does it normally communicate, like to generate a file on the server
and save it to the client?
 

-----Original Message-----
From: stephen smith [mailto:smithsf22@hotmail.com] 
Sent: Monday, July 18, 2011 9:43 AM
To: users@pdfbox.apache.org
Subject: RE: pdDocument.print(); prints to server not browser


Hello and thanks.
 
I am using wicket to "serve" the pdf to the printer. My code is like
this:
 
//component
public class BPPdfGeneration extends Panel { 
    public BPPdfGeneration(String id) throws IOException,
DocumentException, PrinterException 
    { 
        super(id); 
        PDDocument pdDocument; 
        pdDocument = PDDocument.load(PDFGen.generatePDF()); 
        pdDocument.print(); 

//I assume that the pdDocument.print(); should be added to the html
somehow such as: 
//     add(new ?("pdf", pdDocument.print()); 
   }
} 

Help would be greatly appreciated 

 

> Subject: RE: pdDocument.print(); prints to server not browser
> Date: Mon, 18 Jul 2011 09:21:20 -0400
> From: edouglas@blockhouse.com
> To: users@pdfbox.apache.org
> 
> If your document is on the server it sounds like it does what it's 
> supposed to.
> How is your server talking to your client?
> Try streaming the pdf to the client first?
> 
> 
> -----Original Message-----
> From: stephen smith [mailto:smithsf22@hotmail.com]
> Sent: Friday, July 15, 2011 5:51 PM
> To: users@pdfbox.apache.org
> Subject: pdDocument.print(); prints to server not browser
> 
> 
> Hello,
> 
> When we use:
> pdDocument.print();
> it actually opens up the print dialog box on the server, not the
client.
> 
> Has anyone seen this before?
> 
> Thanks. 
 		 	   		  

RE: pdDocument.print(); prints to server not browser

Posted by stephen smith <sm...@hotmail.com>.
Hello and thanks.
 
I am using wicket to "serve" the pdf to the printer. My code is like this:
 
//component 
public class BPPdfGeneration extends Panel 
{ 
    public BPPdfGeneration(String id) throws IOException, DocumentException, PrinterException 
    { 
        super(id); 
        PDDocument pdDocument; 
        pdDocument = PDDocument.load(PDFGen.generatePDF()); 
        pdDocument.print(); 

//I assume that the pdDocument.print(); should be added to the html somehow such as: 
//     add(new ?("pdf", pdDocument.print()); 
   } 
} 

Help would be greatly appreciated 

 

> Subject: RE: pdDocument.print(); prints to server not browser
> Date: Mon, 18 Jul 2011 09:21:20 -0400
> From: edouglas@blockhouse.com
> To: users@pdfbox.apache.org
> 
> If your document is on the server it sounds like it does what it's
> supposed to.
> How is your server talking to your client?
> Try streaming the pdf to the client first?
> 
> 
> -----Original Message-----
> From: stephen smith [mailto:smithsf22@hotmail.com] 
> Sent: Friday, July 15, 2011 5:51 PM
> To: users@pdfbox.apache.org
> Subject: pdDocument.print(); prints to server not browser
> 
> 
> Hello,
> 
> When we use:
> pdDocument.print();
> it actually opens up the print dialog box on the server, not the client.
> 
> Has anyone seen this before?
> 
> Thanks. 
 		 	   		  

RE: pdDocument.print(); prints to server not browser

Posted by Eric Douglas <ed...@blockhouse.com>.
If your document is on the server it sounds like it does what it's
supposed to.
How is your server talking to your client?
Try streaming the pdf to the client first?
 

-----Original Message-----
From: stephen smith [mailto:smithsf22@hotmail.com] 
Sent: Friday, July 15, 2011 5:51 PM
To: users@pdfbox.apache.org
Subject: pdDocument.print(); prints to server not browser


Hello,
 
When we use:
pdDocument.print();
it actually opens up the print dialog box on the server, not the client.
 
Has anyone seen this before?
 
Thanks.