Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Mon Dec 13, 2021 9:08 pm

When particular .docx document is converted to .pdf or images some headers appear on a previous page.
You can see such behavior for attached document "original.docx" page 12.

Code: Select all
           
            Document document = new Document(Settings.FileToProcess);
            document.SaveToFile(Settings.FileToProcess.Replace(".docx", "_images.pdf"), Spire.Doc.FileFormat.PDF);
            Document documentResult = new Document();
            var section = documentResult.AddSection();
            section.PageSetup.Margins.Top = 0f;
            section.PageSetup.Margins.Bottom = 0f;
            section.PageSetup.Margins.Left = 0f;
            section.PageSetup.Margins.Right = 0f;

            Image[] images = document.SaveToImages(Spire.Doc.Documents.ImageType.Bitmap);
            document.Close();

            foreach (var item in images)
            {
                Paragraph paragraph = section.AddParagraph();
                paragraph.AppendPicture(item);
            }

Kazax_Kazax
 
Posts: 10
Joined: Tue Nov 30, 2021 4:58 pm

Tue Dec 14, 2021 7:46 am

Hello,

Thank you for your inquiry.
I tested your Word file with your code, but did not reproduce your problem. I have attached my result file for your reference. The version I used is the latest version(Spire.Doc Pack(hot fix) Version:9.11.6). If you were not using the latest version, please first give it a try. If the issue still exists after trying, please provide the following information for further investigation. Thanks in advance.
1) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
2) Your application type, such as Console app (. Net Framework 4.5).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1101
Joined: Wed Apr 07, 2021 2:50 am

Tue Dec 14, 2021 11:02 am

Sorry, Annika but you have this problem in your result document at pages 17, 20 etc.
According to parameters of my workplace Win10 Professional 64, Spire.Doc 9.11.6, Russian region, .Net Framework 4.5

Kazax_Kazax
 
Posts: 10
Joined: Tue Nov 30, 2021 4:58 pm

Wed Dec 15, 2021 3:57 am

Hello,

Thanks for your feedback.
I used the new engine method to test your Word file again on Window10 (set the thread culture to Russian and English respectively, the code is as follows) and found that the result PDF file was different from the previous PDF file provided to you. Please check my result PDF file and confirm whether this is the result you want. If the PDF file I provided is not the result file you want, please provide me with your expected Pdf file.
In addition, I parsed the source Word file you provided and found that it was created by MS Word2010. But when I opened the source file with MS Word2010, I found that the page layout was inconsistent with the screenshot you provided (see the picture in the attachment). Please tell me the version of MS Word you used.
Code: Select all
 CultureInfo cc = Thread.CurrentThread.CurrentCulture;
 Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ru-RU");
 //Thread.CurrentThread. CurrentCulture = CultureInfo.GetCultureInfo("en-US");
 Document document = new Document("original.docx");
 // Use the new engine method
 document. UseNewEngine = true;
 document.SaveToFile("RU-result.pdf", FileFormat.PDF);
//document.SaveToFile("EN-result.pdf", FileFormat.PDF);
   ...         
  Thread.CurrentThread.CurrentCulture = cc;

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1101
Joined: Wed Apr 07, 2021 2:50 am

Thu Dec 16, 2021 10:20 pm

The same story - NewEngine helps only with saving to .pdf. Saving to images has the same bugs.

Kazax_Kazax
 
Posts: 10
Joined: Tue Nov 30, 2021 4:58 pm

Fri Dec 17, 2021 6:12 am

Hello,

Thank you for your further response.
Regarding the issue of converting Word to images, I have logged it into our bug tracking system with the ticket number SPIREDOC-7122. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.
In addition, please tell us the version of MS Word you are using, so that we can better confirm the layout of the file content you want when solving the issue.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1101
Joined: Wed Apr 07, 2021 2:50 am

Fri Dec 17, 2021 10:40 am

I use MS Word 2019 but it is not my file

Kazax_Kazax
 
Posts: 10
Joined: Tue Nov 30, 2021 4:58 pm

Mon Dec 20, 2021 5:39 am

Hello,

Thanks for your sharing, and sorry for the late reply on the weekend.
I used MS Word2019 to open your source Word file, and found that the page content on page 11, page 17 and page 20 was inconsistent with the PDF file that we converted using the new engine method, but it is consistent with the paging effect opened with MS Word2010. I have attached the screenshots (including the screenshots of the contents of the corresponding pages of source Word file and a screenshot of MS Office settings). Please reconfirm on your side whether the content of the corresponding page of the source Word file you opened is consistent with mine. If they are inconsistent, please provide the screenshots of the content you viewed.
In addition, since the source Word file you provided was created by MS Word2010, when Word is converted to PDF, we will convert it according to the open page layout of MS Word2010. Therefore, we will adjust the inconsistency of the current conversion results. For your expected result file, I suggest you add page breaks on these pages (page 11, page 17, and page 20) when creating a Word file, so that the title position is at the beginning of the new page.
Please tell me if you have any questions.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1101
Joined: Wed Apr 07, 2021 2:50 am

Mon Dec 27, 2021 2:15 am

Hello,

Greetings from E-iceblue.
Are the contents of the corresponding pages of the source Word file you viewed consistent with the contents of the screenshots I provided? If they are inconsistent, please provide the screenshots of the content you viewed. Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1101
Joined: Wed Apr 07, 2021 2:50 am

Tue Apr 26, 2022 6:29 am

Hello,

Thank you for your patience.
I used the latest version of Spire.Doc Pack (hot fix) Version: 10.4.5 to test the word file you provided before, and used the new engine method to convert the word file into an image and a PDF, and found that the page layout of the image is the same as that of the PDF. Please download the latest version and test it.
Code: Select all
CultureInfo cc = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ru-RU");
            Document document = new Document("original.docx");
            document.UseNewEngine = true;
            //document.SaveToFile("RU-result.pdf", FileFormat.PDF);
            Image[] images = document.SaveToImages(ImageType.Bitmap);
            document.Close();
            for (int i = 0; i < images.Length; i++)
            {
                images[i].Save(@"output\images-" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
            }
            Thread.CurrentThread.CurrentCulture = cc;

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1101
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc