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 Mar 25, 2021 7:56 am

Hello, i'm going to writing you to connect with my problem. I dont know, how i can set page margin by css by SpireDoc.

For example:
Code: Select all
<html class="no-js">
   <head>
      <meta charset="utf-8" />
      <meta http-equiv="x-ua-compatible" content="ie=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1" />
      <style>
         @page WordSection {
            margin: 0.6in 0.8in 0.7in 0.8in;
            mso-header-margin: 0.1in;
            mso-footer-margin: 0.1in;
            mso-paper-source: 0;
         }

         div.word-sections
         {
            page: WordSection;
         }
      </style>
   </head>
   <body>
      <div class="word-sections">
         <p>
            Hello world
         </p>
      </div>
   </body>
</html>


If I open this html by Word 365, word page margins set 1,52cm 2,03cm 1,78cm 2,03cm , but after Spire convertation, i always take base settings 2cm 1,5 cm 2cm 3cm. It's bug or not?

IgorSukhov
 
Posts: 6
Joined: Tue Mar 10, 2020 12:21 am

Thu Mar 25, 2021 9:27 am

Hello,

Thanks for your inquiry.
When using our Spire.Doc to convert HTML to Word, it uses the default margins inside our product, which are different from the rules of Microsoft Word. However, you can refer to the code below to set your desired margins. Feel free to contact us if you have further questions.
Code: Select all
            Document document = new Document();
            document.LoadFromFile(@"new.html", FileFormat.Html, XHTMLValidationType.None);
            Section sec = document.Sections[0];
            sec.PageSetup.Margins.Top = (float)(1.52 * 28.35);
            sec.PageSetup.Margins.Bottom = (float)(2.03 * 28.35);
            sec.PageSetup.Margins.Left = (float)(1.78 * 28.35);
            sec.PageSetup.Margins.Right = (float)(2.03 * 28.35);
            document.SaveToFile("HtmlFileToWord.docx", FileFormat.Docx);


Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Fri Apr 09, 2021 9:37 am

Hello,

Greetings from E-iceblue!
Has the issue been solved now? Could you please give us some feedback at your convenience?

Sincerely,
Andy
E-iceblue support team
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.Doc