Jump to content

BIRT Developer Center Download


Photo

Problem download pdf

bird generate pdf java8 OpenXava Liferay

  • Please log in to reply
No replies to this topic

#1 el_odiado76

el_odiado76

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 16 March 2017 - 06:58 AM

Hello,
I am trying to download a pdf generate with Birt.
In this moment, the archive is downloaded in my desktop, but a error ocurred and dont finish well.

Furthermore, i want that donwload through the browser and dont save in the desktop.
The PDF in the future Will be formed with parameters that the user fills in the web.

 

I use:
- Java 8
- Birt 4.6.0

- OpenXava
- LifeRay

Here my code:

package org.openxava.datos.actions;

import org.openxava.actions.TabBaseAction;

import java.io.*;
import java.net.URL;

import java.util.*;
import java.util.logging.Level;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
import org.eclipse.birt.report.engine.api.impl.*;

public class Imprimir extends TabBaseAction {

	@Override
	public void execute() throws EngineException {

			IRunAndRenderTask task=null;
			IReportEngine engine=null;
			EngineConfig config = null;

			try{
				//System.setProperty("java.io.tmpdir", "c:/temp/test/testsampledb");	
				config = new EngineConfig( );			
				config.setLogConfig("c:/dwn", Level.INFO);
				config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, this.getClass().getClassLoader());
				config.getAppContext().put(EngineConstants.WEBAPP_CLASSPATH_KEY, "C:\\Birt\\birt-runtime-4_6_0\\eventjar.jar");			
				config.setBIRTHome("C:\\Birt\\birt-runtime-4_6_0\\ReportEngine");
				//URL url = Imprimir.class.getResource("fonts/arial.ttf");
				//config.setFontConfig(url);
				//config.setLogConfig(null, Level.FINEST);
				Platform.startup( config );
				
				IReportEngineFactory factory = (IReportEngineFactory) Platform
				.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
				engine = factory.createReportEngine( config );
			

			IReportRunnable design = null;
			//Open the report design
			
			design = engine.openReportDesign("Info.rptdesign"); 
			
			task = engine.createRunAndRenderTask(design);		
			//task.setParameterValue("Top Count", (new Integer(5)));
			task.validateParameters();
			
			//HTMLRenderOption options = new HTMLRenderOption();		
			//options.setImageDirectory("./");
			//options.setOutputFileName("C:/Users/ADMIN/Desktop/topn.html");
			//options.setEmbeddable( false );
			//options.setOutputFormat("html");
			
			PDFRenderOption options = new PDFRenderOption();
			options.setOutputFileName("c:/report/topn.pdf");
			options.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF;SVG");
			options.setOutputFormat("pdf");
			
			//EXCELRenderOption options = new EXCELRenderOption();	
			//options.setOutputFormat("xls");
			//options.setOutputFileName("output/resample/customers.xls");
			//options.setWrappingText(true);
			
			task.setRenderOption(options);
			task.setLocale(new Locale("en", "US"));
			task.run();
			task.close();
			engine.destroy();
			}catch( Exception ex){
				ex.printStackTrace();
			}				
			finally
			{
				if ( !task.getErrors( ).isEmpty( ) )

				{

					for ( Object e : task.getErrors( ) )

					{

						( (Exception) e ).printStackTrace( );

					}

				}			
				Platform.shutdown( );
				System.out.println("Finished");
			}
			
		}	
}

Here error trace:

