NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

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

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
becklery



Joined: 18 Apr 2009
Posts: 58

PostPosted: Mon Jul 13, 2009 1:52 pm    Post subject: Export image format PDF files with page break in Java reporting tool Reply with quote

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 parameter 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 welcomed 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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo