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.
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