How to export screen content to a PDF?

UI Components for JSF
Post Reply
rboreddy
Posts: 5
Joined: 14 Aug 2011, 12:09

16 Sep 2011, 10:52

Hi All,

I have set panels as below

First Panel-Personal Details
Second Panel-Educational Details
Third Panel-Family Details
Fourth Panel-Address Details.

My requirement is I have a PDF button on the UI, when I click on it, it should export all the panels data to a PDF file.

Note: I had look at <p:dataTable>to export the data to a PDF. But my UI doesn't have any <p:dataTable> components.My UI has only Panels.

Can you please help us in exporting these panels data to PDF?

Thanks & Regards,
Ravi Boreddy

miha
Posts: 8
Joined: 23 Aug 2011, 14:11

06 Oct 2011, 07:41

I am searching for the same solution! Anybody has any idea?
PrimeFaces 3.0.M3, Mojarra JSF 2.1, JSTL 1.1, GlassFish Server 3.1, Java EE 6

User avatar
leventgny
Posts: 238
Joined: 24 May 2011, 16:49
Contact:

07 Oct 2011, 21:33

Try to handle your own stream with p:fileDownload, placed in our showcase;
http://www.primefaces.org/showcase-labs ... wnload.jsf
PrimeFaces Team Member

pfrocks
Posts: 2
Joined: 14 Dec 2011, 00:56

14 Dec 2011, 01:01

Hi, Any simple example on how to convert the panel content to InputStream?

I did the following:

In the view:

Code: Select all

		
<p:panel id="ptpListPanel" style="width: 98%" binding="#{homeBean.ptpListPanel}"> 	
//Components etc.
</p:panel>

<p:commandButton value="PDF Export" ajax="false">
			 <p:fileDownload value="#{homeBean.file}" />  
		</p:commandButton> 
In the Bean HomeBean.java:

Code: Select all

	private UIPanel ptpListPanel;
	 public void setPtpListPanel(UIPanel ptpListPanel) {
		this.ptpListPanel = ptpListPanel;
	}
	public UIPanel getPtpListPanel() {
		return ptpListPanel;
	}

	private StreamedContent file;  
	    public StreamedContent getFile() {  
	    	file = new DefaultStreamedContent(new ByteArrayInputStream(ptpListPanel.toString().getBytes()), "pdf", "test.pdf");  
	        return file;  
	    }  
Obviously, I am missing something simple here. How to create the stream from the panel component? The panel component on the view is bound to the Bean and I have the ptpListPanel in the getFile() method. How to convert it to pdf? Any pointers are highly appreciated.

Do I need to have the iText jar in my classpath?

Thanks!

rkrenn
Posts: 33
Joined: 26 Jul 2011, 03:55
Location: Austria

14 Dec 2011, 16:52

you probably cannot convert pf components other than datatable to a pdf using the dataexporter kit.

as we all others have to do, i would suggest to:

-render (draw) your pdf with a java pdfapi like e.g. pdfbox or iText - it will allow you to plot your custom information (ie. fields of your backing beans) in a desired layout and format
-finally, like ironhide said, use p;filedownload to deliver the pdf binary content to the client browser
Mojarra 2.1.28, PrimeFaces 3.3.1, Primefaces Extensions 0.7.0, libservlet3.1-java tomcat8, openjdk-8-jdk

pfrocks
Posts: 2
Joined: 14 Dec 2011, 00:56

14 Dec 2011, 20:37

But according to ironHide, the fileDownload option can be used?

Solyrithm
Posts: 1
Joined: 10 Jul 2015, 21:17

18 Aug 2015, 13:53

does anyone have an idea how could get byte stream from P:panel ?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 70 guests