From e81e178f965863e3bb9053997910e73003880a4b Mon Sep 17 00:00:00 2001 From: eOPUS-Alex <93913509+eOPUS-Alex@users.noreply.github.com> Date: Wed, 1 Apr 2026 11:17:59 +0200 Subject: [PATCH 1/3] HeaderFooter fix for PDF --- .../Rendering/FormattedDocument.cs | 12 +++++++++--- .../Rendering/FormattedHeaderFooter.cs | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs index 3c9c8b24..a1e05ed9 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs @@ -193,10 +193,16 @@ Rectangle CalcContentRect(int page) XUnitPt height = pageSetup.PageHeight.Point; - height -= pageSetup.TopMargin.Point; - height -= pageSetup.BottomMargin.Point; + double topMargin = pageSetup.TopMargin.Point; + if (_formattedHeaders.TryGetValue(new HeaderFooterPosition(_sectionNumber, CurrentPagePosition), out FormattedHeaderFooter? header)) + topMargin = Math.Max(topMargin, header.ContentRect.Y.Point + header.ContentRect.Height.Point); + height -= topMargin; + double bottomMargin = pageSetup.BottomMargin.Point; + if (_formattedFooters.TryGetValue(new HeaderFooterPosition(_sectionNumber, CurrentPagePosition), out FormattedHeaderFooter? footer)) + bottomMargin = Math.Max(bottomMargin, pageSetup.PageHeight.Value - footer.ContentRect.Y.Point); + height -= bottomMargin; XUnitPt x; - XUnitPt y = pageSetup.TopMargin.Point; + XUnitPt y = topMargin; if (pageSetup.MirrorMargins) x = page % 2 == 0 ? pageSetup.RightMargin.Point : pageSetup.LeftMargin.Point; else diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedHeaderFooter.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedHeaderFooter.cs index 64940be9..bd249f37 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedHeaderFooter.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedHeaderFooter.cs @@ -25,6 +25,13 @@ internal void Format(XGraphics gfx) _formatter = new TopDownFormatter(this, _documentRenderer, _headerFooter.Elements); _formatter.FormatOnAreas(gfx, false); _contentHeight = RenderInfo.GetTotalHeight(GetRenderInfos()); + if (_headerFooter.IsHeader) + ContentRect.Height = _contentHeight; + if (_headerFooter.IsFooter) + { + ContentRect.Y = ContentRect.Y + ContentRect.Height - _contentHeight; + ContentRect.Height = _contentHeight; + } } Area? IAreaProvider.GetNextArea() From 8e933bf41b917df57d5b1fc18f0fcf1b2d3c51c5 Mon Sep 17 00:00:00 2001 From: eOPUS-Alex <93913509+eOPUS-Alex@users.noreply.github.com> Date: Wed, 1 Apr 2026 12:30:28 +0200 Subject: [PATCH 2/3] HeaderFooter fix for PDF --- .../src/MigraDoc.Rendering/Rendering/FormattedDocument.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs index a1e05ed9..bee24084 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs @@ -386,8 +386,9 @@ Area IAreaProvider.GetNextArea() ++_sectionPages; InitFieldInfos(); FormatHeadersFooters(); + Rectangle rect = CalcContentRect(_currentPage); _isNewSection = false; - return CalcContentRect(_currentPage); + return rect; } int _currentPage; From 8924df44f8f73771b8ccb8f4f8eba1dda2d03684 Mon Sep 17 00:00:00 2001 From: eOPUS-Alex <93913509+eOPUS-Alex@users.noreply.github.com> Date: Wed, 1 Apr 2026 16:25:31 +0200 Subject: [PATCH 3/3] Footer Height Fix --- .../src/MigraDoc.Rendering/Rendering/FormattedDocument.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs index bee24084..be4391b6 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs @@ -199,7 +199,7 @@ Rectangle CalcContentRect(int page) height -= topMargin; double bottomMargin = pageSetup.BottomMargin.Point; if (_formattedFooters.TryGetValue(new HeaderFooterPosition(_sectionNumber, CurrentPagePosition), out FormattedHeaderFooter? footer)) - bottomMargin = Math.Max(bottomMargin, pageSetup.PageHeight.Value - footer.ContentRect.Y.Point); + bottomMargin = Math.Max(bottomMargin, pageSetup.PageHeight.Point - footer.ContentRect.Y.Point); height -= bottomMargin; XUnitPt x; XUnitPt y = topMargin;