Note that there are some explanatory texts on larger screens.

plurals
  1. POhaving trouble in pdf conversion using itext
    text
    copied!<p>This is my Java class for generating PDF. I am using iText for PDF generation.</p> <pre><code>public class pdfgen { public void createPdf(String inputFile, String outputFile, boolean isPictureFile) { Rectangle pageSize = new Rectangle(2780, 2525); Document pdfDoc = new Document(pageSize); String pdfFilePath = outputFile; try { FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath); PdfWriter writer = null; writer = PdfWriter.getInstance(pdfDoc, fileOutputStream); writer.open(); pdfDoc.open(); if (isPictureFile){ pdfDoc.add(com.itextpdf.text.Image.getInstance(inputFile)); } else{ URL url=new URL(inputFile); URLConnection conn = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) !=null ) { System.out.println(line); } System.out.println(inputFile); in.close(); File file = new File(inputFile); pdfDoc.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file))); } pdfDoc.close(); writer.close(); }catch(DocumentException e){ System.err.println("The error has occured in the document"); }catch(FileNotFoundException e){ System.err.println("Your file is not found."); } catch(Exception e){ System.err.println("Exception: "+e); } } } </code></pre> <p>This is my JSP file in which I am calling my the above class</p> <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;%@ page import="java.util.Vector" %&gt; &lt;%@page import="com.dalkin.pdfgen" %&gt; &lt;% Vector result=(Vector)request.getAttribute("val");%&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;Output &lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;%Vector names; %&gt; &lt;%if(arrcol.size()!=0){ %&gt; &lt;div style="width:1024px;"&gt; &lt;table cellpadding="5" cellspacing="5"&gt; &lt;tr&gt; &lt;td&gt; &lt;%for(int q=0;q&lt;result.size();q+=3){ %&gt; &lt;div style="background:url(sample.gif) no-repeat; height:320px; width:500px; float:left;"&gt; &lt;input type="text" size="50" value=&lt;%=result.get(q) %&gt;&gt; &lt;input type="text" size="50" value= &lt;%=result.get((q+1))%&gt;&gt; &lt;input type="text" size="50" value=&lt;%=result.get((q+2))%&gt;&gt; &lt;/div&gt; &lt;%}} %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;%pdfgen pf = new pdfgen(); pf.createPdf("http://localhost:8080/New/FirstServlet","D:\\first.pdf",false);%&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>When I run the program I am getting <code>FileNotFoundException "http://localhost:8080/New/FirstServlet" Your file is not found.</code> Can anyone help me where I am doing wrong? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload