Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Feb 06, 2020 1:37 pm

Hello,

Using v8.1.10
See attachment
text in DOCX first paragraph ends as SPACE + "2"
Code creates a TextRange from the text of the paragraph, then saves in PDF format.
PDF is not rendering properly the last SPACE before the "2"
Saving in DOCX format works correctly.

Code: Select all
    internal void DoTest()
    {
      string inputFilename = Path.Combine(Application.StartupPath, "AA.docx");
      string outputFilename = Path.Combine(Application.StartupPath, "AA.pdf");
      Document document = new Document(inputFilename);

      Section section = document.Sections[0];
      Paragraph paragraph = section.Paragraphs[0];
     
      string texte1 = paragraph.Text;
      int nbCar = texte1.Length;
      TextSelection selection = new TextSelection(paragraph, 0, nbCar - 1);
      // Cette instruction perturbe la mise en forme dans le PDF, l'espace avant le chiffre de fin de ligne est contracté
      TextRange range = selection.GetAsOneRange();

      document.SaveToFile(outputFilename);
      Process.Start(outputFilename);
    }

danielhalte1
 
Posts: 23
Joined: Sat Dec 14, 2019 12:50 am

Fri Feb 07, 2020 7:23 am

Hi,

Thanks for your inquiry.
I finally reproduced your issue on Win10 environment with normal method. But I found the result is correct with PS method. Please use PS method to convert your file to PDF.
Code: Select all
            Document document = new Document("AA.docx");

            Section section = document.Sections[0];
            Paragraph paragraph = section.Paragraphs[0];

            string texte1 = paragraph.Text;
            int nbCar = texte1.Length;
            TextSelection selection = new TextSelection(paragraph, 0, nbCar - 1);
            // Cette instruction perturbe la mise en forme dans le PDF, l'espace avant le chiffre de fin de ligne est contracté
            TextRange range = selection.GetAsOneRange();

            ToPdfParameterList ps = new ToPdfParameterList();
            //Use PS method
            ps.UsePSCoversion = true;
            document.SaveToFile("20470PS.pdf", ps);

Attached is the result for your kind reference.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Fri Feb 07, 2020 10:35 am

Hello
I have tested and validated your method
My fear: that other problems appear with this method
My hope, and I'm going to do the tests: that some problems that I have reported disappear by this method

Thank's

danielhalte1
 
Posts: 23
Joined: Sat Dec 14, 2019 12:50 am

Mon Feb 10, 2020 2:05 am

Hi,

We will make sure the other problems you reported will be solved with the PS method and let you know in the corresponding thread.
Any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.Doc