PD4ML v4 Forums PD4ML v3 Archived Forums (Read Only) General questions / FAQ need servlet code for converting html string to pdf Re: Re: need servlet code for converting html string to pdf

#29033

Hello,
I tried to run above code in my applicayion which is a JSF enabled application.while trying to convert given URL i get the following exception.

java.lang.NullPointerException
org.zefer.pd4ml.PD4ML.o00000(Unknown Source)
org.zefer.pd4ml.PD4ML.render(Unknown Source)
com.xyz.report.jsf.HtmlToPDF.doGet(HtmlToPDF.java:38)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
com.xyz.servlet.BaseEntityFilter.doFilter(BaseEntityFilter.java:44)

my code is

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

URL url = new URL(“http://localhost:8080/xyzweb/faces/templates/includes/report/A104_fv_1.xhtml”);

PD4ML pd4ml = new PD4ML();

pd4ml.setPageSize( PD4Constants.A4 );
pd4ml.setPageInsets( new java.awt.Insets(20, 50, 10, 10) );
pd4ml.setHtmlWidth(1000);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pd4ml.render(url, baos);
//pd4ml.render(arg0, arg1)
byte[] result = baos.toByteArray();

response.setContentType(“application/pdf”);
response.setHeader(“Content-disposition”,”inline; filename=test.pdf”);
response.setHeader(“Pragma”, “cache”);
response.setHeader(“Expires”, “0”);
response.setHeader(“Cache-control”, “private”);

response.setContentLength(result.length);
ServletOutputStream sos = response.getOutputStream();
sos.write( result );
}