Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » probleam to generate PDF/HTML
probleam to generate PDF/HTML [message #139606] Mon, 06 March 2006 14:19
Jayanta is currently offline JayantaFriend
Messages: 22
Registered: July 2009
Junior Member
HI
I am a new comers &

I create this servlet to generate PDF & HTML of a .rptdesing file
named
user_reg_report.rptdesign.Now my probleam is -when i save this rptdesign
as .PDF & put in
" C://jakarta-tomcat-5.0.27/webapps/learnity/report/test11.rpt design" then
it is ok. But when i create only rptdesign not .PDF then my servlet
doesnot generate PDF/HTML.

This is my source code. Please reply me.










package report;
import java.util.HashMap;
import org.eclipse.birt.report.engine.api.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.ecs.*;
import org.apache.ecs.html.*;
import org.apache.ecs.xhtml.*;


public class user_reg_report extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public static void run( String name, HashMap params,String format,
boolean showInfo )
{
EngineConfig config = new EngineConfig( );
config.setEngineHome( "..\\webapps\\learnity" );
HTMLEmitterConfig hc = new HTMLEmitterConfig( );
HTMLServerImageHandler imageHandler = new HTMLServerImageHandler( );
hc.setImageHandler( imageHandler );
config.setEmitterConfiguration( HTMLRenderOption.OUTPUT_FORMAT_HTML, hc
);
ReportEngine engine = new ReportEngine( config );
IReportRunnable report = null;
try
{
report = engine.openReportDesign( name );
}
catch ( EngineException e )
{
System.err.println( "Report " + name + " not found!\n" );
engine.destroy( );
return;
}
if ( format != null )
{
IRunAndRenderTask task = engine.createRunAndRenderTask( report );
HTMLRenderOption options = new HTMLRenderOption( );
options.setOutputFormat( format );
String output = name.replaceFirst( ".rptdesign", "." + format );
options.setOutputFileName( output );
task.setRenderOption( options );
task.setParameterValues( params );
try
{
task.run( );
task = null;
}
catch ( EngineException e1 )
{
System.err.println( "Report " + name + " run failed.\n" );
System.err.println( e1.toString( ) );
}
}
engine.destroy( );
}
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws IOException, ServletException
{
response.setContentType("text/html");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
HttpSession mysession=request.getSession(true);
OutputStream out_frame = response.getOutputStream( );
String report_file1 =
" C://jakarta-tomcat-5.0.27/webapps/learnity/report/test11.rpt design";
boolean showInfo = false;
HashMap params = new HashMap();
String tfor = new String();
String format = HTMLRenderOption.OUTPUT_FORMAT_PDF;
if(format.equals(HTMLRenderOption.OUTPUT_FORMAT_HTML))
{
tfor="h";
}
else
{
tfor="p";
}
run( report_file1, params, format, showInfo);
if(tfor.equals("p"))
{
response.setContentType("application/pdf");
}
returnFile(out_file(report_file1,tfor),out_frame);
}
public String out_file(String filename,String fmat)
throws FileNotFoundException, IOException
{
String in = new String();
String out = new String();
int sl = 0;
int l = 0;
in = filename;
l = in.length();
sl = l-9;
out = in.substring(0,sl);
if(fmat.equals("h"))
out=out+"html";
else
out=out+"pdf";
System.out.println("OUT = "+out);

return out;
}

public static void returnFile(String filename, OutputStream fout)
throws FileNotFoundException, IOException
{
InputStream in = null;
try
{
in = new BufferedInputStream(new FileInputStream(filename));
byte[ ] buf = new byte[4 * 1024];
int bytesRead;
while ((bytesRead = in.read(buf)) != -1)
{
fout.write(buf, 0, bytesRead);
}
}
finally
{
if (in != null) in.close( );
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
doPost(request,response);
}
}
Previous Topic:Birt charts flicker on resize
Next Topic:ODA for EJBQL available?
Goto Forum:
  


Current Time: Sat Jul 27 12:24:22 GMT 2024

Powered by FUDForum. Page generated in 0.02981 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top