From 36afa548cf6622cfdd6f08c1842bde2b77f47c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Guti=C3=A9rrez=20Vera?= Date: Tue, 29 Jan 2019 11:13:44 +0100 Subject: [PATCH] Update PdfGenerator.cs With one embeded image make an error because anchorPageidx = 0 and it isn't a valid page. --- Source/HtmlRenderer.PdfSharp/PdfGenerator.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 +}