Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Nov 05, 2019 8:15 am

Hi Spire!
Is there any way how to draw RTF text data onto PDF page?

As an example, the following RTF text data:
{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard
This is some {\b bold} text.\par
}


is a document which would be rendered like this when read by a program that supports RTF:
This is some bold text.

Source: https://en.wikipedia.org/wiki/Rich_Text_Format
Best regards,
Vladimir

procamSpire
 
Posts: 22
Joined: Tue Sep 03, 2019 7:56 am

Tue Nov 05, 2019 10:28 am

Hi,

Thanks for your inquiry.
Sorry that Spire.PDF doesn't support to draw rtf text on the page of an existing PDF. If you want to convert Rtf file to Pdf file, please try to use Spire.Doc(Now the latest version is Spire.Doc Pack(hot fix) Version:7.11.1). Or you could append rtf string to the Word file then convert it to Pdf file. Below is the code for your reference.
Code: Select all
            //Convert Rtf file to Pdf file
            Document doc = new Document();
            doc.LoadFromFile(@"B0009STM.rtf", Spire.Doc.FileFormat.Rtf);
            doc.SaveToFile(@"resultCore.pdf", Spire.Doc.FileFormat.PDF);

            //Append rtf string to the Word file then convert it to Pdf file.
            doc.LoadFromFile(@"……\filename.docx");
            string rtfCode = "your rtf code";
            doc.Sections[0].Paragraphs[0].AppendRTF(rtfCode);
            doc.SaveToFile(@"resultCore-1.pdf",Spire.Doc.FileFormat.PDF);


Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Thu Dec 26, 2019 10:35 am

Hi,

Greetings from E-iceblue.
Have you tried the code I offered you last time? Does it solve your issue? Could you please give us some feedback at your convenience?

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Jan 08, 2020 9:59 am

Amber.Gu wrote:Hi,

Greetings from E-iceblue.
Have you tried the code I offered you last time? Does it solve your issue? Could you please give us some feedback at your convenience?

Best wishes,
Amber
E-iceblue support team


Hi Spire!
Is there any way how to draw RTF text data stored in string variable or buffer and draw it onto PDF page using Spire.PDF?
We do not want to use Spire.Doc.
Best regards,
Procam

procamSpire
 
Posts: 22
Joined: Tue Sep 03, 2019 7:56 am

Thu Jan 09, 2020 7:16 am

Hi,

Thanks for your reply.
Sorry that Spire.PDF doesn't support to convert RTF to PDF. I'm afraid at present the only way to convert RTF to PDF is to use Spire.Doc(now the latest version is Spire.Doc Pack(hot fix) Version:7.12.23).
Our sales team just sent you a one-month free license of Spire.Doc to help you remove the warning information. Please check and apply it to have a better evaluation on our product. Here is a guide for you: https://www.e-iceblue.com/Tutorials/Licensing/Licensing.html.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Feb 16, 2021 10:19 am

Hello.
I think that you do not understand me. I do not want to convert RTF file to PDF,
but I have RTF formatted text in string variable/buffer and I want to draw it onto PDF page on specific position x, y.

For example RTF formatted text looks like:

Code: Select all
{\rtf1\ansi\deff0
{\colortbl;\red0\green0\blue0;\red255\green0\blue0;}
This line is the default color\line
\cf2
This line is red\line
\cf1
This line is the default color
}


RTF formatting uses control characters escaped with backslashes along with nested curly braces.

So it is some kind of styled text like the HTML Styled Text (PdfHTMLTextElement) which is allready implemented in Spire.PDF
https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Text/How-to-Insert-HTML-Styled-Text-to-PDF-in-C-VB.NET.html

you can see for some details here: https://chrisbenard.net/2014/08/20/extract-text-from-rtf-in-c-net/

It is possible to implement this another kind of styled text type - RTF formatted text to Spire.PDF?
Thank you.
BR

procamSpire
 
Posts: 22
Joined: Tue Sep 03, 2019 7:56 am

Tue Feb 16, 2021 2:14 pm

Hello,

Thanks for your message.
I'm sorry that currently our Spire.Pdf doesn't have a direct way to add RTF text to the PDF specified location. Since we have a 7-Day Chinese Spring Festival Holiday during 02/11/2021-02/17/2021, once we come back to work on Feb 18, 2021, I will further confirm with dev colleagues if there is any workaround approach to achieve it. Thanks for your patience.

Sincerely,
Sofia
E-iceblue support team
User avatar

Sofia.Yang
 
Posts: 84
Joined: Tue Jul 14, 2020 1:41 am

Thu Feb 18, 2021 9:58 am

Hello,

Sorry for the truth that our Spire.Pdf doesn't provide the method to insert RTF text into PDF anymore. Please use our Spire.Doc instead to insert rtf string to Word document. Please download the latest Spire.Doc (Spire.Doc Pack(hot fix) Version:9.2.0) and use the following code to have a try.
Code: Select all
Document doc = new Document();
Section section = doc.AddSection();
// Add a paragraph to the section.
Paragraph para = section.AddParagraph();
//Declare a String variable to store the RTF string.
String rtfString = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 hakuyoxingshu7000;}}\f0\fs28 Hello, World}";
// Append RTF string to paragraph.
para.AppendRTF(rtfString);
//Save to PDF file.
doc.SaveToFile("Output.pdf", FileFormat.PDF);


Sincerely,
Sofia
E-iceblue support team
User avatar

Sofia.Yang
 
Posts: 84
Joined: Tue Jul 14, 2020 1:41 am

Return to Spire.PDF