Welcome Guest Search | Active Topics | Sign In | Register

HTML Anchors Options
RobD
Posted: Tuesday, April 25, 2017 9:58:31 AM
Rank: Newbie
Groups: Member

Joined: 4/25/2017
Posts: 3
If I have a simple anchor pair in my original HTML page, EOPdf will correctly convert this into an internal PDF link when I create a PDF based on the HTML.

My question is, can I create similar links after the PDF had been created? I'd like to create a basic navigation which will link to specific pages in the report, but I need to insert this navigation after the PDF has been created.

So, if I have an anchor in the original HTML (<a name="my-anchor"></a>), I want to insert a link to this anchor into the generated PDF (<a href="#my-anchor">My anchor</a>). This doesn't seem to work, as it appears both the anchor and the link need to be present in the original HTML before a PDF link is created.

Is there anyway to do what I want?
eo_support
Posted: Tuesday, April 25, 2017 10:09:33 AM
Rank: Administration
Groups: Administration

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

No. There is no way to do that. You must have them both in the original HTML file.

PDF file has no notion of named anchor. So once you convert the HTML into a PDF file, the target anchor element that was in your HTML file is lost --- it no longer exists in the PDF file. As such it is not possible to add another anchor to point to this non-existing anchor.

Thanks!
RobD
Posted: Tuesday, April 25, 2017 10:11:39 AM
Rank: Newbie
Groups: Member

Joined: 4/25/2017
Posts: 3
Thanks for your reply. Is it possible to do something similar with PDF bookmarks? Can I insert a bookmark and then create a link to it?
eo_support
Posted: Tuesday, April 25, 2017 10:29:57 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Yes. You can do that. The missing information in your original case is the location of the target anchor. A PdfBookmark has a Destionation property that points to the target location, so this provides exactly what you need.

Here is the steps involved in order to do it using the bookmark (assuming that you have already created the bookmark object):

1. Run the HTML to PDF converter, which would return a HtmlToPdfResult object;
2. Call one of the HtmlToPdfResult.HtmlDocument.GetElementByXXXX method to get the HtmlElement object that represents the source link object (this is where you would click);
3. Call HtmlElement.CreateLink to create a PdfLink object. A PdfLink object manages two pieces of information: The source rectangle (where you click) and the target location (where it goes when you click). This step fills the source rectangle information for the PdfLink object;
4. Set PdfLink.Destination to PdfBookmark.Destination. This step fills in the target location information;
5. Call PdfLink.Render to actually render the link into the PDF file;

As you can see, the key is the PdfBookmark.Destination which provides the target location. You can also construct a PdfDestination object yourself without relying on PdfBookmark object, assuming that you already have all the information you need (page index, and x, y position). You can get these information from the HtmlToPdfResult object returned by the original conversion (first get HtmlElement and then use HtmlElement.Location.CreateDestination method).

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
RobD
Posted: Tuesday, April 25, 2017 11:45:10 AM
Rank: Newbie
Groups: Member

Joined: 4/25/2017
Posts: 3
Thanks, this is working for me, good solution!
eo_support
Posted: Tuesday, April 25, 2017 11:48:57 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Glad to hear that. Please feel free to let us know if you have any more questions.


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.