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.

Thu Aug 03, 2017 7:49 pm

Can someone help me to understand what is that I am doing wrong? You can see that the text on page 2, page 13...etc are cut off between pages. I have attached the input RTF file and the output PDF document, and the C# code I used.

.NET Code Used (Copied from Sample)
PdfDocument pdf = new PdfDocument();
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();

PdfMargins margin = new PdfMargins();
margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Bottom = margin.Top;
margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Right = margin.Left;

PdfPageBase page = pdf.Pages.Add(PdfPageSize.A4, margin);
var rtf = System.IO.File.ReadAllText(@"C:\Users\Jay\Desktop\United States of America.rtf");
page.LoadFromRTF(rtf, page.Canvas.ClientSize.Width, true);
pdf.SaveToFile(@"C:\Users\Jay\Desktop\DELETE\United States of America.pdf");

ijayaks
 
Posts: 3
Joined: Thu Aug 03, 2017 7:24 pm

Fri Aug 04, 2017 3:08 am

Hello,

Thanks for your inquiry.
I have noticed the issue and referred it to our dev team for fixing. Once there's any good news, I will let you know.
In addition, there's a much easier way to convert rtf file to pdf, that is using Spire.Doc. I have tested it and the result is correct. Please download the hotfix(Spire.Doc Pack(hot fix) Version:6.0.5) and use the code below.
Code: Select all
Document doc = new Document();
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\Files\United States of America.rtf", FileFormat.Rtf);
            doc.SaveToFile(@"C:\Users\Administrator\Desktop\Files\doc.pdf", FileFormat.PDF);

If there's still any doubt, welcome to contact us.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Aug 16, 2017 4:44 pm

Thanks Jane. Unfortunately we don't have license to Spire.Rtf. Will wait for the hotfix. Fingers crossed.

ijayaks
 
Posts: 3
Joined: Thu Aug 03, 2017 7:24 pm

Thu Aug 17, 2017 2:13 am

Hello Jay,

Thanks for your response.
After a further investigation, the cut-off issue can be avoided by setting the last parameter to be false in the method "LoadFromRTF", it should be like below.
Code: Select all
page.LoadFromRTF(rtf, page.Canvas.ClientSize.Width, false);

But since the Spire.Pdf reads the content of the original rtf file by stream, the typesetting will not be the same as the source file.
Sorry for the inconvenience casued.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Aug 17, 2017 5:16 pm

Thank you for the quick response, Jane. That worked. Does setting isSplitLine = false cause problems during printing? What is the impact of turning this flag off?

Best,
Jay

ijayaks
 
Posts: 3
Joined: Thu Aug 03, 2017 7:24 pm

Fri Aug 18, 2017 6:20 am

Hello Jay,

Thanks for your response.
Once you set the "isSplitLine = false", that means there is no split line which will cut the content off and all the content will be writen one by one util the page is filled. Theoritically, there's no bad impact of turning this off.
If you encounter any issue, please feel free to contact us.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Jan 15, 2019 1:25 pm

hello
I face the same probleme when I add Imeges in RichTextBox and save it to Pdf... it spans across the page, I used "page.LoadFromRTF(rtf, page.Canvas.ClientSize.Width, false);" and it is work very good with Text but not with Images.
can you help me pleas!!!

bioparhom2018
 
Posts: 6
Joined: Tue Jan 15, 2019 1:18 pm

Wed Jan 16, 2019 8:02 am

Hi bioparhom,

Thanks for your inquiry.
To help us investigate further, please upload your input RTF and the entire code you were using here or send it to me(Betsy.jiang@e-iceblue.com) via Email.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Jan 23, 2019 8:14 am

Hi bioparhom,

Hope you are doing well.
Has your issue been resolved? Could you please give us some feedback at your convenience?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Jan 24, 2019 11:16 am

Hello,
sorry for being late.
in fact, I have multi object of User Controller, and the dimensions of these objects can change every time, I want to save all these object on my form to pdf file, for that I drawed these controller in Bitmap Image and pasted them to Richtextbox element.
after that when I saved it to PDF file, It was done well but it spans across the page

