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
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
Thank you so much! This was exactly what I needed.
Hello Jouin,
Thank you for contacting Infragistics!
Instead of creating a new section you should modify the final section properties of the document writer:
https://es.infragistics.com/help/aspnet/16.2/infragistics.webui.documents.io~infragistics.documents.word.worddocumentwriter~finalsectionproperties