Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
83ec240
started work in scaling pdf with percentage
AdrianEPPlus Sep 22, 2026
76ec058
Merge branch 'develop9' into feature/pdf_scaling
AdrianEPPlus Sep 22, 2026
246d6c6
Progress
AdrianEPPlus Sep 22, 2026
b1593ac
Scaling header and footer
AdrianEPPlus Sep 23, 2026
4e1303d
Added fit to page test.
AdrianEPPlus Sep 24, 2026
b65aa60
scaling progress
AdrianEPPlus Oct 1, 2026
40117fe
Added more tests for scaling
AdrianEPPlus Oct 5, 2026
9036253
Merge branch 'develop9' into feature/pdf_scaling
AdrianEPPlus Oct 5, 2026
9fdbd4d
Fixed layout order and renamed PdfCatalog to EPPlusToPdfWriter
AdrianEPPlus Oct 7, 2026
e02c710
Merge branch 'develop9' into fix/_pdf_minior_issues
AdrianEPPlus Oct 7, 2026
a9e363d
removed debug comments
AdrianEPPlus Oct 7, 2026
912d439
removed more comments from pdf.
AdrianEPPlus Oct 7, 2026
5dd4d79
Added additional info to info object.
AdrianEPPlus Oct 8, 2026
a930c16
Merge branch 'develop9' into feature/pdf_info_object_update
swmal Oct 8, 2026
7a7a324
Merge branch 'develop9' into feature/pdf_info_object_update
swmal Oct 8, 2026
d7cac71
fixed null error when reading File from package.
AdrianEPPlus Oct 8, 2026
cc62230
header footer scaling.
AdrianEPPlus Oct 12, 2026
2ed20f9
align with page margins progress
AdrianEPPlus Oct 12, 2026
34386a3
Align with page margins done
AdrianEPPlus Oct 12, 2026
84e91a5
Merge branch 'develop9' into fix/pdf_hf_fixes
AdrianEPPlus Oct 13, 2026
fa91931
removed commented code.
AdrianEPPlus Oct 13, 2026
0244d3c
Added shrink to fit & better check clipping for spilling text.
AdrianEPPlus Oct 13, 2026
b00cdbb
Fixed fill selection for total row in tables.
AdrianEPPlus Oct 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/EPPlus.Export.Pdf.Tests/PdfTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,12 +1307,23 @@ public void MultiSheet_PerSheetScaling_IsIsolated()
$"combined ({combined}) should equal plain ({plainAlone}) + scaled ({scaledAlone}) - " +
"per-sheet scaling must stay isolated");
}
public void TableDxfStyleTest()

[TestMethod]
public void TableDxfStyleTest1()
{
using var p = OpenTemplatePackage("TableDxfStylePdf1.xlsx");
var ws = p.Workbook.Worksheets[0];
string path = _pdfPath + "TableDxfStylePdf1.pdf";
ws.SaveAsPdf(path);
}

