Welcome Guest Search | Active Topics | Sign In | Register

<base href and HtmlToPdfOptions.BaseUrl and <a> links within the document Options
Aaron
Posted: Monday, December 10, 2018 6:27:27 AM
Rank: Advanced Member
Groups: Member

Joined: 12/13/2017
Posts: 29
Hi,

This may be helpful to others.

Our html document is being generated in a website then we send it to a web api to be rendered as a pdf. As such we set the html's <base href to be the website's url.

e.g. <base href="http://localhost:5100/" />


The html renders properly.
The pdf renders properly (sort of)

... BUT, the <a href="#mylocalId" > links aren't correct.

While debugging, you can see that the HtmlElement.Href is now prefixed with the base href url and the TargetElement is null.


BUT ... by pulling out the <base href from the html and programmatically setting the HtmlToPdfOptions.BaseUrl to this value corrects this issue and the HtmlElement.Href is no longer prefixed and the HtmlElement.TargetElement is no longer null and references the correct location within the document.


It just feels a bit hacky that I have to set this value in code to match what is already in the html.

I hope this helps someone in the future.
eo_support
Posted: Monday, December 10, 2018 1:37:06 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Thanks for bring this issue to our attention. I agree with you that ideally the library should be able to pull the base Url automatically in this case. Currently the library always derive the baseUrl from the document Url when HtmlToPdf.Options.BaseUrl is not set and it does not check the base element in the HTML file. We will look into this and see if we can add this case as well.
eo_support
Posted: Monday, February 18, 2019 11:30:30 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi,

This is just to let you know that we have posted build 2019.0.56 that should resolve this issue. You can download the new build from our download page. Please take a look and let us know how it goes.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.