Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #26536

    getiing the following exception

    PWC1406: Servlet.service() for servlet PdfCreater threw exception java.lang.NumberFormatException: For input string: “/F” at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:449) at org.zefer.pd4ml.pdf.h$_b.o00000(Unknown Source) at org.zefer.pd4ml.pdf.c.O?0000(Unknown Source) at org.zefer.pd4ml.pdf.c.?00000(Unknown Source) at org.zefer.pd4ml.pdf.c.close(Unknown Source) at org.zefer.pd4ml.pdf.PD4Device.dispose(Unknown Source) at org.zefer.pd4ml.PD4ML.o00000(Unknown Source) at org.zefer.pd4ml.PD4ML.render(Unknown Source) at ae.rwd.model.Pdf.convertHtmlToPdf(Pdf.java:79) at ae.rwd.servlet.PdfCreater.processRequest(PdfCreater.java:45) at ae.rwd.servlet.PdfCreater.doPost(PdfCreater.java:65) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:662)

    it says that i have an invalid input string that should be number but i dont have and here is my code . please if any body faced this issue before help

    and here is my code

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package ae.rwd.model;

    import java.awt.Dimension;
    import java.awt.Insets;
    import java.io.BufferedReader;
    import java.io.ByteArrayOutputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import java.io.StringWriter;
    import java.io.UnsupportedEncodingException;
    import java.io.Writer;
    import java.net.MalformedURLException;
    import java.net.URL;
    import org.zefer.pd4ml.PD4Constants;
    import org.zefer.pd4ml.PD4ML;
    import org.zefer.pd4ml.PD4PageMark;

    /**
    *
    * @author Anas
    */
    public class Pdf {

    protected static int userSpaceWidth = 638;
    protected static Dimension format = PD4Constants.A4;
    protected static boolean landscapeValue = false;
    protected static int topValue = 10;
    protected static int leftValue = 50;
    protected static int rightValue = 50;
    protected static int bottomValue = 10;

    public static ByteArrayOutputStream convertHtmlToPdf(String bodyUrl, String headerUrl, String footerUrl, String charsetParam) throws MalformedURLException, FileNotFoundException, IOException {

    java.io.ByteArrayOutputStream fos = null;
    PD4ML pd4ml = null;
    PD4PageMark header = null;
    PD4PageMark footer = null;
    String charset = “windows-1256”;
    URL url = new URL(bodyUrl);
    fos = new java.io.ByteArrayOutputStream();
    pd4ml = new PD4ML();

    if (charsetParam != null && charsetParam.trim().length() > 0 && charsetParam.equalsIgnoreCase(“UTF-8”)) {
    charset = “UTF-8”;
    }

    if (headerUrl != null) {
    header = new PD4PageMark();
    header.setHtmlTemplate(getUrlAsStream(headerUrl, charset));
    header.setAreaHeight(-1);
    pd4ml.setPageHeader(header);
    }

    if (footerUrl != null) {
    footer = new PD4PageMark();
    footer.setHtmlTemplate(getUrlAsStream(footerUrl, charset));
    footer.setAreaHeight(-1);
    pd4ml.setPageFooter(footer);
    }

    pd4ml.useTTF(“/WINDOWS/Fonts/”, true);
    //pd4ml.useTTF(“/windows/fonts”, true);
    pd4ml.setDefaultTTFs(“Times New Roman”, “Arial”, “Courier New”);
    //pd4ml.setDefaultTTFs(“Simplified Arabic”, “ae_Arab”, “ae_Nice”);
    pd4ml.setPermissions(“empty”, PD4ML.AllowCopy, false);
    pd4ml.setPermissions(“empty”, PD4ML.AllowModify, false);
    // pd4ml.setPageInsets(new Insets(topValue, leftValue, bottomValue, rightValue));
    pd4ml.setHtmlWidth(userSpaceWidth);
    pd4ml.setPageSize(format);
    pd4ml.adjustHtmlWidth();

    pd4ml.render(url, fos);

    return fos;
    }

    private static String getUrlAsStream(String Url, String charset) throws MalformedURLException, IOException {
    URL url = new URL(Url);
    return convertInputStreamToString(url.openConnection().getInputStream(), charset);
    }

    private static String convertInputStreamToString(InputStream is, String charset) throws IOException, UnsupportedEncodingException {
    /*Anas Ibraheem Alsarairah
    * To convert the InputStream to String we use the
    * Reader.read(char[] buffer) method. We iterate until the
    * Reader return -1 which means there’s no more data to
    * read. We use the StringWriter class to produce the string.
    */
    if (is != null) {
    Writer writer = new StringWriter();
    char[] buffer = new char[1024];
    try {
    Reader reader = new BufferedReader(new InputStreamReader(is, charset));
    int n;
    while ((n = reader.read(buffer)) != -1) {
    writer.write(buffer, 0, n);
    }
    } finally {
    is.close();
    }
    return writer.toString();
    } else {
    return “”;
    }
    }
    }
    any help

    #28482

    It seems the exception is thrown by an image colorspace processing. Can you please temporarily comment images out from the document? Does it help?

    If yes, it would be nice if you send us the images that cause the problem.

    #28483

    hello

    yes the cause is an image with extention PNG .. but why its not accepting PNG images

    thanks

    #28484

    I did not wrote it accepts no PNG. Normally it has no problems with PNGs. But it could be that:
    1. your particular image has corrupted colorspace information
    2. there are bugs in the recent application update (the development build you evaluate did not pass QA yet).

    #28485

    Hi anas_srairah,
    can you give me an example of how I would use use PDF class in a servlet?

    #28486

    hello

    here is an example servlet that uses the class directly beneath it to do the conversion job

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package ae.rwd.servlet;

    import ae.rwd.model.Pdf;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    /**
    *
    * @author Anas
    */
    public class PdfCreater extends HttpServlet {

    private static final String bodyUrlParamater = “bodyUrl”;
    private static final String headerUrlParamater = “headerUrl”;
    private static final String footerUrlParamater = “footerUrl”;
    private static final String charsetParamater = “charset”;
    private static final String contentType = “application/pdf”;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    ServletOutputStream out = response.getOutputStream();
    String bodyUrl = null;
    String headerUrl = null;
    String footerUrl = null;
    String charset = null;
    bodyUrl = request.getParameter(PdfCreater.bodyUrlParamater);
    if (bodyUrl == null || bodyUrl.length() == 0) {
    throw new ServletException();
    }

    headerUrl = request.getParameter(PdfCreater.headerUrlParamater);
    footerUrl = request.getParameter(PdfCreater.footerUrlParamater);
    charset = request.getParameter(PdfCreater.charsetParamater);

    ByteArrayOutputStream baos = Pdf.convertHtmlToPdf(bodyUrl, headerUrl, footerUrl, charset);

    response.setContentType(PdfCreater.contentType);
    response.setContentLength(baos.size());
    out = response.getOutputStream();
    baos.writeTo(out);
    out.flush();

    out.close();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
    return “Short description”;
    }
    }

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package ae.rwd.model;

    import java.awt.Dimension;
    import java.io.BufferedReader;
    import java.io.ByteArrayOutputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import java.io.StringWriter;
    import java.io.UnsupportedEncodingException;
    import java.io.Writer;
    import java.net.MalformedURLException;
    import java.net.URL;
    import org.zefer.pd4ml.PD4Constants;
    import org.zefer.pd4ml.PD4ML;
    import org.zefer.pd4ml.PD4PageMark;

    /**
    *
    * @author Anas
    */
    public class Pdf {

    protected static int userSpaceWidth = 638;
    protected static Dimension format = PD4Constants.A4;
    protected static boolean landscapeValue = false;
    protected static int topValue = 10;
    protected static int leftValue = 50;
    protected static int rightValue = 50;
    protected static int bottomValue = 10;

    public static ByteArrayOutputStream convertHtmlToPdf(String bodyUrl, String headerUrl, String footerUrl, String charsetParam) throws MalformedURLException, FileNotFoundException, IOException {

    java.io.ByteArrayOutputStream fos = null;
    PD4ML pd4ml = null;
    PD4PageMark header = null;
    PD4PageMark footer = null;
    String charset = “windows-1256”;
    URL url = new URL(bodyUrl);
    fos = new java.io.ByteArrayOutputStream();
    pd4ml = new PD4ML();

    if (charsetParam != null && charsetParam.trim().length() > 0 && charsetParam.equalsIgnoreCase(“UTF-8”)) {
    charset = “UTF-8”;
    }

    if (headerUrl != null) {
    header = new PD4PageMark();
    header.setHtmlTemplate(getUrlAsStream(headerUrl, charset));
    header.setAreaHeight(-1);
    pd4ml.setPageHeader(header);
    }

    if (footerUrl != null) {
    footer = new PD4PageMark();
    footer.setHtmlTemplate(getUrlAsStream(footerUrl, charset));
    footer.setAreaHeight(-1);
    pd4ml.setPageFooter(footer);
    }

    pd4ml.useTTF(“java:fonts”, true);
    //pd4ml.useTTF(“/windows/fonts”, true);
    //pd4ml.setDefaultTTFs(“Times New Roman”, “Arial”, “Courier New”);
    //pd4ml.setDefaultTTFs(“Simplified Arabic”, “ae_Arab”, “ae_Nice”);
    pd4ml.setPermissions(“empty”, PD4ML.AllowCopy, false);
    pd4ml.setPermissions(“empty”, PD4ML.AllowModify, false);
    pd4ml.setPermissions(“empty”, PD4ML.AllowPrint, true);
    // pd4ml.setPageInsets(new Insets(topValue, leftValue, bottomValue, rightValue));
    pd4ml.setHtmlWidth(userSpaceWidth);
    pd4ml.setPageSize(format);
    pd4ml.enableDebugInfo();
    pd4ml.adjustHtmlWidth();

    pd4ml.render(url, fos);

    return fos;
    }

    private static String getUrlAsStream(String Url, String charset) throws MalformedURLException, IOException {
    URL url = new URL(Url);
    return convertInputStreamToString(url.openConnection().getInputStream(), charset);
    }

    private static String convertInputStreamToString(InputStream is, String charset) throws IOException, UnsupportedEncodingException {
    if (is != null) {
    Writer writer = new StringWriter();
    char[] buffer = new char[1024];
    try {
    Reader reader = new BufferedReader(new InputStreamReader(is, charset));
    int n;
    while ((n = reader.read(buffer)) != -1) {
    writer.write(buffer, 0, n);
    }
    } finally {
    is.close();
    }
    return writer.toString();
    } else {
    return “”;
    }
    }
    }

    i hope this good for you

    thanks

Viewing 6 posts - 1 through 6 (of 6 total)

The forum ‘HTML/CSS rendering issues’ is closed to new topics and replies.