We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to insert an RTF text into a PDF document?


Essential PDF supports drawing an RTF text into a PDF document by converting it as bitmap or metafile image. Converting an RTF text into Bitmap option will have good performance while converting RTF text to metafile image will have great resolution and searchable text.

We can render the RTF text into a PDF document by using the method FromRtf() in PdfImage class.


//Read the RTF document

StreamReader reader = new StreamReader("Essential PDF.rtf", Encoding.ASCII);

text = reader.ReadToEnd();


//Convert it as Bitmap image.

PdfImage bitmap = PdfImage.FromRtf(text, bounds.Width, PdfImageType.Bitmap);

PdfLayoutFormat format = new PdfLayoutFormat();

format.Break = PdfLayoutBreakType.FitPage;

format.Layout = PdfLayoutType.Paginate;

bitmap.Draw(page, 0, 0, format);

//Convert it as metafile.

PdfMetafile metafile = (PdfMetafile)PdfImage.FromRtf(text, bounds.Width, PdfImageType.Metafile);

PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();

format.SplitTextLines = true;

//Draw the image.

metafile.Draw(page, 0, 0, format);


'Read the RTF document

Dim reader As StreamReader = New StreamReader("Essential PDF.rtf", Encoding.ASCII)

text = reader.ReadToEnd()


'Convert it as Bitmap image.

Dim bitmap As PdfImage = PdfImage.FromRtf(text, bounds.Width, PdfImageType.Bitmap)

Dim format As PdfLayoutFormat = New PdfLayoutFormat()

format.Break = PdfLayoutBreakType.FitPage

format.Layout = PdfLayoutType.Paginate

bitmap.Draw(page, 0, 0, format)

'Convert it as metafile.

Dim metafile As PdfMetafile = CType(PdfImage.FromRtf(text, bounds.Width, PdfImageType.Metafile), PdfMetafile)

Dim format As PdfMetafileLayoutFormat = New PdfMetafileLayoutFormat()

'Allow the text to flow multiple pages without any breaks.

format.SplitTextLines = True

'Draw the image.

metafile.Draw(page, 0, 0, format)

Please do find the sample from the below specified location,

http://websamples.syncfusion.com/samples/PDF.W indows/PDF_RTFSupport.zip

Article ID: Published Date: Last Revised Date: Platform: Control:
905 04/30/2011 07/10/2014 Windows Forms PDF
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.