Export Chart to PDF

UI Components for JSF
Post Reply
mnico73
Posts: 1
Joined: 07 Aug 2013, 18:01

08 Aug 2013, 13:08

Hello,

First of all i had to tell you that I am not an English native speaker so I hope i will explain you correctly my issue.

I have some problems with exporting my bar chart in PDF. I am working with primefaces 3.5 and tomcat v7.

After some resarch, I learned that is not possible to export directly a chart in PDF. But it seem to be some way to save the chart in an image like png or jpeg.

I find this : http://www.primefaces.org/showcase-labs ... Export.jsf but it's only a print screen way and i want to save it for use it in my pdf report .

I also see the JFreeChart solution but i really want to keep the some chart in my html page and in my pdf report.

Here is my code :

Code: Select all


<h:form id="finalreport">
			<c:if test="#{treeBean.finalPrintReport.create == 1}">
				<h1>
					<h:outputText value="#{treeBean.finalPrintReport.namefinalreport}"
						escape="false" />
				</h1>
				<p:dataTable id="dataTableReport" var="row"
					value="#{treeBean.finalPrintReport.allData}" paginator="true"
					rows="10">
					<p:columns value="#{treeBean.finalPrintReport.column}" var="column"
						columnIndexVar="colIndex">
						<f:facet name="header">
							<h:outputText value="#{column}" />
						</f:facet>
						<h:outputText value="#{row[colIndex]}" />
					</p:columns>
				</p:dataTable>
				<br />

				<h:commandLink>
					<p:graphicImage value="/images/pdf.png" />
					<p:dataExporter type="pdf" target="dataTableReport"
						fileName="Report" preProcessor="#{treeBean.createPDF}" />
				</h:commandLink>
			</c:if>
		</h:form>
		<!-- Graph -->
		<h:form id="graph">
			<c:if test="#{treeBean.finalPrintReport.create == 1}">
				<c:if test="#{treeBean.finalPrintReport.propertyOfFinalReport.graph == true}">
					<p:barChart id="basic" value="#{treeBean.chartbar2d}"
						legendPosition="ne" title="Basic Bar Chart" 
						style="height:300px" />
				</c:if> 
			</c:if>
		</h:form>

I hope you will help me to find a good solution

Thanks

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

08 Aug 2013, 15:07

You will get the CanvasURL in the view and create the image using Base64 code on the server side.Later you can export that image to PDF using Itext lib.You can customize the export PDF chart as your requirement.You can get more details in the forum search(you can find my comments as well).I tried to make a component with this approach but it won't be supported in IE8 just like Primefaces export chart feature.So I reverted that new component.But Oleg introduced new charts and export chart feature as new component.https://github.com/primefaces-extension ... issues/134
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 64 guests