org.eclipse.birt.report.engine.api.EngineException: Error happened while running the report.
	at org.eclipse.birt.report.engine.api.impl.EngineTask.handleFatalExceptions(EngineTask.java:2375)
	at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:191)
	at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)
	at org.openxava.datos.actions.Imprimir.execute(Imprimir.java)
	at org.openxava.controller.ModuleManager.executeAction(ModuleManager.java:535)
	at org.openxava.controller.ModuleManager.executeAction(ModuleManager.java:443)
	at org.openxava.controller.ModuleManager.execute(ModuleManager.java:404)
	at org.apache.jsp.xava.execute_jsp._jspService(execute_jsp.java:256)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:720)
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:523)
	at org.openxava.web.servlets.Servlets.getURIAsStream(Servlets.java:72)
	at org.openxava.web.dwr.Module.getURIAsStream(Module.java:214)
	at org.openxava.web.dwr.Module.request(Module.java:62)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34)
	at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428)
	at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431)
	at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283)
	at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
	at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
	at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
	at org.eclipse.birt.report.engine.layout.pdf.font.FontHandler.getMappedFont(FontHandler.java:213)
	at org.eclipse.birt.report.engine.layout.pdf.font.FontHandler.selectFont(FontHandler.java:172)
	at org.eclipse.birt.report.engine.layout.pdf.font.FontSplitter.buildChunk(FontSplitter.java:98)
	at org.eclipse.birt.report.engine.layout.pdf.font.FontSplitter.getNext(FontSplitter.java:189)
	at org.eclipse.birt.report.engine.layout.pdf.text.ChunkGenerator.getNext(ChunkGenerator.java:104)
	at org.eclipse.birt.report.engine.nLayout.area.impl.TextCompositor.getNextTextArea(TextCompositor.java:189)
	at org.eclipse.birt.report.engine.nLayout.area.impl.TextCompositor.getNextArea(TextCompositor.java:127)
	at org.eclipse.birt.report.engine.nLayout.area.impl.TextAreaLayout.layoutChildren(TextAreaLayout.java:182)
	at org.eclipse.birt.report.engine.nLayout.area.impl.TextAreaLayout.layout(TextAreaLayout.java:173)
	at org.eclipse.birt.report.engine.nLayout.area.impl.InlineTextArea.layout(InlineTextArea.java:70)
	at org.eclipse.birt.report.engine.nLayout.LayoutEngine.startContent(LayoutEngine.java:562)
	at org.eclipse.birt.report.engine.emitter.ContentEmitterAdapter.startText(ContentEmitterAdapter.java:147)
	at org.eclipse.birt.report.engine.emitter.ContentEmitterAdapter.startLabel(ContentEmitterAdapter.java:153)
	at org.eclipse.birt.report.engine.emitter.ContentEmitterUtil.startContent(ContentEmitterUtil.java:65)
	at org.eclipse.birt.report.engine.nLayout.LayoutEngine.visitContent(LayoutEngine.java:713)
	at org.eclipse.birt.report.engine.nLayout.LayoutEngine.visitContent(LayoutEngine.java:721)
	at org.eclipse.birt.report.engine.nLayout.LayoutEngine.startForeign(LayoutEngine.java:764)
	at org.eclipse.birt.report.engine.emitter.ContentEmitterUtil.startContent(ContentEmitterUtil.java:77)
	at org.eclipse.birt.report.engine.nLayout.LayoutEngine.visitContent(LayoutEngine.java:713)
	at org.eclipse.birt.report.engine.nLayout.LayoutEngine.visitChildren(LayoutEngine.java:737)
	at org.eclipse.birt.report.engine.nLayout.RegionLayoutEngine.layout(RegionLayoutEngine.java:31)
	at org.eclipse.birt.report.engine.nLayout.area.impl.PageArea.layoutFooter(PageArea.java:489)
	at org.eclipse.birt.report.engine.nLayout.area.impl.PageArea.initialize(PageArea.java:249)
	at org.eclipse.birt.report.engine.nLayout.area.impl.RootArea.createNewPage(RootArea.java:147)
	at org.eclipse.birt.report.engine.nLayout.area.impl.RootArea.initialize(RootArea.java:138)
	at org.eclipse.birt.report.engine.nLayout.LayoutEngine.setContainer(LayoutEngine.java:366)
	at org.eclipse.birt.report.engine.nLayout.LayoutEngine._startContainer(LayoutEngine.java:454)

Thanks for the help.
Have a good day.

 







Also tagged with one or more of these keywords: bird, generate pdf, java8, OpenXava, Liferay