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.

Fri Aug 20, 2021 8:10 am

I am using FreeSpire.PDF.4.3.1 with .NET Framework 4.6.2.
I am unable to load rtf text (defined on a single rtf page in WordPad with #Tags that gets replaced by strings) from a rtf template file to pdf over multiple pages.
When the replacement text of the rtf #tags below (e.g. #MyDescription1,...) is long enough to not fit on a single page, then the remainder of the text is not generated on the next page of the pdf. It gets truncated to only one page.

****Sample C# code BEGIN*****

string readAllText = File.ReadAllText("myTemplate.rtf);

readAllText = readAllText.Replace("#MyDescription1", "Description 1......");
readAllText = readAllText.Replace("#MyDescription2", "Description 2......");
.....
readAllText = readAllText.Replace("#MyDescription15", "Description 15......");

PdfDocument pdf = new PdfDocument();
page = pdf.Pages.Add(PdfPageSize.A4, margin);
page = pdf.Pages.Add(PdfPageSize.A4, margin);
page.LoadFromRTF(readAllText, page.Canvas.ClientSize.Width, maxHeight, true, startingPoint);

pdf.SaveToFile("myFile.pdf");
pdf.Close();

****Sample C# code END*****

How do I change the source code above to have the rtf text over multiple pdf pages if it does not fit on a single page?

devilspeak
 
Posts: 1
Joined: Thu Aug 19, 2021 1:15 pm

Fri Aug 20, 2021 9:36 am

Hello,

Thanks for your inquiry.

I did an initial test and did notice the issue you mentioned. However, the method "LoadFromRTF" is deprecated and our Spire.PDF will not support RTF.

For your situation, we suggest you can directly use our Spire.Doc to convert the RTF to Word, replace the text and then convert to PDF. Below is the corresponding code for your reference.

Code: Select all
    Document doc = new Document();
    doc.LoadFromFile("test.rtf");
    doc.Replace("#MyDescription1", "Description 1......", false, false);
    doc.SaveToFile("myFile.pdf", Spire.Doc.FileFormat.PDF);


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF