diff --git a/Source/HtmlRenderer.PdfSharp/PdfGenerator.cs b/Source/HtmlRenderer.PdfSharp/PdfGenerator.cs index 365be2d95..0f15c5a7a 100644 --- a/Source/HtmlRenderer.PdfSharp/PdfGenerator.cs +++ b/Source/HtmlRenderer.PdfSharp/PdfGenerator.cs @@ -218,6 +218,11 @@ private static void HandleLinks(PdfDocument document, HtmlContainer container, X { // document links to the same page as the link is not allowed int anchorPageIdx = (int)(anchorRect.Value.Top / pageSize.Height); + + // in case that not find the page index, set to the first page. + if (anchorPageIdx == 0) + anchorPageIdx = 1; + if (i != anchorPageIdx) document.Pages[i].AddDocumentLink(new PdfRectangle(xRect), anchorPageIdx); } @@ -233,4 +238,4 @@ private static void HandleLinks(PdfDocument document, HtmlContainer container, X #endregion } -} \ No newline at end of file +}