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.

Mon Aug 03, 2020 7:50 pm

Hi,

I'm having a problem during the following DOCX> HTML> DOCX conversion flow, what happens is that the original document is in portrait mode and the resulting DOCX is coming in landscape mode and i lost A4 size, messing up my entire document.

as shown below:

ORIGINAL:
Image

AFTER CONVERTED HTML TO DOCX AGAIN:
Image

This is my code (i use Spire.Doc 8.7.5 version):

Code: Select all
                    Document document = new Document();
                    document.LoadFromFile(newPath + i + "-Contrato" + ext);
                    document.AcceptChanges();

                    document.SaveToFile(newPath + @"\convertido.html", FileFormat.Html);

                    Document DestinationDoc = new Document();
                    DestinationDoc.LoadFromFile(newPath + @"\convertido.html", FileFormat.Html, XHTMLValidationType.None);
                    DestinationDoc.SaveToFile(newPath + @"\resultante.docx", FileFormat.Docx);

prado_lol
 
Posts: 10
Joined: Thu Jul 30, 2020 7:12 pm

Tue Aug 04, 2020 7:11 am

Hi,

Thanks for your post.
I tested your code, but didn't reproduce your issue. The page orientation of generated .docx is still Portrait. I attached my outputs for your reference. To help us further investigate your issue, please provide your test environment, such as OS information(E.g. Windows 7,64bit), Region setting (E.g. China, Chinese) and the .NET Framework version of your application. Thanks in avdance.

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Tue Aug 04, 2020 1:03 pm

I found something that can help, as shown in the prints below, during conversion the decimal number loses the "." turning into an integer.

before:
Image

after:
Image

answering your questions:
Windows 10 64bit, Brazil, .NET Core 2.1

Thanks in advance.

prado_lol
 
Posts: 10
Joined: Thu Jul 30, 2020 7:12 pm

Wed Aug 05, 2020 12:01 pm

Hi,

Thanks for your feedback.
With the same Region setting (Brazil) as yours, I reproduced your issue on my side. The behavior was caused by the current culture, please set it as InvariantCulture to avoid this issue. See the following code. If there is any question, please feel free to write back.
Code: Select all
            //Set the CurrentCulture as InvariantCulture
            CultureInfo cc = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            Document document = new Document();
            document.LoadFromFile(@"120-Contrato.docx");
            document.AcceptChanges();
            Section section = document.Sections[0];
            PageOrientation orientation = section.PageSetup.Orientation;
            SizeF size = section.PageSetup.PageSize;
            Console.WriteLine("the Orientation of original document is: ", orientation.ToString());
            Console.WriteLine("the Width and Height of original document are {0} , {1}: ", size.Width,size.Height);
            document.SaveToFile("convertido.html", FileFormat.Html);

            Document DestinationDoc = new Document();
            DestinationDoc.LoadFromFile("convertido.html", FileFormat.Html, XHTMLValidationType.None);
            DestinationDoc.SaveToFile("resultante.docx", FileFormat.Docx);

            Document doc = new Document();
            doc.LoadFromFile("resultante.docx");
            Section section1 = doc.Sections[0];
            PageOrientation orientation1 = section1.PageSetup.Orientation;
            SizeF size1 = section1.PageSetup.PageSize;
            Console.WriteLine("the Orientation of saved document is: ", orientation1.ToString());
            Console.WriteLine("the Width and Height of saved document are {0} , {1}: ", size1.Width, size1.Height);

            Thread.CurrentThread.CurrentCulture = cc;

Sinecerly,
Nina
E-iceblue supoport team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Wed Aug 05, 2020 2:09 pm

It's Work.

Thanks for you reply!

I have a few more questions about spire.doc before I buy it, but as they are from another topic, I will ask in another post.

thank you!

prado_lol
 
Posts: 10
Joined: Thu Jul 30, 2020 7:12 pm

Thu Aug 06, 2020 7:42 am

Hi

Thanks for your feedback.
We will reply your questions on other post.

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Return to Spire.Doc

cron