Hi All,

I'm trying to create a pdf file that takes html tags and renders the 
contents, however it only displays text properly but does not display 
images of the <img> tags. I use a method called filterForHtmlTags to 
convert html tags to Element objects which I use to convert any html 
that I use.Since it didn't display any image, I chose to use column text 
but this also fails.
Any suggestions as to how I can display the images?


public void createGuidelinePDF(PageView pageView) throws 
DocumentException, IOException, FileNotFoundException
      {
   
          String filePath = 
settingsDAO.getDefaultSetting().getFileStoragePath();
          String downloadfilePath = filePath;
          
           //Adding Date and Time Stamps to FileName
           String fileName =generateFileName();
          
           //Adding filename to path
           filePath+= fileName;  
             
           FileOutputStream fileOutputStream = new FileOutputStream 
(filePath);  
           PrintStream printStream;  
   
           Document doc = new Document ();
           
           PdfWriter writer = PdfWriter.getInstance (doc, 
fileOutputStream);  
           doc.open ();
           PdfContentByte cb = writer.getDirectContent();

           //paragraph.setSpacingAfter(50);
          
          
           Paragraph p = new Paragraph();
          
           //adding Headline for parent Page
           addBoldText(p, pageView.getPage().getPageName());
           changeLine(p);
          
           // adding Content for parent Page
           addNormalText(p, pageView.getPage().getContent());
           changeLine(p);
           changeLine(p);
          
          
           for(PageView subPageView : pageView.getSubPages())
           {
               generateSubPageGuidelines(subPageView, p);
           }
          

              
          
            ColumnText ct = new ColumnText(cb);
            ct.setUseAscender(true);
            ct.setSimpleColumn(doc.left(), doc.bottom(), doc.left() + 
500f, doc.top());
          
          
           ct.addElement(p);

           ct.go();
          
          
             
          
           //doc.add(p);
           doc.close ();     
          
           printStream = new PrintStream(fileOutputStream);     
           printStream.close();

}


private void addBoldItalicText(Paragraph p, String text, int fontSize)
    {
        p.add(new Chunk(text, new Font(Font.TIMES_ROMAN, fontSize, 
Font.BOLDITALIC)));
    }
   
    private void changeLine(Paragraph p){
        p.add(new Chunk("\r\n"));
    }
   
   
    private void addNormalText(Paragraph p, String text){       
        try
        {
            p.add(new Chunk(filterForHTMLTags(text).toString(), new 
Font(Font.TIMES_ROMAN, 12,Font.NORMAL)));
        } catch (IOException e) {
            p.add(new Chunk(text, new Font(Font.TIMES_ROMAN, 
12,Font.NORMAL)));       
        }       
    }       
   
    private Element filterForHTMLTags(String s) throws IOException{
        log.debug("enter_filterForHTMLTags");
        StyleSheet styles = new StyleSheet();
        styles.loadTagStyle("ol", "leading", "16,0");
                           
        StringReader reader = new StringReader(s);       
        ArrayList objects = HTMLWorker.parseToList(reader, styles);
       
        for(Object obj : objects)
        {
            log.debug("Object Type = #0", obj.toString());
        }
       
        return (Element)objects.get(objects.size()-1);   
       
    }
   







-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to