Hello,
I have a scenario requiring multiple calls to HtmlToPdf.ConvertHtml(), each with different HtmlToPdfOptions for each call, in order to accomplish different margins on different pages of the PDF. These individual documents then get merged together into a single document.
One thing I'm having issues with is anchor links. If the link and target reside in the same original document (were part of the same ConvertHtml() call), the links work correctly. However, if the link and target resided in two different documents before the merge, the links do not work. They wind up looking like this: file:///HtmlToPdf.Options.BaseUrl/NotSet#TestId123
I have tried merging the documents together two different ways:
1. Making multiple ConvertHtml() calls passing the same document
2. Making multiple ConvertHtml() calls each with a new document, and then calling PdfDocument.Merge() and passing the HtmlToPdfResults.
I've tried setting the HtmlToPdfOptions.BaseUrl to something explicitly but that doesn't seem to help. For example, I've tried setting it to the base URL of our website, but it then just prepends
that URL before the anchor link like this:
http://www.google.com/#TestId123 -- which is never going to be a legit URL as I am just trying to link to another element in the same PDF,
not elsewhere on our website.
Below is a very simple, stripped down code sample I have tried that doesn't work. For reference, this is running EO.Pdf version 21.0.69.
Code: C#
var htmlToPdfResults = new List<HtmlToPdfResult>();
var pdfOptions = new HtmlToPdfOptions();
pdfOptions.NoLink = false;
var html1 = "<div><a href='#TestId123'>Click Me</a></div>";
var htmlToPdfResult1 = HtmlToPdf.ConvertHtml(html1, new PdfDocument(), pdfOptions);
htmlToPdfResults.Add(htmlToPdfResult1);
var html2 = "<div id='TestId123' name='TestId123'>Hello World</div>";
var htmlToPdfResult2 = HtmlToPdf.ConvertHtml(html2, new PdfDocument(), pdfOptions);
htmlToPdfResults.Add(htmlToPdfResult2);
var doc = PdfDocument.Merge(true, htmlToPdfResults.ToArray());
What am I missing? Thanks in advance for your assistance.