user176105 user176105 - 9 months ago 41
HTML Question

Turn CKEDITOR into a pdf

I have a ckeditor ( on my site. I would like for users to be able to push a button to generate a PDF. Currently, I have them press the print function that came with ckeditor, which brings up the print window and from most browsers they can generate a PDF. But I want to make it simplier. I know that generating PDFs from html is difficult, but are there any simple solutions to do this (generate a PDF from the html that ckeditor gives)?

I've heard of a few solutions like fpdf, dompdf and html2pdf.


You can use iText and XMLWorker to create PDF from HTML code.

public void createPDF() throws DocumentException, IOException 
    String fileName="path you want to create the document";
    Document document=new Document();
    PdfWriter pdfWriter=PdfWriter.getInstance(document, new FileOutputStream(fileName));;
    String finall="<h1>This is a Demo</h1>";
    InputStream is = new ByteArrayInputStream(finall.getBytes());
    XMLWorkerHelper.getInstance().parseXHtml(pdfWriter,document, is);


Here we are using XML worker so all your tags should be closed correctly. You need iText and XMLWorker JAR files.Hope this will help you.