Incorrect behavior on line breaks with PdfHtmlTextElement

When using PdfHtmlTextElement, if the text doesn't fit the row, it breaks to next line. That's fine. If the last space at the break fits on the first row, the second row starts with the text and it's aligned properly. But if the space doesn't fit the first row, the space is inserted at beginning of next line causing a visual glitch. Here is a screenshot of such a problem. You see on second line that there's a space before "labore". I've added 2x t and a comma to fill the first row and make sure the space doesn't fit. It's then quite easy to reproduce.

Image_4876_1734296100338


13 Replies

IJ Irfana Jaffer Sadhik Syncfusion Team December 16, 2024 01:43 PM UTC

Hi Jacques,


We were unable to reproduce the reported behavior. Please share with us the replication sample to reproduce the code with us. We have used the below Html string to reproduce the issue.So that we can assist with you further in this.

// Create a new PDF document

        using (PdfDocument document = new PdfDocument())

        {

            // Add a page

            PdfPage page = document.Pages.Add();


            // Define a font

            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);


           // Define a long text with a deliberate layout issue

            string htmlContent = @"<font color='#0000F8' face='TimesRoman' size='14'>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt uttt,

labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco

laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in

voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat

non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

</font>";


            // Create a PdfHtmlTextElement

            PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(htmlContent, font, PdfBrushes.Black);


            //Format layout

            PdfLayoutFormat format = new PdfLayoutFormat();

            format.Layout = PdfLayoutType.Paginate;

            format.Break = PdfLayoutBreakType.FitPage;

            //Draw htmlString.

            richTextElement.Draw(page, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height), format);


            // Save the document to a file

            string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "Output.pdf");

            MemoryStream stream = new MemoryStream();

            document.Save(stream);

            File.WriteAllBytes(outputPath, stream.ToArray());

            Console.WriteLine($"PDF saved to {outputPath}");


Regards,

Irfana J.



JA Jacques December 16, 2024 02:43 PM UTC

Hi,

The string depends on the font you use, the margin, etc. You have to play with the content to be sure the space doesn't fit the row. I just copied your code here and was able to reproduce the problem with the following text (see below the screenshot):

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididuntt, labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Image_9709_1734360144020


Regards
Jacques




IJ Irfana Jaffer Sadhik Syncfusion Team December 17, 2024 01:40 PM UTC

Hi Jacques,


Currently we are analyzing on the reported behavior with the provided details on our end and we will share the further details on December 19th, 2029.


Regards,

Irfana J.



IJ Irfana Jaffer Sadhik Syncfusion Team December 19, 2024 11:00 AM UTC

Hi Jacques,


We have confirmed the issue “Incorrect behavior on line breaks with PdfHtmlTextElement” as a defect in our product and we will include the fix in weekly release on 7th January, 2025.

Please use the below feedback link to track the status of the reported bug.

https://www.syncfusion.com/feedback/64157/incorrect-behavior-on-line-breaks-with-pdfhtmltextelement

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,

Irfana J



RA Rangarajan Ashokan Syncfusion Team January 6, 2025 05:35 PM UTC

Hi  Jacques,


We were unable to include the fix for the issue "Incorrect behavior on line breaks with PdfHtmlTextElement" as promised in this weekly release due to stability concerns. The fix will be included in the upcoming weekly release on January 15, 2025.

 

If you would like to verify the fix before the next release, we can provide you with a custom patch. Please let us know if you are interested.

 

We apologize for any inconvenience this may have caused and appreciate your understanding.


Regards,

Rangarajan.



JA Jacques January 7, 2025 07:41 AM UTC

Hi Rangarajan,


Thanks for the feedback. Glad to learn that the fix is on its way. I can wait for the next release, no worry.


Regards

Jacques



AG Alfonzo Glidden January 10, 2025 01:07 PM UTC

Thank you so much for the info.



KV Kirthika Vijayagiri Syncfusion Team January 13, 2025 07:27 AM UTC

Hi Jacques, Alfonzo

You are welcome. We will let you know once the fix is rolled out.

Regards,

Kirthika



RA Rangarajan Ashokan Syncfusion Team January 15, 2025 05:43 PM UTC

Hi  Jacques,


We apologize for the inconvenience caused. We have implemented a fix for the reported issue; however, we are encountering complexities in testing and stability concerns. The fix we made for the reported issue has resulted in a failure of an existing test case. We need to validate this failure and confirm the effectiveness of the fix. We assure you that the fix will be included in the upcoming weekly release on January 21, 2025.

 

If you would like to verify the fix before the next release, we can provide you with a custom patch. Please let us know if you are interested.


Regards,

Rangarajan.



JA Jacques January 15, 2025 07:06 PM UTC

Hi Rangarajan,

As the problem only occurs on few occasions, I can modify my text when needed to avoid it. So no worry to wait some days for the fix. Thanks for feedback.

Regards
Jacques



IJ Irfana Jaffer Sadhik Syncfusion Team January 22, 2025 06:11 AM UTC

Hi Jacques,


We have included the fix for the reported issue “Incorrect behavior on line breaks with PdfHtmlTextElement" in our weekly release (v28.1.41). Please use the below link to download our latest NuGet.

 

https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/28.1.41

 

Root cause:

The reported issue occurs while drawing the text with line break. When a line breaks and the next line starts with a space, it draws the space in the beginning. It is not handled properly to trim the space if the text starts with the space value.


Regards,

Irfana J



JA Jacques January 31, 2025 11:39 AM UTC

Hi Irfana,

Sorry for the delay. I was not able to have a look before. I just checked the fix and confirm it works fine. Thanks for the help.

Regards
Jacques



IJ Irfana Jaffer Sadhik Syncfusion Team February 4, 2025 04:32 AM UTC

Hi Jacques,


We are glad to know that your issue is resolved. Please reach out to us if you need any further assistance.



Regards,

Irfana J.



Loader.
Up arrow icon