Hello Team,

I am trying to write to PDF from a rtf document.
But when i try to do so, the entire doc is getting overwritten on the same 
line .So in one line , my entire rtf text is written.

I am reading from RTF using POI , and writing using iText.

This is my code

Document writePdf = new Document();
 
                HttpServletResponse response = null;
                 FacesContext context = FacesContext.getCurrentInstance();
                String currentEvent = "Document.pdf" ;
                response = (HttpServletResponse) 
context.getExternalContext().getResponse();
                response.setHeader("Content-disposition", "attachment; 
filename="+ currentEvent);
                response.setHeader("Pragma", "public");
                response.setDateHeader("Expires", 0);
                response.setHeader("Cache-Control","must-revalidate, 
post-check=0, pre-check=0");
                response.setHeader("Cache-Control", "public");
                response.setHeader("Content-Description", "File Transfer"
);
                response.setContentType("application/pdf");
 
 
                PdfWriter.getInstance(writePdf, 
response.getOutputStream()); 
                writePdf.open();
 
 
                //POI stuff
                POIFSFileSystem fspdf = new POIFSFileSystem(new 
FileInputStream("myRTFfile.rtf"));
                HWPFDocument docpdf = new HWPFDocument(fspdf);
 
 
 
                Range r1pdf = docpdf.getRange();
                for (int i = 0; i < r1pdf.numSections(); ++i) 
                {
                   Section spdf = r1pdf.getSection(i);
                   for (int x = 0; x < spdf.numParagraphs(); x++)
                        {
                                  org.apache.poi.hwpf.usermodel.Paragraph 
paraPdf = spdf.getParagraph(x);
                                  for (int z = 0; z < 
paraPdf.numCharacterRuns(); z++) 
                                  {
                                        CharacterRun runPdf = 
paraPdf.getCharacterRun(z);
                                        String text = runPdf.text();
                                         Chunk chunk=new Chunk();
                                        chunk.append(text);
                                        writePdf.add(Chunk.NEWLINE);
                                        writePdf.add(chunk);
 

                                }

                }

        }
 
                writePdf.close();
 
                 response.getOutputStream().close();
                 context.responseComplete();


Attached is the PDF generated.
Can someone plz help me in this. 






Regards,
Swapna Matanam
Tata Consultancy Services
Mailto: [email protected]
Website: http://www.tcs.com
____________________________________________
Experience certainty.   IT Services
                        Business Solutions
                        Outsourcing
____________________________________________
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you


Attachment: Document.pdf
Description: Binary data

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to