Add HTML string inside PDF using Aspose.PDF - Symbol not wrapping correctly with the preceding word

Hi,

I was wondering if someone could advice me on how i could ensure that when an emdash (—) is always on the same line as the preceding word?

The text is first added into an HTMLFragment then added to a paragraph

example:
image.png (72.7 KB)

If anymore information is required please do not hesitate to ask.

@cbparl

Could you please share your sample HTML string with us along with sample code snippet that you are using to generate PDF document. We will test the scenario in our environment and address it accordingly.

@asad.ali

Here is the html snippet:

"<b>4. </b><div style='margin-top:-20px;margin-left:35px; width: 580px'><b>Section 22 report:</b>&nbsp;&nbsp;The Committee will take evidence on the Auditor General for Scotland's report&nbsp;entitled Scotland's Finance Future from&mdash;<br><br> <span style ='margin-left: 1px; text-align:left;'> Test Lovatt,   Director,  </span> Flock Health Limited;<br/><br/> <span style ='margin-left: 1px; text-align:left;'>Chief Superintendent Test Flynn,   Chief Superintendent,  </span> Scottish SPCA.<br/><br/><br><br><br><br></div>"

here is what it looks like on the page:

image.png (22.2 KB)

let me know if you need any further information

ps sorry it wouldnt let me paste the actually html without it formatting

image.png (8.6 KB)

@cbparl

We have tested the scenario using following code snippet and Aspose.PDF for .NET 21.1. We did not notice any issue. Please check attached source and output PDF for your reference:

Document myDocument = new Document();
Page page = myDocument.Pages.Add();

HtmlFragment html = new HtmlFragment(File.ReadAllText(dataDir + "PercedingLine.html"));
page.Paragraphs.Add(html);
myDocument.Save(dataDir + "htmlFragment.pdf");

PercedingLine.zip (469 Bytes)
htmlFragment.pdf (72.1 KB)

Would you please make sure to use the latest version of the API and let us know if you still face any issue.

@asad.ali

Sorry i did not include this information. Here is the margins that we add to the pages that might be causing this issue.

        var document = new Document
        {
            PageInfo = new PageInfo { Margin = new MarginInfo(45, 28, 45, 60) }
        };

The font size is 12 and the style is Arial

let me know if you need more information

@cbparl

Using the margins and font specifications, we were still unable to notice the issue:

Document myDocument = new Document();
Page page = myDocument.Pages.Add();
page.PageInfo.Margin = new MarginInfo(45, 28, 45, 60);
HtmlFragment html = new HtmlFragment(File.ReadAllText(dataDir + "PercedingLine.html"));
html.TextState = new TextState() { Font = FontRepository.FindFont("Arial Unicode MS"), FontSize = 12 };
page.Paragraphs.Add(html);
myDocument.Save(dataDir + "htmlFragment.pdf");

htmlFragment.pdf (83.3 KB)

Please try to share a sample console application which is able to reproduce the issue so that we can try to replicate it and address it accordingly.

hi @asad.ali

here is a console application that has the issue above:

The project does not include the license for aspose as im assuming that should not be shared.

If you have any issues please do not hesitate to ask.

@cbparl

@cbparl

The archive includes only executables. It does not have a complete Visual Studio project with code files. Please try to share a sample Visual Studio project which we can run at our end and observe the issue.

@asad.ali

A sample Visual Studio project has been added to the folder.

Looking forward to hearing from you

@cbparl

We have tested the scenario in our environment and found that the issue was due to a larger font size i.e. 14. This can be prevented by either reducing the margins or the font size. You can also put a <br> tag before the word “from” which will cause it to break to the next line along with the symbol:

testingDocument.pdf (77.6 KB)

Due to accessibility guidelines we are restricted to use these sizes for our font and margins when producing documents. If we were allowed to change the font or margins this would resolve this instance of the issue but would not stop it from happening again.

Adding the br tag before the “from” would resolve this scenario however when building our pdfs not all emdashes end against the margin and we have no way of identifying when a emdash is going to hit the margin.

I have tried wrapping the “from” and emdash in a span and adding the style white-space and this works in a html editor but does not seem to be supported by aspose

(Sorry for the image i dont know how to add html code without it formatting)

image.png (10.7 KB)

Is there any other suggestions that you could provide that would resolve this issue?

edit: Ive updated the project to convey this issue

@cbparl

Thanks for sharing your feedback.

We have logged an investigation ticket as PDFNET-49343 in our issue tracking system for the sake of your requirements. We will look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali

Is there any update for this ticket ?

@cbparl

We are afraid that the ticket is not yet investigated. Please note that it was logged recently under normal support model and will be investigated/fixed on a first come first serve basis. We will surely update you as soon as we have some definite updates regarding its resolution. Please give us some time.

We are sorry for the inconvenience.

@asad.ali

Is there a possibility to give an estimate on when this could be fix?

I understand that there will be other issues in front of this issue .

@cbparl

The issue has been scheduled for an investigation and as soon as it is fully investigated, we will be in a position to share some ETA regarding its fix. We will surely inform you once it is completely analyzed. Please be patient and give us some time.

We apologize for the inconvenience.

@cbparl

We have made an investigation against the logged ticket and found that you can use &NoBreak keyword in the HTML which will be supported by Aspose.PDF. Please try to use the template like the attached HTML and let us know in case you need further assistance.

49343.zip (488 Bytes)