PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Apr 18, 2024 8:55 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Wed Jun 24, 2009 3:00 pm 
Offline

Joined: Wed Jun 24, 2009 2:53 pm
Posts: 3
I am having some trouble adding a clickable text that would open a browser to a certain page. For example, if I do this:

gfx.DrawString("http://www.yahoo.com/", font, XBrushes.Red, new System.Drawing.PointF(15, 62));

It works, but what I want is to have a text that reads "Click Here" or an image that when clicked in the PDF would take the user to the web browser.

I tried this:

XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
XSize size = gfx.MeasureString("Click Here", font);
XRect rect = new XRect(new XPoint(15, 10), size);
gfx.DrawString("Click Here", font, XBrushes.Black, new System.Drawing.PointF(15, 30));
PdfSharp.Pdf.Annotations.PdfLinkAnnotation pla = doc.Pages[0].AddWebLink(new PdfRectangle(rect), "http://www.yahoo.com");

I verified that the rect is in fact over the text (I made a box to make sure). But when I open the PDF in a viewer the link doesn't exist.

I also tried this:

paragraph.AddHyperlink("Click here", MigraDoc.DocumentObjectModel.HyperlinkType.Url);

But I don't know how to add the URL and also, the text doesn't even get rendered on the page...

Any ideas as to how I can add a hyperlink without actually displaying the entire link?

Thank you,

Iulian


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 25, 2009 11:22 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
The AddXxx functions in MigraDoc always return the newly created objects for further modification.

Code:
Hyperlink hyperlink = paragraph.AddHyperlink("http://www.qualitaetsberichte.net/", HyperlinkType.Url);
FormattedText ftext = hyperlink.AddFormattedText("http://www.qualitaetsberichte.net/");


Your "Click here" would be given with AddFormattedText.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 25, 2009 1:48 pm 
Offline

Joined: Wed Jun 24, 2009 2:53 pm
Posts: 3
Thank you! It works!

But I have one more question: I add the proper URL (I verify in the debugger that the Name property of the link is indeed the URL that I need); but when the PDF gets generated the URL pointed is some kind of giberish. Here is an example:

The url I set:
http://www.mysite.com/vacation-rentals/ ... index.aspx

And this is the url pointed by the PDF:
http://localhost:8080/qìC\Sb zyü—ÍŒ¬V¤7ô큟dîhÀÝîžW2pl

(localhost:8080 is the server where I am testing the application). Do I have to do something else to pass the proper link address?

Thank you,

Iulian

Thomas Hoevel wrote:
The AddXxx functions in MigraDoc always return the newly created objects for further modification.

Code:
Hyperlink hyperlink = paragraph.AddHyperlink("http://www.qualitaetsberichte.net/", HyperlinkType.Url);
FormattedText ftext = hyperlink.AddFormattedText("http://www.qualitaetsberichte.net/");


Your "Click here" would be given with AddFormattedText.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 29, 2009 7:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
iulianionescu wrote:
Do I have to do something else to pass the proper link address?

Do you create password-protected PDF files?
The code works - but we only use unprotected PDF files. Maybe there's a bug with the security settings.

Does the URL contain characters that need escaping?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 29, 2009 7:45 pm 
Offline

Joined: Wed Jun 24, 2009 2:53 pm
Posts: 3
Thomas, you were correct: the securitySettings.OwnerPassword was the culprit. Once I removed the password the Urls are no longer garbled. This means that there is a bug somewhere that encrypts the Name value of the hyperlink as well and that's why it wasn't working...

Thank you!

Iulian


Thomas Hoevel wrote:
iulianionescu wrote:
Do I have to do something else to pass the proper link address?

Do you create password-protected PDF files?
The code works - but we only use unprotected PDF files. Maybe there's a bug with the security settings.

Does the URL contain characters that need escaping?


Top
 Profile  
Reply with quote  
PostPosted: Tue Dec 17, 2013 8:50 am 
Offline

Joined: Tue Dec 17, 2013 8:43 am
Posts: 1
Location: Brühl, NRW
It seems the bug already exists in 1.32.
Is there a workaround for using links in encrypted PDF?
Or can you tell me where i can fix that bug?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 14, 2014 7:39 pm 
Offline

Joined: Wed Jun 04, 2014 5:51 pm
Posts: 6
I am running into this as well - encrypting a PDF messes up any hyperlinks on it.
Other than leaving the doc unprotected, is there any way to remedy this... is there a bug fix in the works?


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 13, 2015 8:23 pm 
Offline

Joined: Sun Jan 25, 2015 3:37 am
Posts: 5
I have run into the same problem, and a few more regarding the password protection.
Here is the "workaround" I determined.
1. Save the file without setting any passwords or setting any other security items (e.g. noprint)
2. Reprocess the file changing only the security settings.
3. links are retained and not messed up. Passwords are intact.

BEWARE: the other bug I found was setting only a owner password. No good. You can set only a user password. You can set a owner and a user password. But not just a owner password. Here is the "workaround" I determined.
If there is only a owner password, set both the owner and user password to same value.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 49 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