PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

PdfSharp AddDocumentLink not being placed where expected
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2491
Page 1 of 1

Author:  Oodin [ Tue Jun 25, 2013 6:49 pm ]
Post subject:  PdfSharp AddDocumentLink not being placed where expected

I am trying to build a TOC using PdfSharp and while I can add the elements where I would like them, I can't get the document links to line up with the TOC elements like I expect they should. See the following code for an example:
Code:
PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();

XGraphics gfx = XGraphics.FromPdfPage(page);
XRect rect = new XRect(5, 5, 500, 20);
PdfRectangle prect = new PdfRectangle(rect);

page.AddDocumentLink(prect, 1);
gfx.DrawRectangle(XBrushes.Transparent, rect);

doc.Save(@"C:\test.pdf");


With the code above I would place the text of my TOC element inside 'rect' and then clicking on that rectangle should link to the page of the document. However, the AddDocumentLink method is not placing that link at the same place on the page as the DrawRectangle is. It's placing it at the bottom. You can see the attached example document to see what is happening.

Thank you for any help with this,

Jon

Attachments:
test.zip [978 Bytes]
Downloaded 644 times

Author:  Thomas Hoevel [ Wed Jun 26, 2013 8:21 am ]
Post subject:  Re: PdfSharp AddDocumentLink not being placed where expected

The MigraDoc renderer includes the following line:
Code:
XRect rect = this.gfx.Transformer.WorldToDefaultPage(this.hyperlinkRect);

Author:  Oodin [ Wed Jun 26, 2013 1:54 pm ]
Post subject:  Re: PdfSharp AddDocumentLink not being placed where expected

That did the trick, thank you.

Code:
PdfRectangle prect = new PdfRectangle(gfx.Transformer.WorldToDefaultPage(rect));

page.AddDocumentLink(prect, 1);

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/