)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to insert an RTF text into a PDF document?

Platform: WinForms |
Control: PDF |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014

 

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.

C#

//Read the RTF document

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

text = reader.ReadToEnd();

reader.Close();

//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);

VB

'Read the RTF document

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

text = reader.ReadToEnd()

reader.Close()

'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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon