Branched from~ 188409 ~Preservation issue occurs while drawing the PDF Grid with a page break

Jacques

Hi. Sure. Here is an example. It prints a big PDF that will show the problem. I've also included in the folder the result I'm getting. I apologize for the code. I've reused part of an existing project and have only do the necessary changes so that I can publish it.


Attachment: TestPdfOutput_a0b9fa15.zip


8 Replies

IJ Irfana Jaffer Sadhik Syncfusion Team December 17, 2024 12:27 PM UTC

Hi Jacques,


We were able to reproduce the reported behavior with the provided details on our end. Currently, we are analyzing this on our end, and we will share the further details on December 19th, 2024.


Regards,

Irfana J.



AG Aribalakrishnan Govindasamy Syncfusion Team December 19, 2024 02:07 PM UTC

Hi Jacques,
We have confirmed the issue “Text overlapping while drawing the PdfHTMLTextElement” as a defect in our product and we will include the fix into our upcoming weekly NuGet release on January 7th, 2025.
 
Please use the below feedback link to track the status of the reported bug.
  
Note: If you require a patch for the reported issue in any of our Essential Studio Main or SP release version, then kindly let us know the version, so that we can provide a patch in that version based on our SLA policy.
 
Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization
Regards,
Aribalakrishnan G.


JA Jacques December 19, 2024 02:28 PM UTC

Great. Thanks for the confirmation. Looking forward for the fix.



AG Aribalakrishnan Govindasamy Syncfusion Team January 7, 2025 01:45 PM UTC

Hi  Jacques,


Sorry for the inconvenience caused.

 Due to concerns about stability, we cannot include the fix in our last weekly update. So, we have created the custom patch for the latest weekly release version. We will ensure that the solution is included in our next weekly NuGet release, which you can expect on January 15th, 2024.


Regards,

Aribalakrishnan G.



IJ Irfana Jaffer Sadhik Syncfusion Team January 16, 2025 11:34 AM UTC

Hi Jacques,

We have included the fix for this issue "Text overlapping while drawing the PdfHTMLTextElement" in our latest weekly release (28.1.39).Please download the NuGet from the below link

 

NuGet  : NuGet Gallery | Syncfusion.Pdf.Net.Core 28.1.39


Root cause : 

While drawing the HTML multiple times when exceeds the page height paginated. After paginating new page bounds are not set properly that's why issues occur.

Moreover, we have modified the sample as per your requirement. Please find the attached sample


Regards,

Irfana J.


Attachment: Sample_2_c45063c2.zip


JA Jacques January 17, 2025 06:55 AM UTC

Hi. I just tested with the example I've created previeously. The new version partially fixes the problem. I indeed don't see the page with only a single line on top. But I still see sometimes text overlapping on top of page. Here is an example:

Image_8902_1737096742265

You should be able to reproduce this using the sample I provided.



JT Jeyalakshmi Thangamarippandian Syncfusion Team January 20, 2025 12:56 PM UTC

Hi Jacques ,


We have ensured that the reported issue on our end is not reproducible and everything works as expected. Could you please confirm if you used the modified sample we provided? Upon further analysis of your sample, we observed that the pagination's new page top position was not calculated properly. We have modified it as per the requirements. Please find the modified code snippet and the latest NuGet version (28.1.39.0)

// Create PDF content

PdfDocument doc = new PdfDocument();

doc.PageSettings.Margins.Left = MARGIN_LEFT;

doc.PageSettings.Margins.Right = MARGIN_RIGHT;

doc.PageSettings.Margins.Top = MARGIN_TOP;

doc.PageSettings.Margins.Bottom = MARGIN_BOTTOM + FOOTER_HEIGHT + FOOTER_MARGIN;

// Create page

var page = doc.Pages.Add();

var PageWidth = doc.PageSettings.Width;

var PageInnerWidth = page.GetClientSize().Width;

string FontPath = Path.Combine(_webEnvironment.WebRootPath, "fonts", "Univers.otf");

string FontBoldPath = Path.Combine(_webEnvironment.WebRootPath, "fonts", "Univers-Bold.otf");

var StdFont = new PdfTrueTypeFont(FontPath, 10f);

var SmallerFont = new PdfTrueTypeFont(FontBoldPath, 9f);

var Format = new PdfLayoutFormat();

Format.Layout = PdfLayoutType.Paginate;

Format.Break = PdfLayoutBreakType.FitPage;

var FormatCenter = new PdfStringFormat();

FormatCenter.Alignment = PdfTextAlignment.Center;

var FormatRight = new PdfStringFormat();

FormatRight.Alignment = PdfTextAlignment.Right;

