Dear all
       I have to render the pdf from html. I'm using tidy parser to conver the html to xml and i passing xml to itext to render the pdf.  but it throwing exception.... Please do support.. Here is my coding
 
 
package src;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.File;
import java.io.RandomAccessFile;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStream;
import java.io.FileReader;
import java.io.BufferedReader;
import org.w3c.tidy.Tidy;
import org.apache.fop.apps.Driver;
import com.lowagie.text.Document;
import com.lowagie.text.html.SAXmyHtmlHandler;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.xml.SAXiTextHandler;

public class Html2Pdf {

    public static void main(String[] args)  {
  
     try
     {
           FileOutputStream xmlout=new FileOutputStream("c:\\test.xml");
          
     RandomAccessFile out = new RandomAccessFile("C:\\Test1.html","r");
        long datalength = out.length();
         byte [] bytearray=new byte[(int)datalength];
         out.read(bytearray);
        String htmlcontent =new String(bytearray);
        System.out.println("html content  "+htmlcontent);
       htmlcontent=htmlcontent.replaceAll("<o:p>","&nbsp;");
      htmlcontent=htmlcontent.replaceAll("</o:p>","&nbsp;");
                   
     Tidy tidy = new Tidy();
     tidy.setXmlOut(true);
        tidy.parse(new ByteArrayInputStream(htmlcontent.getBytes()), xmlout);
         
       
         System.out.println("parsed successfully");
        
         RandomAccessFile out1 = new RandomAccessFile("C:\\test.xml","r");
         long datalength1 = out1.length();
          byte [] bytearray1=new byte[(int)datalength1];
          out1.read(bytearray1);
          System.out.println("Testing:"+new String(bytearray1));
          
     Document doc=new Document();
     PdfWriter.getInstance(doc, new FileOutputStream("c:\\dummy.pdf"));
     System.out.println("before the transformer");
     SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
     System.out.println("after the transformer");
     parser.parse(new String(bytearray1), new SAXiTextHandler(doc));
   
     System.out.println("SUCCESS");
     
     }
   
     catch(Exception e){
      e.printStackTrace();
     }
     
    }
}
 
 
Here is my html input
 
<html>
<head>
<title>Test.</title>
</head>
<body>
Testing for tables..
<table border="2">
<tr>
<td> 1 column</td>
<td> 2 column</td>
</tr>
<tr>
<td> 1 data </td>
<td> 2 data </td>
</tr>
</table>
</body>
</html>
 
 
If i run this program i got below exception
 
service for checking URLs for accessibility.
java.net.MalformedURLException: no protocol: <tr>
at java.net.URL.<init>(URL.java:537)
at java.net.URL.<init>(URL.java:434)
at java.net.URL.<init>(URL.java:383)
at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:223)
at src.Html2Pdf.main(Html2Pdf.java:106)

Thanks
With Regards
Visa


Visalatchi Jayakumar
Mobile No: 0065-81131421


Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2ยข/min or less.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to