- Home
- Forum
- ASP.NET Core - EJ 2
- Branched from~ 188409 ~Preservation issue occurs while drawing the PDF Grid with a page break
Branched from~ 188409 ~Preservation issue occurs while drawing the PDF Grid with a page break
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
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.
Great. Thanks for the confirmation. Looking forward for the fix.
Hi Jacques,
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
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:
You should be able to reproduce this using the sample I provided.
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
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
- 8 Replies
- 4 Participants
-
JA Jacques
- Dec 17, 2024 12:10 PM UTC
- Jan 20, 2025 01:43 PM UTC