Html anchor not working in html to pdf

We are currently trying out aspose html to pdf (using aspose.pdf version 25.3.0). We are running into the following problem. We have html with anchors like this:

<!DOCTYPE html>
<html>
  <head>
    <style>
      div.pageBreak {
        page-break-before: always;
      }
    </style>
  </head>
  <body>
    <a href="#page2" target="_self"> Show details </a>
    <div class="pageBreak"></div>
    <div class="pageBreak"></div>
    <div class="pageBreak"></div>
    <div class="pageBreak"></div>
    <div id="page2" name="page2">Hellow world</div>
  </body>
</html>

When converting this html to pdf using the following code:

        var asposeOptions = new Aspose.Pdf.HtmlLoadOptions();
        byte[] bytes = Encoding.ASCII.GetBytes(html);
        var outputStream = new MemoryStream();
        using (var document = new Document(new MemoryStream(bytes), asposeOptions))
        {
            // Save PDF document
            document.Save(outputStream);
        }
        return outputStream.ToArray();

The result pdf document does not have a working anchor. Is there any way to solve this? We have found this issue (from a while ago): Add HTML string in PDF using Aspose.PDF for .NET - Anchor tag is not working in PDF output

Where this is said to be fixed, but we might be missing something here?

@MichielB

It seems that you are experiencing issues with HTML anchors not functioning correctly when converting HTML to PDF using Aspose. The code you provided appears to be set up correctly for the conversion process, but there are a few considerations to keep in mind regarding anchor tags in the generated PDF.

  1. Anchor Tag Support: Ensure that the version of Aspose.PDF you are using supports anchor tags in the HTML to PDF conversion. There have been updates in the library that may have addressed this issue, so it’s worth checking if you are using the latest version.

  2. HTML Structure: The structure of your HTML looks fine, but sometimes additional CSS or JavaScript can affect how anchors are processed. Make sure that there are no conflicting styles or scripts that might interfere with the anchor functionality.

  3. Testing with Simple HTML: To isolate the issue, try testing with a simpler HTML structure that only includes the anchor and the target element. This can help determine if the problem lies within the complexity of your current HTML.

  4. Using Load Options: You might want to explore the HtmlLoadOptions further. For instance, setting specific options related to resource loading or rendering might help in resolving the issue.

Here’s a simplified example of how you might set up your conversion:

using System.IO;
using Aspose.Pdf;

public class HtmlToPdfExample
{
    public static void ConvertHtmlToPdf(string html)
    {
        var options = new HtmlLoadOptions();
        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(html);
        using (var document = new Document(new MemoryStream(bytes), options))
        {
            document.Save("output.pdf");
        }
    }
}

If the issue persists, I recommend checking the Aspose forums for similar discussions or updates regarding anchor tag support in HTML to PDF conversion. You may find relevant threads that provide additional insights or solutions.

If you have already checked the forum post you mentioned and it indicates that the issue was fixed, ensure that you are using the version of Aspose.PDF that includes that fix.

For further assistance, consider providing a minimal reproducible example on the forum, as this can help the community or support team to diagnose the issue more effectively.

If you have any more questions or need further clarification, feel free to ask!

Ive tried replacing the page-breaks with
but this didnt change a thing. Ive also added a trial license to see if it had anything to do with the evaluation license, but this wasnt the case either. Ive tried/reviewed all the bot suggestions but it did not resolve my issue.

@MichielB

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-59567

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.