bioparhom2018
 
Posts: 6
Joined: Tue Jan 15, 2019 1:18 pm

Thu Jan 24, 2019 11:30 am

This is part of My code

Code: Select all
private void AddMyformToRichtextbox()
{
   Bitmap bitmap;
   Size s;
   
   s= Userbloc1.Size;
   bitmap = new Bitmap(s.Width, s.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
   Userbloc1.DrawToBitmap(bitmap, Userbloc1.DisplayRectangle);
   Clipboard.SetImage(bitmap);
   richTextBox1.Paste();           
   bitmap.Dispose();

   s= Userbloc2.Size;
   bitmap = new Bitmap(s.Width, s.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
   Userbloc2.DrawToBitmap(bitmap, Userbloc2.DisplayRectangle);
   Clipboard.SetImage(bitmap);
   richTextBox1.Paste();           
   bitmap.Dispose();
   
   s= Userbloc3.Size;
   bitmap = new Bitmap(s.Width, s.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
   Userbloc3.DrawToBitmap(bitmap, Userbloc3.DisplayRectangle);
   Clipboard.SetImage(bitmap);
   richTextBox1.Paste();           
   bitmap.Dispose();

   SaveAsPDF();           
}


Code: Select all
private void SaveAsPDF()
{
   SaveFileDialog saveFileDialog1 = new SaveFileDialog();
   saveFileDialog1.FileName = "TestPDF";
   saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
   saveFileDialog1.Filter = "PDF|*.pdf";
   saveFileDialog1.Title = "Save";
   if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
   {
      if (saveFileDialog1.FileName.Length > 0)
      {
         PdfDocument pdf = new PdfDocument();
         PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
         //Style
         PdfMargins margin = new PdfMargins();
         margin.Top = unitCvtr.ConvertUnits(0.8f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
         margin.Bottom = unitCvtr.ConvertUnits(1.00f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
         margin.Left = unitCvtr.ConvertUnits(1.0f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
         margin.Right = margin.Left;

         PdfPageBase page = pdf.Pages.Add(PdfPageSize.A4, margin);
         //create a header template with content and apply it to page template
         pdf.Template.Top = CreateHeaderTemplate(pdf, margin);
         //pdf.Template.Bottom = CreateFooterTemplate(pdf, margin);

         page.LoadFromRTF(richTextBox1.Rtf, page.Canvas.ClientSize.Width, false);

         pdf.SaveToFile(FileName);

         MessageBox.Show("Done!");
         System.Diagnostics.Process.Start(FileName);;
      }
   }
}

bioparhom2018
 
Posts: 6
Joined: Tue Jan 15, 2019 1:18 pm

Fri Jan 25, 2019 3:20 am

Hi bioparhom,

Thanks for your information.
I simulated some data and then tested your code, yet I didn't reproduce your issue. To help us investigate your issue accurately, could you please share a sample RTF file or a sample project for showing your issue?
Besides, now the conversion function from RTF to PDF has been marked as deprecated in the latest Spire.PDF V5.1.16. Our Spire.Doc supports the function better, you could have a try.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jan 25, 2019 9:13 am

thank you for your fast response.
I updated it to version 5.1, but the problem is still existing... and Unfortunately, I found another one... now the result in the first page is ok but the other page is Empty.

I will send you my PDF file by Email...

Sincerely.

bioparhom2018
 
Posts: 6
Joined: Tue Jan 15, 2019 1:18 pm

Fri Jan 25, 2019 9:41 am

Hi Amjad,

Many thanks for your PDF.
I need your input RTF file, please share it. Thanks in advance.

Best wishes,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jan 25, 2019 11:48 am

Hi
I send you by Email a small prototype with it's result PDF...
thanks in advance

bioparhom2018
 
Posts: 6
Joined: Tue Jan 15, 2019 1:18 pm

Return to Spire.PDF