mozbi / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

while Converting html to pdf it is showing error as com.lowagie.text.html.simpleparser.IncCell cannot be cast to com.lowagie.text.Paragraph #52

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Java file created is 

package com.pdf;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.html.simpleparser.HTMLWorker;
import com.lowagie.text.html.simpleparser.StyleSheet;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.codec.Base64;

public class ConverttoPdf {
    @SuppressWarnings("unchecked")
    public static void main(String args[])
    {

        try
        {
            Document pdfDocument = new Document();
            @SuppressWarnings("unused")
            PdfWriter pdfwriter=null;
            Reader htmlreader = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\oc4j_extended_101330\\j2ee\\home\\applications\\VisiLogplus\\VisiLogplus\\login.htm")));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            pdfwriter=PdfWriter.getInstance(pdfDocument, baos);
            pdfDocument.open(); 
            StyleSheet styles = new StyleSheet();
            styles.loadTagStyle("body", "font", "Bitstream Vera Sans");
            ArrayList arrayElementList = HTMLWorker.parseToList(htmlreader, styles);
            for (int i = 0; i < arrayElementList.size(); ++i) {
                Element e = (Element) arrayElementList.get(i);
                pdfDocument.add(e);
            }
            pdfDocument.close();
            byte[] bs = baos.toByteArray();

            @SuppressWarnings("unused")
            String pdfBase64 = Base64.encodeBytes(bs); //output
            File pdfFile = new File("pdfExample.pdf");
            FileOutputStream out = new FileOutputStream(pdfFile);
            out.write(bs);
            out.close();
        }
        catch(DocumentException e)
        {
            e.printStackTrace();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
}
}
Please Help me.

Original issue reported on code.google.com by sravankumarvnit2006 on 30 Aug 2011 at 11:08

GoogleCodeExporter commented 9 years ago
You may not put it in the right place: we focus JSON.simple realted issues here.

Original comment by fangyid...@gmail.com on 29 Nov 2011 at 3:10