PdfSharpCore icon indicating copy to clipboard operation
PdfSharpCore copied to clipboard

Text do not fit inside Table Cell after migration to MigraDocCore

Open PatrykPlewaOfficial opened this issue 4 years ago • 6 comments

After migration to PdfSharpCore / MigraDocCore I have noticed that text do no fit anymore in table cell. The code stayed untouched.

MigraDocCore-text-fit-issue

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.

PatrykPlewaOfficial avatar Sep 23 '20 11:09 PatrykPlewaOfficial

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.

ststeiger avatar Sep 23 '20 14:09 ststeiger

Previously worked on PdfSharp assembly version 1.50.4589.0

PatrykPlewaOfficial avatar Sep 23 '20 15:09 PatrykPlewaOfficial

My current workaround for this is:

table.BottomPadding = Unit.FromMillimeter(1.6);

PatrykPlewaOfficial avatar Sep 24 '20 07:09 PatrykPlewaOfficial

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:

image

adamxi avatar Nov 19 '20 21:11 adamxi

I am also experience the same issue.

cchillen avatar Jan 07 '21 14:01 cchillen

@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

image

[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");
        }

jafin avatar Sep 09 '21 11:09 jafin