Export image format PDF files with page break in Web reporting tool

Last Post 04 Oct 2009 06:18 AM by freezea. 0 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
freezea
New Member
New Member

--
04 Oct 2009 06:18 AM
Background
In real application of web report, users often want to export report to PDF files. However, when users export web report to PDF file with API, there is usually no page break As a result, the exported PDF file may be very large, and the PDF file is of text mode.

Solution
RAQ Report is a Excel-like web-based Java reporting tool, and it provides a perfect solution to solve this problem.
With the API of RAQ Report, users can export web report as PDF file easily. Moreover, RAQ Report can export PDF files as image format with page break. As a result, the PDF file won't be very large.
The only thing users need to do is setting the page break mode and image format for exporting web report to PDF file. The codes are as follows:
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.runqian.report4.model.ReportDefine;
import com.runqian.report4.model.engine.ExtCellSet;
import com.runqian.report4.usermodel.Context;
import com.runqian.report4.usermodel.Engine;
import com.runqian.report4.usermodel.IReport;
import com.runqian.report4.util.ReportUtils;
public class ExportToPdf {
public static void main(String[] args) {
try{
String report = "D:/toExcel.raq"; //The location of report template
String pdfPath= "D:/test.pdf";
String licenceFile = "D:/2009-12-31V4.0Windows.lic"; //The location of authorization file
//Read report template
ReportDefine rd = (ReportDefine) ReportUtils.read( report );
//Second step: set report authorization file,and compute report.
ExtCellSet.setLicenseFileName( licenceFile );
Context context = new Context();
Engine enging = new Engine( rd, context);
IReport iReport = enging.calc();
ReportUtils.exportToPDF(pdfPath,iReport,true,true);
}catch(Exception e){
e.printStackTrace();
}catch(Throwable t){
t.printStackTrace(); } }}
The parameters of function exportToPDF(pdfPath,iReport,true,true):
The first parameter pdfPath is the path of the PDF file.
The second parameter iReport is the object of the report.
The third parameter is the page break mode of the PDF file. True means page break, while false means no page break.
The fourth is the format of the PDF file. True means image, while false means text.
With this wonderful function, users can export perfect PDF file easily.

This post is from freezea's blog. You are welcome to cc it anywhere, and please indicate the source.

If you would like to read more articles about reporting tool, you are also welcome to refer to my blog.


Acceptable Use Policy
---