PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Fri Aug 29, 2025 10:09 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Jul 29, 2025 12:18 am 
Offline

Joined: Sun Apr 24, 2011 3:08 pm
Posts: 6
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 29, 2025 11:21 am 
Offline

Joined: Sun Apr 24, 2011 3:08 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 29, 2025 1:03 pm 
Offline

Joined: Sun Apr 24, 2011 3:08 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 31, 2025 5:23 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1054
Location: CCAA
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

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 87 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group