PdfSharpCore
PdfSharpCore copied to clipboard
Text do not fit inside Table Cell after migration to MigraDocCore
After migration to PdfSharpCore / MigraDocCore
I have noticed that text do no fit anymore in table cell.
The code stayed untouched.
As you can see, MigraDocCore
generated PDF document has some extra top cell spacing/margin/distance, which results in pruning some part of text with cell border.
Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MigraDocCore.DocumentObjectModel" Version="0.1.1" />
<PackageReference Include="MigraDocCore.Rendering" Version="0.1.0" />
<PackageReference Include="PdfSharpCore" Version="1.2.6" />
<PackageReference Include="PdfSharpCore.Charting" Version="0.1.0" />
</ItemGroup>
</Project>
Repro Code:
Document document = new Document();
Section section = document.AddSection();
Table table = section.AddTable();
table.Borders.Width = 0.25;
for (int i = 0; i < 4; i++)
{
var column = table.AddColumn();
column.Format.Alignment = ParagraphAlignment.Center;
}
Row row = table.AddRow();
row.HeadingFormat = false;
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = false;
row.Cells[0].AddParagraph("Payment Date From:");
row.Cells[0].Format.Font.Bold = true;
row = table.AddRow();
row.HeadingFormat = false;
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = false;
row.Cells[0].AddParagraph("Entered by");
row.Cells[0].Format.Font.Bold = true;
row = table.AddRow();
row.HeadingFormat = false;
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = false;
row.Cells[0].AddParagraph("Data sorted by");
row.Cells[0].Format.Font.Bold = true;
// ...
I don't know if there is some kind of breaking change which adds a default top margin or it's an issue.
It may be an issue that has been fixed in PdfSharp after MigraDocCore has branched from MigraDoc.NET. Or it may be incorrect font handling.
Previously worked on PdfSharp
assembly version 1.50.4589.0
My current workaround for this is:
table.BottomPadding = Unit.FromMillimeter(1.6);
Experiencing the same issue. I've drawn borders around the paragraph and it's clear that the font is simply simply being calculated too high:
I am also experience the same issue.
@PatrykPlewaOfficial
I ran the code above, on PDFSharpCore 1.2.19 MigraDocCore.Rendering 0.1.3 and it appears to match the expected?
Perhaps has been fixed? If so consider closing the issue
[Fact]
public void VerifyMarginPadding()
{
var document = new Document();
var section = document.AddSection();
var table = section.AddTable();
table.Borders.Width = 0.25;
for (var i = 0; i < 4; i++)
{
var column = table.AddColumn();
column.Format.Alignment = ParagraphAlignment.Center;
}
var row = table.AddRow();
row.HeadingFormat = false;
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = false;
row.Cells[0].AddParagraph("Payment Date From:");
row.Cells[0].Format.Font.Bold = true;
row = table.AddRow();
row.HeadingFormat = false;
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = false;
row.Cells[0].AddParagraph("Entered by");
row.Cells[0].Format.Font.Bold = true;
row = table.AddRow();
row.HeadingFormat = false;
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = false;
row.Cells[0].AddParagraph("Data sorted by");
row.Cells[0].Format.Font.Bold = true;
// Create a renderer for the MigraDoc document.
const bool unicode = false;
var pdfRenderer = new PdfDocumentRenderer(unicode)
{
Document = document
};
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save("C:\\temp\\table.pdf");
}