// Now, we need to go through all the tasks (then hours) one by one.

// On recurring projects, we only display the chapters that have been linked to the project.

// It much simpler.

var curTop = 0f;

// First, do the job with std font

var dataList = System.IO.File.ReadAllLines(Path.Combine(_webEnvironment.WebRootPath, "data.txt"));

foreach (var data in dataList)

{

    page.Graphics.DrawString(DateTime.Now.ToString("dd.MM.yyyy"), SmallerFont, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(0, curTop, 50, LINE_HEIGHT));

    page.Graphics.DrawString("AA", SmallerFont, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(60, curTop, 20, LINE_HEIGHT), FormatCenter);

    page.Graphics.DrawString(0.ToString("N2") + " h", SmallerFont, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(PageInnerWidth - 110, curTop, 40, LINE_HEIGHT), FormatRight);

    page.Graphics.DrawString(0.ToString("N2"), SmallerFont, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(PageInnerWidth - 60, curTop, 60, LINE_HEIGHT), FormatRight);

    var taskDesc = new PdfHTMLTextElement(data, SmallerFont, PdfBrushes.Black);

    var taskDescResult = taskDesc.Draw(page, new Syncfusion.Drawing.PointF(90, curTop), PageInnerWidth - 240, Format);

    if (page != taskDescResult.Page)

    {

        if(taskDescResult is PdfTextLayoutResult textLayoutResult)

        {

            page = taskDescResult.Page;

            curTop = textLayoutResult.LastLineBounds.Bottom + (LINE_HEIGHT / 2);

        }

    }

    else

    {

        curTop = taskDescResult.Bounds.Bottom + (LINE_HEIGHT / 2);

        if (curTop + (LINE_HEIGHT * .8) > page.GetClientSize().Height)

        {

            page = doc.Pages.Add();

            curTop = 0;

        }

    }

}

//Same with ttf font

page = doc.Pages.Add();

curTop = 0;

string FontPathTTF = Path.Combine(_webEnvironment.WebRootPath, "fonts", "UniversRegular.ttf");

string FontBoldPathTTF = Path.Combine(_webEnvironment.WebRootPath, "fonts", "UniversBold.ttf");

var StdFontTTF = new PdfTrueTypeFont(FontPathTTF, 10f);

var SmallerFontTTF = new PdfTrueTypeFont(FontBoldPathTTF, 9f);

foreach (var data in dataList)

{

    // Make sure we have two lines fitting the page.

    if (curTop + (LINE_HEIGHT * .8) > page.GetClientSize().Height)

    {

        page = doc.Pages.Add();

        curTop = 0;

    }

    page.Graphics.DrawString(DateTime.Now.ToString("dd.MM.yyyy"), SmallerFontTTF, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(0, curTop, 50, LINE_HEIGHT));

    page.Graphics.DrawString("AA", SmallerFontTTF, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(60, curTop, 20, LINE_HEIGHT), FormatCenter);

    page.Graphics.DrawString(0.ToString("N2") + " h", SmallerFontTTF, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(PageInnerWidth - 110, curTop, 40, LINE_HEIGHT), FormatRight);

    page.Graphics.DrawString(0.ToString("N2"), SmallerFontTTF, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(PageInnerWidth - 60, curTop, 60, LINE_HEIGHT), FormatRight);

    var taskDesc = new PdfHTMLTextElement(data, SmallerFontTTF, PdfBrushes.Black);

    var taskDescResult = taskDesc.Draw(page, new Syncfusion.Drawing.PointF(90, curTop), PageInnerWidth - 240, Format);

    if (page != taskDescResult.Page)

    {

        if (taskDescResult is PdfTextLayoutResult textLayoutResult)

        {

            page = taskDescResult.Page;

            curTop = textLayoutResult.LastLineBounds.Bottom + (LINE_HEIGHT / 2);

        }

    }

    else

    {

        curTop = taskDescResult.Bounds.Bottom + (LINE_HEIGHT / 2);

        if (curTop + (LINE_HEIGHT * .8) > page.GetClientSize().Height)

        {

            page = doc.Pages.Add();

            curTop = 0;

        }

    }

}

MemoryStream stream = new MemoryStream();

doc.Save(stream);

doc.Close();

return stream.ToArray();

NuGet  : NuGet Gallery | Syncfusion.Pdf.Net.Core 28.1.39


Regards,

Jeyalakshmi T



JA Jacques January 20, 2025 01:43 PM UTC

Hi,

My bad. I indeed missed curTop changes in the sample. After doing the modification, it works fine. Sorry for the confusion.

Best Regards

Jacques



Loader.
Up arrow icon