PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 6:34 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri May 10, 2019 6:12 pm 
Offline

Joined: Fri May 10, 2019 6:00 pm
Posts: 1
Hi all,

I am attempting to create a WebLink that overlays drawn text. I am using the same XRect when drawing the text and adding the web link. An example of my current code is:

Code:
        PdfDocument document = new PdfDocument();
        PdfPage page = document.Pages.Add();
        XFont font = new XFont("Arial Unicode MS", 10, XFontStyle.Regular);
        string text = "Hello World";

        XGraphics gfx = XGraphics.FromPdfPage(page);
        XSize textSize = gfx.MeasureString(text, font);
        XPoint textLocation = new XPoint(50, 50);
        XRect textRectangle = new XRect(textLocation, textSize);
        gfx.DrawString(text, font, XBrushes.Black, textRectangle, XStringFormats.TopLeft);

        page.AddWebLink(new PdfRectangle(textRectangle), "http://www.google.com");


However, the above code creates the text in the top left corner and the annotation in the bottom left. In order to get the two elements to line up I need to invert the annotation's Y position like so:

Code:
        XPoint invertedYPoint = new XPoint(textLocation.X, page.Height - textLocation.Y - textSize.Height);
        page.AddWebLink(new PdfRectangle(invertedYPoint, textSize), "http://www.google.com");


Is this intended behavior, or perhaps there are orientation settings I need to add/change?

Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Sun May 12, 2019 12:58 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
The function call you need is
Code:
XRect rect = this.gfx.Transformer.WorldToDefaultPage(this.hyperlinkRect);
[/quote]


See also:
viewtopic.php?p=3805#p3805

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 122 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