-
Converting an HTML Page to PDF using iText (10 messages)
- Posted by: shweta ahuja
- Posted on: July 15 2008 02:23 EDT
Hi,I am new to using iText. We are developing a Web application using Struts. We have a requirement of converting a complete HTML page to PDF. The way we want to do it is provide a Button called "Generate PDF" and when the user clicks on this button, the whole page should be converted to a PDF. This HTML Page has images and form fields like Text boxes, radio buttons, etc. Is there a way I can read this whole page as it is and convert to PDF using iText? Please let me know how I can achieve this. Thanks and regards, ShwetaThreaded Messages (10)
- Re: Converting an HTML Page to PDF using iText by Satish Iyengar on July 15 2008 09:44 EDT
- Converting an HTML Page to PDF using iText by shweta ahuja on July 16 2008 02:00 EDT
-
Converting an HTML Page to PDF using iText by Sekhar Bhimireddy on July 17 2008 05:35 EDT
-
Converting an HTML Page to PDF using iText by shweta ahuja on July 17 2008 06:46 EDT
- suggest me which is the best technology? by Sekhar Bhimireddy on July 31 2008 02:25 EDT
-
Re: Converting an HTML Page to PDF using iText by aloy adam on February 16 2009 11:20 EST
-
HTMLWorker by Matt Pickell on March 30 2009 09:05 EDT
- Converting HTML pages to PDF by Kitty Zheng on November 13 2010 04:57 EST
-
HTMLWorker by Matt Pickell on March 30 2009 09:05 EDT
-
Converting an HTML Page to PDF using iText by shweta ahuja on July 17 2008 06:46 EDT
-
Converting an HTML Page to PDF using iText by Sekhar Bhimireddy on July 17 2008 05:35 EDT
- Converting an HTML Page to PDF using iText by shweta ahuja on July 16 2008 02:00 EDT
- Converting an HTML Page to PDF using iText by Andrei Visan on January 03 2011 09:36 EST
- Try by Vardius Pavardzius on August 20 2011 11:48 EDT
-
Re: Converting an HTML Page to PDF using iText[ Go to top ]
- Posted by: Satish Iyengar
- Posted on: July 15 2008 09:44 EDT
- in response to shweta ahuja
Try JodConverter JodConverter supports conversion from one format to another. It is opensource. It uses OpenOffice API and OpenOffice instance (service). Openoffice service need to run separately on windows or unix (including linux) environments. Visit http://artofsolving.com/opensource/jodconverter/guide/supportedformats -
Converting an HTML Page to PDF using iText[ Go to top ]
- Posted by: shweta ahuja
- Posted on: July 16 2008 02:00 EDT
- in response to Satish Iyengar
i have gone through the link given by you. But it does not support HTML to PDF converter. Moreover, i was unable to find any example(source code) for the same. Can you provide me with a simple example, so that i can test the conversion? Thanks in advance. Shweta -
Converting an HTML Page to PDF using iText[ Go to top ]
- Posted by: Sekhar Bhimireddy
- Posted on: July 17 2008 05:35 EDT
- in response to shweta ahuja
did u converted the HTML page to PDF ? if "yes" how? -
Converting an HTML Page to PDF using iText[ Go to top ]
- Posted by: shweta ahuja
- Posted on: July 17 2008 06:46 EDT
- in response to Sekhar Bhimireddy
i have converted HTML to PDF now using the following code: untitled <%try{String paramStr = "func=getReport&print=true&reportID=1&selectedIDs=315,158"; // POST requests are required to have Content-Length String lengthString = String.valueOf(paramStr.length()); /* * Establish a connection to the application. */ URL url = new URL("http://10.230.213.163:8988/crm_interaction-crmint-context-root/common/CreatedPdf.jsp"); URLConnection con = url.openConnection(); /* * configure the connection to allow for the operations necessary. * 1. Turn off all caching, so that each new request/response is * made from a fresh connection with the servlet. 2. Indicate that * this client will attempt to SEND and READ data to/from the * servlet. */ con.setUseCaches(false); con.setDefaultUseCaches(false); con.setDoInput(true); con.setDoOutput(true); // Set the content type we are POSTing and length of the data. con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); con.setRequestProperty("Content-Length", lengthString); OutputStream os = con.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(os); // send data to servlet osw.write(paramStr); osw.flush(); osw.close(); Document document = new Document(); document.setPageSize(PageSize.A4.rotate()); OutputStream out1 = response.getOutputStream(); response.addHeader("Content-Type", "application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=\"ss.pdf\""); //response.addHeader("Content-Length", "" + cachedURL.length()); try { PdfWriter.getInstance(document, out1); HtmlParser.parse(document, con.getInputStream()); } catch (Exception e) { System.out.println("error="+e); e.printStackTrace(); //log.error(e); } } catch (Throwable t) { System.out.println("error="+t); t.printStackTrace(); // log.error(t); } %> Here, CreatedPdf is the jsp file which i want to convert into PDF.. It works fine if i add simple text. But if i add table tags to it it gives followinf error: 08/07/17 15:39:28 java.lang.ClassCastException: com.lowagie.text.Table 08/07/17 15:39:28 at com.lowagie.text.xml.SAXiTextHandler.handleStartingTags(Unknown Source) 08/07/17 15:39:28 at com.lowagie.text.html.SAXmyHtmlHandler.startElement(Unknown Source) 08/07/17 15:39:28 at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1181) 08/07/17 15:39:28 at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:300) 08/07/17 15:39:28 at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:267) 08/07/17 15:39:28 at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:149) 08/07/17 15:39:28 at oracle.xml.jaxp.JXSAXParser.parse(JXSAXParser.java:286) 08/07/17 15:39:28 at com.lowagie.text.html.HtmlParser.go(Unknown Source) 08/07/17 15:39:28 at com.lowagie.text.html.HtmlParser.parse(Unknown Source) 08/07/17 15:39:28 at _common._HtmltoPdf._jspService(HtmltoPdf.jsp:64) 08/07/17 15:39:28 at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:139) 08/07/17 15:39:28 at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:349) 08/07/17 15:39:28 at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509) 08/07/17 15:39:28 at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413) 08/07/17 15:39:28 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) 08/07/17 15:39:28 at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65) 08/07/17 15:39:28 at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source) 08/07/17 15:39:28 at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:604) 08/07/17 15:39:28 at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317) 08/07/17 15:39:28 at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:220) 08/07/17 15:39:28 at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069) 08/07/17 15:39:28 at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274) 08/07/17 15:39:28 at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455) 08/07/17 15:39:28 at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:320) 08/07/17 15:39:28 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279) 08/07/17 15:39:28 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) 08/07/17 15:39:28 at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507) 08/07/17 15:39:28 at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) 08/07/17 15:39:28 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) 08/07/17 15:39:28 at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65) 08/07/17 15:39:28 at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source) 08/07/17 15:39:28 at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:604) 08/07/17 15:39:28 at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317) 08/07/17 15:39:28 at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790) 08/07/17 15:39:28 at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270) 08/07/17 15:39:28 at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112) 08/07/17 15:39:28 at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192) 08/07/17 15:39:28 at java.lang.Thread.run(Thread.java:534) -
suggest me which is the best technology?[ Go to top ]
- Posted by: Sekhar Bhimireddy
- Posted on: July 31 2008 02:25 EDT
- in response to shweta ahuja
Hi , can u plz suggest me the best technology which helps me to work even in USA? rite now m working on a tool (OpenClovis IDE) which is related to java/j2ee technologies.... Everybody(Companies) are asking me in interviews about Spring , Hibernate...JBoss...along with java/j2ee & Somebody(Friends) suggested to go/learn for WebSphere MQ..some are Dataware Housing....some are Oracle Apps....Some are .Net..... probably my trip to USA on H1B would be in Feb/March 2009. Pls Suggest me.... -
Re: Converting an HTML Page to PDF using iText[ Go to top ]
- Posted by: aloy adam
- Posted on: February 16 2009 11:20 EST
- in response to shweta ahuja
Were you able to get this working with Table tags? What do we have to do? -
HTMLWorker[ Go to top ]
- Posted by: Matt Pickell
- Posted on: March 30 2009 09:05 EDT
- in response to aloy adam
I could not tell if you have found a response to this based on this thread. I have used iText extensively and it supports printing HTML to PDF. The thing you want to use is called HTMLWorker. It is not an in-depth HTML parser, but it works for basic HTML. With iText, this is currently your best method; it is not heavily supported. Check out this link, I have posted some code that I used to do this: http://www.nabble.com/HTMLWorker-tables-and-fonts-td22232868.html#a22232868 -
Converting HTML pages to PDF[ Go to top ]
- Posted by: Kitty Zheng
- Posted on: November 13 2010 04:57 EST
- in response to Matt Pickell
"... I have used iText extensively and it supports printing HTML to PDF..."
But the support for HTML seems to be only partial. I need to convert arbitary web pages into PDF documents. Is there a way to improve the quality of conversion, or an alternative library? Please don't suggest ABCpdf - it really needs to be converted natively in Java. Any recommendations would be greatly appreciated.
-
Converting an HTML Page to PDF using iText[ Go to top ]
- Posted by: Andrei Visan
- Posted on: January 03 2011 09:36 EST
- in response to shweta ahuja
-
Try[ Go to top ]
- Posted by: Vardius Pavardzius
- Posted on: August 20 2011 11:48 EDT
- in response to shweta ahuja
If you just need a button than I recommend you to use service like http://www.web2pdfconvert.com/pdf-button#cid7 This service also has offer for developers.