Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
815
Word Adds A Blank Page After Calling writer.DefineSection()
posted

I am using version 15.1.20151.1018.

I have a web application that that allows the user to generate several different word documents. Some of these documents require custom page margins and custom page sizes. The problem is, when I define a section to apply the custom margins and page size, an extra blank page is added to the end of my document.

How can I apply these custom margins and custom page sizes without adding the extra blank page at the end? Or at least remove the extra blank page at the end?

Here is the relevant code:

Using writer As WordDocumentWriter = WordDocumentWriter.Create(filePath)

   ' start the word document
   writer.StartDocument()


   Dim font As Infragistics.Documents.Word.Font = writer.CreateFont()
   font.Underline = Underline.Single
   font.BackColor = Drawing.Color.Yellow

   writer.StartParagraph()
   writer.AddTextRun("PLEASE SIGN AND RETURN IN THE ENCLOSED ENVELOPE", font)
   writer.EndParagraph()

   writer.Unit = UnitOfMeasurement.Inch

   Dim pageMargins As New Padding(1.25, 1, 1.25, 1)

   Dim sectionProperties As SectionProperties = writer.CreateSectionProperties()

   sectionProperties.PageSize = New Drawing.SizeF(8.5F, 11.0F)
   sectionProperties.PageMargins = pageMargins

   writer.DefineSection(sectionProperties)

   writer.EndDocument()

End Using

Parents
No Data
Reply Children