Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Really its possible just one week before i did it. I was used java, servlet and jsp to did the same.</p> <h2>Steps :</h2> <ol> <li>Read the html file and have it in string.</li> <li>Use ITextRenderer for converting html to pdf</li> <li>set render document from string using setDocumentFromString()</li> <li>Then create pdf using createPDF() method <ul> <li>you can store pdf in specified path or output stream, i have used output stream</li> </ul></li> </ol> <h2>Sample Code :</h2> <pre><code>Visit http://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html protected void doProcess(HttpServletRequest request, HttpServletResponse response){ response.setContentType("application/pdf;"); response.setHeader("Content-Disposition", "attachment; filename=Filenametodownload.pdf"); String reportContent = "&lt;html&gt;&lt;body&gt;&lt;b&gt;This is sample HTML&lt;/b&gt;&lt;/body&gt;&lt;/html&gt;"; ServletOutputStream sos =null; try { sos = response.getOutputStream(); } catch (IOException e1) { e1.printStackTrace(); } String st = System.getProperty("user.dir"); // ITextRenderer is only works fine with compailed version of core-renderer.jar //Jar available in http://wo-repository.doit.com.br/content/repositories/thirdparty/org/xhtmlrenderer/core-renderer/R8-final/ ITextRenderer renderer = new ITextRenderer(); //System.out.println(reportContent); renderer.setDocumentFromString(reportContent); renderer.layout(); try { renderer.createPDF(sos); } catch (DocumentException e) { e.printStackTrace(); } try { sos.close(); session.removeAttribute("ReportContent"); } catch (IOException e) { e.printStackTrace(); } } </code></pre> <p>Note : include itext.jar and core-renderer.jar</p> <p>Try this way u can do... All the best...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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