PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 16, 2024 8:19 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Aug 02, 2013 10:50 pm 
Offline

Joined: Fri Aug 02, 2013 2:02 am
Posts: 2
Using PdfSharp, I can create an intra-document link and make it clickable using the following code:

Code:
private void AddPageLink(PdfPage page, XGraphics gfx, XFont font, double x, double y, String text, int dest)
{
    //XRect link = new XRect(new PdfSharp.Drawing.XPoint(20, 50), new PdfSharp.Drawing.XPoint(200, 200));
    //PdfRectangle lin = new PdfRectangle(link);
    double lineSpace = font.GetHeight();
    int cellSpace = font.FontFamily.GetLineSpacing(font.Style);
    int cellAscent = font.FontFamily.GetCellAscent(font.Style);
    int cellDescent = font.FontFamily.GetCellDescent(font.Style);
    double cyAscent = lineSpace * cellAscent / cellSpace;

    XRect rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(x, y), gfx.MeasureString(text, font)));
    rect.Offset(0, cyAscent);
    page.AddDocumentLink(new PdfRectangle(rect), dest);
    gfx.DrawString(text, font, XBrushes.Blue, x, y, XStringFormats.Default);
}


When I open the resulting PDF file, I can click the links that I added and jump around within the same document.

How would I do the same with MigraDoc? I've searched and can't find the example that I am looking for.

Thanks in Advance,
Rick


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 05, 2013 8:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!
With MigraDoc you use AddHyperlink to add a link to a paragraph.
AddHyperlink returns a Hyperlink object that allows to add text or formatted text.

For intra-document links, use AddBookmark to add a marker (just a string) at the target. Specify the same string in your call to AddHyperlink.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 06, 2013 8:49 pm 
Offline

Joined: Fri Aug 02, 2013 2:02 am
Posts: 2
Got it working! Thanks for steering me in the correct direction.

Regards,
Rick


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 173 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group