Hi!
Answered on Stack Overflow:
http://stackoverflow.com/a/44019399/162529PageFormat is used to set PageWidth and PageHeight if they are unset.
Invoking section.PageSetup = document.DefaultPageSetup.Clone(); assigns both PageWidth and PageHeight with the values for A4 size. Changing PageFormat later has no effect on the effective page size which remains A4.
After invoking section.PageSetup = document.DefaultPageSetup.Clone(); you have to set both PageWidth and PageHeight to the correct values.
section.PageSetup = document.DefaultPageSetup.Clone(); is used to initialize all values of PageSetup. Use this if you use PageSetup to make calculations based on margins and such.
It is not generally recommend to invoke section.PageSetup = document.DefaultPageSetup.Clone();. It is strongly recommend to use a Clone() instead of making changes to the DefaultPageSetup directly.
Setting PageFormat works as expected if you do not assign the Clone().
hoppe wrote:
I'm not sure how I'm supposed to attach the working sample project if the file size limit is 256 KiB.
Remove the BIN and OBJ folders and the NuGet packages from the ZIP.
Unless you have to include large PDFs, images, or fonts to replicate the problem, the remaining ZIP should be well below 256 KiB.