Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all,

How can i generate pdf version of my document, which is RichTextBox.
Help me with proper solution..

Thanks.
Posted
Comments
virang_21 12-Aug-12 0:35am    
check iTextSharp library...it is easy to use and open source..

1 solution

download itextsharp.dll 5.1.2.0 version i have used before.Then try with this..
C#
// step 1: creation of a document-object
iTextSharp.text.Document myDocument = new iTextSharp.text.Document(PageSize.A4.Rotate());
try
{
    // step 2:
    // Now create a writer that listens to this doucment and writes the document to desired Stream.

    PdfWriter.GetInstance(myDocument, new FileStream(sfd.FileName, FileMode.Create));

    // step 3:  Open the document now using
    myDocument.Open();

    // step 4: Now add some contents to the document
    myDocument.Add(new iTextSharp.text.Paragraph(richTextBox1.Text));
}
catch (DocumentException de)
{
    Console.Error.WriteLine(de.Message);
}
catch (IOException ioe)
{
    Console.Error.WriteLine(ioe.Message);
}
// step 5: Remember to close the documnet
myDocument.Close();

It will successfully create pdf files of your writing.Know me if these helps you..
 
Share this answer
 
Comments
Durgamuthu 9-Jul-13 8:57am    
hai thanks its creating file but im not getting the font style and all, i want to export the data in actual format
Prasad Khandekar 9-Jul-13 9:20am    
Hello,

Consider converting the RTF to equivalent HTML and then use XMLWorker class to to write it into PDF. The XMLWroker examples can be found here (http://demo.itextsupport.com/xmlworker/itextdoc/flatsite.html). For converting RTF to HTML you can either use Aspose Word (http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx) or this cp library (http://www.codeproject.com/Articles/27431/Writing-Your-Own-RTF-Converter).

Regards,
ridoy 9-Jul-13 13:02pm    
Yes,in case of font style you can follow what Prasad said,to see whether it works or not..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900