[TestMethod]
public void TableDxfStyleTest2()
{
using var p = OpenTemplatePackage("TableDxfStylePdf2.xlsx");
var ws = p.Workbook.Worksheets[0];
string path = _pdfPath + "TableDxfStylePdf2.pdf";
ws.SaveAsPdf(path);
}
}
}
37 changes: 26 additions & 11 deletions src/EPPlus.Export.Pdf/ExcelPdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void AddContent(PdfPageLayout pageLayout, PdfPage page)
!(t is PdfCellLayout cc && (cc.IsHeading || cc.IsPrintTitle)) &&
!(t is PdfCellContentLayout ccl && (ccl.IsHeaderFooter || ccl.IsHeading || ccl.IsPrintTitle || ccl.IsAddedContent)) &&
!(t is PdfCellBorderLayout cbl && cbl.IsPrintTitle)).ToList();
var headerFooterLayouts = pageLayout.ChildObjects.OfType<PdfCellContentLayout>().Where(t => t.IsHeaderFooter);
//var headerFooterLayouts = pageLayout.ChildObjects.OfType<PdfCellContentLayout>().Where(t => t.IsHeaderFooter);
var AdditionalContent = pageLayout.ChildObjects.OfType<PdfCellContentLayout>().Where(t => t.IsAddedContent && !(pageSettings.AdditionalContent != "null"));
var headingLayouts = pageLayout.ChildObjects.Where(t => (t is PdfCellLayout cl && cl.IsHeading) || (t is PdfCellContentLayout ccl && ccl.IsHeading));
var printTitleLayouts = pageLayout.ChildObjects.Where(t => (t is PdfCellLayout pl && pl.IsPrintTitle) || (t is PdfCellContentLayout pcl && pcl.IsPrintTitle) || (t is PdfCellBorderLayout pbl && pbl.IsPrintTitle));
Expand Down Expand Up @@ -246,17 +246,32 @@ private void AddContent(PdfPageLayout pageLayout, PdfPage page)
contentStream.AddCommand("Q");
}
//Add header and footer.
foreach (var hf in headerFooterLayouts)
foreach (var part in pageLayout.HeaderFooterParts)
{
contentStream.AddCellContentLayout(hf, _dictionaries, pageSettings);
}
//Add images
foreach (PdfImageLayout image in pageLayout.ChildObjects.OfType<PdfImageLayout>())
{
if (!image.IsHeaderFooter) continue;
var imageResource = _dictionaries.AddImage(image.ImageBytes);
contentStream.AddImage(imageResource.Label, image.LocalPosition.X, image.LocalPosition.Y, image.Size.X, image.Size.Y);
if (PdfImageXObject.ProducesSoftMask(image.ImageBytes)) page.HasTransparency = true;
bool scaleHf = pageLayout.ScaleHeaderFooterWithDocument;
if (scaleHf)
{
contentStream.AddCommand("q");
contentStream.AddContentScale(contentScale, part.ScalePivot.X, part.ScalePivot.Y);
}

foreach (var item in part.Items)
{
switch (item)
{
case PdfCellContentLayout text:
contentStream.AddCellContentLayout(text, _dictionaries, pageSettings);
break;
case PdfImageLayout image:
var imageResource = _dictionaries.AddImage(image.ImageBytes);
contentStream.AddImage(imageResource.Label, image.LocalPosition.X, image.LocalPosition.Y, image.Size.X, image.Size.Y);
if (PdfImageXObject.ProducesSoftMask(image.ImageBytes)) page.HasTransparency = true;
break;
}
}

if (scaleHf)
contentStream.AddCommand("Q");
}
//Add print titles
contentStream.AddCommand("q");
Expand Down
10 changes: 7 additions & 3 deletions src/EPPlus.Export.Pdf/Layout/PdfCellContentLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ internal class PdfCellContentLayout : Transform
public TextLineCollection TextLines;
public double LeftTextSpillLength = 0d;
public double RightTextSpillLength = 0d;
public double ScaleAnchorX;
public double ScaleAnchorY;
private double bottomMargin = 3.5d; //Guessed number
private double rightMargin = 1.4d; //I guessed this one too..

Expand Down Expand Up @@ -203,14 +205,16 @@ private Vector2 CalculateRotatedAlignment(double textLength, double textHeight,
return new Vector2(bx - minX, by - minY);
}

internal void SetupClipping(double cellX, double cellY, double cellWidth, double cellHeight)
internal void SetupClipping(double cellX, double cellY, double cellWidth, double cellHeight, bool spillLeft = false, bool spillRight = false)
{
double li = spillLeft ? 0d : rightMargin;
double ri = spillRight ? 0d : rightMargin;
Clip = true;
Clipping = new Rect()
{
X = cellX + rightMargin,
X = cellX + li,
Y = cellY - cellHeight,
Width = cellWidth - rightMargin * 2,
Width = cellWidth - li - ri,
Height = cellHeight
};
}
Expand Down
24 changes: 24 additions & 0 deletions src/EPPlus.Export.Pdf/Layout/PdfHeaderFooterPart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*************************************************************************************************
Required Notice: Copyright (C) EPPlus Software AB.
This software is licensed under PolyForm Noncommercial License 1.0.0
and may only be used for noncommercial purposes
https://polyformproject.org/licenses/noncommercial/1.0.0/

A commercial license to use this software can be purchased at https://epplussoftware.com
*************************************************************************************************
Date Author Change
*************************************************************************************************
27/11/2025 EPPlus Software AB EPPlus 9
*************************************************************************************************/
using EPPlus.Graphics;
using EPPlus.Graphics.Geometry;
using System.Collections.Generic;

namespace EPPlus.Export.Pdf.Layout
{
internal sealed class PdfHeaderFooterPart
{
public Vector2 ScalePivot;
public readonly List<Transform> Items = new List<Transform>();
}
}
2 changes: 2 additions & 0 deletions src/EPPlus.Export.Pdf/Layout/PdfPageLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal class PdfPageLayout : Transform
public double PrintTitleWidth;
public double PrintTitleHeight;
public bool isCommentsPage = false;
public bool ScaleHeaderFooterWithDocument;
internal List<PdfHeaderFooterPart> HeaderFooterParts = new List<PdfHeaderFooterPart>();
internal PdfPageSettings Settings;
public PdfPageLayout(double x, double y, double width, double height)
: base(x, y, width, height)
Expand Down
2 changes: 2 additions & 0 deletions src/EPPlus.Export.Pdf/Settings/PdfPageSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ public PdfScaling Scaling
private double _resolvedFitScale = 1d;
internal void SetResolvedFitScale(double s) { _resolvedFitScale = s; }

internal bool ScaleHeaderWithDocument { get; set; }

internal double ContentScale
{
get
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus/ExcelHeaderFooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public bool AlignWithMargins
{
get
{
return GetXmlNodeBool(alignWithMarginsPath);
return GetXmlNodeBool(alignWithMarginsPath, true);
}
set
{
Expand Down
Loading
Loading