Using custom fonts with HtmlFragment

@thegordon

Thanks for contacting support.

We have recorded your concerns and will definitely consider them while investigating the issue. We will let you know as soon as additional updates are available regarding issue fix. Please spare us little time.

We are sorry for the inconvenience.

Thanks.

If it helps, my investigation seems to show that the TextState property of the HtmlFragment does behave differently than, say, TextFragment.

For example:

  • Direct assignment of the “.TextState” results in an object instance error - this is not the case with TextFragment where direct assignment of values is valid.
  • With HTMLFragment, you must first instantiate an instance of the TextState class, populate it’s parameters, then assign this instance to the TextState of the HTMLFragment object.
  • The “.fontSize” attribute also behaves differently. A font size of 8 in TextFragment appears is equivalent to a font size of 2 in HTMLFragment
  • The “.foregroundcolor” attribute does not appear to work at all. All text is still rendered as black regardless of RGB equivalent used.
  • And of course, the above font assignment only accepts FontRepository.FindFont of standard core fonts, not FontRepository.OpenFont for OT font files.

I am aware that issues are addressed on a case by case basis, but this is an important requirement and appears to be a bug and runs counter to the product claim of support for OT fonts, regardless of method used. Also It’s now December and this was logged by David in August.

I have found it necessary to work around the issues of support for OT fonts for some time now by literally disassembling the HTML into text fragments - an error prone process that shouldn’t be necessary. (I first raised issue with Aspose.PDF OT font support late 2016 and it appears that this is still an ongoing problem. PS: I am using version 18.12.0.0.)

Your prompt assistance is appreciated.

Cheers,
Brad

@thegordon

Thanks for providing these details. This information would definitely be helpful during investigation process. As soon as some significant progress is made towards issue resolution, we will let you know.

Could you please share the issue ID or Thread URL where you had reported similar issue so that we link that with this thread as well and proceed accordingly.

The earliest post I could find was this one; it being a thread I created after giving up on using HTML import, then beginning the process of disassembling HTML into TexrFragments. I do not know the previous ID as it’s not on my list… Open Type font embedding problem

@thegordon

Thanks for providing further details.

We have checked the thread shared by you and observed that some of findings against previous investigation were shared there. However, in case you still have different concerns in that reference, please share with us. We will continue the investigation process where it was left.

Any further progress on this one?

@thegordon

I regret to share that there is no significant updates are available regarding issues resolution due to large number of pending issues in the queue. Please note that the issues were logged under free support model thus, have low priority and will be investigated/resolved on first come first serve basis. We will surely let you know as soon as some significant progress is made towards issues rectification. Please spare us little time.

We are sorry for the inconvenience.

This issue was logged originally in August - I’m a bit concerned about a commercial product being fit for purpose or use if there are so many issues that an obvious bug cannot be addressed within 5 months regardless of how it was logged. I will discuss our refund options with our local AU reseller - this ongoing issue with OT font support has been a constant annoyance so we will be looking at alternative solutions going forwards.

@thegordon Good luck getting this resolved mate! We never ended up completing our requirement but fortunately it was low priority for us. I agree with you though that this probably shouldn’t be taking 5 months. Best of luck to you.

@asad.ali Is there any reason that this post has been set to private? I think it would be useful for anyone having similar issues to know that this is an actual bug within the product, that it has already been reported, and is being worked on.

Cheers,
David

@thegordon

We really apologize for the inconvenience and delay in resolution of the issue. Please note that we do value your concerns and for that we have raised the priority of the issue to escalate things. We will definitely take your issue in account for attention and as soon as we have some investigation results and news for ETA, we will share with you. Please spare us little time

@davidpbtran

We have made this thread public and yes, the investigation of earlier logged issue is under process and we will be sharing updates within this thread for the issue resolution as soon as we have some.

We are sorry for the inconvenience caused.

The issues you have found earlier (filed as PDFNET-45225) have been fixed in Aspose.PDF for .NET 19.3.

Hello, i’ve download your examples from github (GitHub - aspose-pdf/Aspose.PDF-for-.NET: Aspose.PDF for .NET examples, plugins and showcase projects) and seems that this bug is still not fixed in version Aspose.PDF 19.6.0.

I’ve edited the SetHTMLStringFormatting example as below:

            var html = new HtmlFragment("HTML")
            {
                TextState = new TextState
                {
                    Font = FontRepository.OpenFont(@"C:\OpenSans-Regular.ttf"),
                    ForegroundColor = Color.Red,
                    BackgroundColor = Color.Blue,
                    FontStyle = FontStyles.Bold,
                    FontSize = 20
                }
            };

            var text = new TextFragment("TEXT")
            {
                TextState =
                {
                    Font = FontRepository.OpenFont(@"C:\OpenSans-Regular.ttf"),
                    ForegroundColor = Color.Red,
                    BackgroundColor = Color.Blue,
                    FontStyle = FontStyles.Bold,
                    FontSize = 20
                }
            };

            var doc = new Document();
            var page = doc.Pages.Add();
            page.Paragraphs.Add(html);
            page.Paragraphs.Add(text);

            doc.Save(@"C:\test.pdf");

The result is:

test.pdf (87.6 KB)

Any suggestion?

@boardlab

It seems like this is a regression as the issue was resolved in 19.3 version of the API and is still occurring in 19.6. We have created a new regression issue as PDFNET-46643 in our issue tracking system for the sake of correction. We will surely look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

@boardlab

We have tested the scenario with Aspose.PDF for .NET 19.9 and could not reproduce this issue. Would you please try with latest version and let us know in case you still face any issue.

Still present

@boardlab

Would you please share your complete environment details i.e. OS Name and Version and Application type in which you are working. We will further proceed to assist you accordingly.

Hello asad.ali,

with the Aspose.PDF for .NET 19.9 the custom font works, but the foreground and the background colors still no working.
For our purposess it’s enough, but could you tell us if it’s a know limitation? In order to know how to manage future developments.

Thank you!

In attachment you can see the updated generated file:
test.pdf (48.3 KB)

@boardlab

There is no such limitation in the API. We have also observed this behavior in our environment and logged an issue as PDFNET-47054 in our issue tracking system. We will further check this in details and keep you posted with its rectification status. Please spare us little time.

We are sorry for the inconvenience.

Hi, I have a problem with the font. I can’t find a way to change the color. If someone tells me, I will be grateful.

@DaniStone

Could you please share your sample font file along with the sample code snippet that you are using. We will test the scenario in our environment and address it accordingly.