PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
Having trouble with Orientation.Landscape after update https://forum.pdfsharp.net/viewtopic.php?f=2&t=4863 |
Page 1 of 1 |
Author: | DotNetSchnauz [ Tue Jul 29, 2025 12:18 am ] |
Post subject: | Having trouble with Orientation.Landscape after update |
Hello I have a legacy .NET Framework app that uses a quite old version of MigraDoc / PdfSharp that I am updating to .NET 8.0 As part of this I have updated to the newest version from nuget (6.2.1) My legacy code works fine EXCEPT that Orientation.Landscape does not work for me anymore. I reviewed release notes and looked through the forum but I just can figure it out. Has something been deprecated or changed? I used to just do this..... MigraDoc.DocumentObjectModel.Section section = cDocument.AddSection(); section.PageSetup.PageWidth = MD.Unit.FromInch(8.5); section.PageSetup.PageHeight = MD.Unit.FromInch(11); section.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape; section.PageSetup.TopMargin = new MigraDoc.DocumentObjectModel.Unit(0.60, MigraDoc.DocumentObjectModel.UnitType.Inch); section.PageSetup.LeftMargin = new MigraDoc.DocumentObjectModel.Unit(0.25, MigraDoc.DocumentObjectModel.UnitType.Inch); section.PageSetup.RightMargin = new MigraDoc.DocumentObjectModel.Unit(0.25, MigraDoc.DocumentObjectModel.UnitType.Inch); section.PageSetup.BottomMargin = MD.Unit.FromInch(0.5); MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph("........... I tried a very simplified version after reading the forums MD.Document document = new MD.Document(); MD.Section section = document.AddSection(); section.PageSetup = document.DefaultPageSetup.Clone(); section.PageSetup.Orientation = MD.Orientation.Landscape; ............... Nothing I try seems to work. I am certain it is something stupid I am doing but I would appreciate a nudge in the right direction. Thank you |
Author: | DotNetSchnauz [ Tue Jul 29, 2025 11:21 am ] |
Post subject: | Re: Having trouble with Orientation.Landscape after update |
After much further experimentation I have discovered that it is not the document or PDF rendering that does not work correctly for me but the winforms document preview control. Has anyone observed this? Regardless of the actual page layout the control always shows portrait. |
Author: | DotNetSchnauz [ Tue Jul 29, 2025 1:03 pm ] |
Post subject: | Re: Having trouble with Orientation.Landscape after update |
I looked at what you were doing in DocumentPreview.cs in the Page prop. I think something may be backwards. When I add the following to my viewer form to it works as expected (Width and Height are NOT reversed for Landscape): private void documentPreview1_PageChanged(object sender, EventArgs e) { int pageNum = documentPreview1.Page; PageInfo pageInfo = documentPreview1.Renderer.FormattedDocument.GetPageInfo(pageNum); if (pageInfo.Orientation == PdfSharp.PageOrientation.Portrait) { documentPreview1.PageSize = new Size((int)(double)pageInfo.Width, (int)(double)pageInfo.Height); } else { documentPreview1.PageSize = new Size((int)(double)pageInfo.Width, (int)(double)pageInfo.Height); } } Seems counter intuitive to me but this change works. |
Author: | TH-Soft [ Thu Jul 31, 2025 5:23 am ] |
Post subject: | Re: Having trouble with Orientation.Landscape after update |
Hi! DotNetSchnauz wrote: My legacy code works fine EXCEPT that Orientation.Landscape does not work for me anymore. I reviewed release notes and looked through the forum but I just can figure it out. Has something been deprecated or changed? There is a documented breaking change with respect to orientation and there is a new ResetPageSize method in the PageSetup class. See here:https://docs.pdfsharp.net/MigraDoc/DOM/ ... #page-size If you think there is a bug in the Preview class, then please use the IssueSubmissionTemplate to make it reproducible. https://docs.pdfsharp.net/General/Issue ... About.html |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |