How to add PDF page link when converting HTML to PDF?

Requirements

I need to convert some HTML pages to one PDF.
For example:

  • Page1 - Cover Page
  • Page2 - TOC Page
  • Page3 - ContentA Page
  • Page4 - ContentB Page
  • Page5…

The Page2 - TOC Page contains a Content Page List. For example:

<ul>
  <li>Page3 - ContentA Page</li>
  <li>Page4 - ContentB Page</li>
  <li>Page5 - ContentC Page</li>
</ul>

Question

How to add a page link to the ‘li’ elements so that I can jump to the content page in the final PDF? Or are there any other methods that can do the same thing?

Puppeteersharp Solution

I used puppeteer-sharp before because it will use Chromium to render the HTML during the conversion. So it can use something like <a href='#Page3-ContentA'> and z-index to implement this function. (Aspose also does not support the z-index property, it may be another feature request:sweat_smile:)

Asbose Possible Solution?

I know Asbose has the LocalHyperlink. Not sure whether can implement this by adding an invisible but still clickable LocalHyperlink(like CSS opacity + z-index combo) to my HTML wording(Page3 - ContentA Page) position. It is still very tricky because I need to hardcode the HTML element position in the C# code.

@diyuan

We are afraid that such feature is not supported in Aspose.PDF. However, if a hyperlink in HTML is present for some web URL, it will be converted accordingly in PDF. As far as local hyperlinks are concerned, you can only add them in the PDF once it is generated from the HTML.

You can search the specific text and then add local hyperlink around it. For your original requirements, we have logged a feature request as PDFNET-55260 in our issue management system to analyze the feasibility. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

1 Like