I have the following function to create a weblink using PdfSharp:
public static void AddWebLink(XGraphics gfx, PdfPage page, XFont font, string url, string text, int startX, int startY)
{
if (gfx == null)
throw new ArgumentNullException("gfx");
if (page == null)
throw new ArgumentNullException("page");
if (font == null)
throw new ArgumentNullException("font");
// Write out the text
gfx.DrawString(text, font, XBrushes.Blue, new PointF(startX, startY));
var stringSize = gfx.MeasureString(text, font);
// Create the linked area
// For some reason the Y of the rectangle needs to be startY minus the height
startY -= (int)stringSize.Height;
var rect = gfx.Transformer.WorldToDefaultPage(new XRect(startX, startY, stringSize.Width, stringSize.Height));
var pdfRect = new PdfRectangle(rect);
var annotation = page.AddWebLink(pdfRect, url);
annotation.Opacity = 0; // Try and prevent it from rendering a box around the link in some viewers
}
When the PDF is generated, everything is fine when viewed in Foxit Reader:
However, Adobe Acrobat Reader 10 and 11 shows a black-thin border around the linked area:
Acrobat http://dl.dropbox.com/u/6753359/acrobat-bad.PNG
Unfortunately, since Acrobat Reader is more standard it's a requirement that it must look right in it.
Can someone clue me in as to why all of my link areas are getting borders in them in acrobat reader?
annotation.Opacity = 0
and annotation.Color = XColor.FromArgb(255, 255, 255, 255);
. The former did not work (border still appeared), the latter made the border white which doesn't 100% work because it creates oddities in some lines of text (like a white line cutting off the bottom of y's, p's, etc...).
It's a known problem.
The solution can be found here: http://forum.pdfsharp.net/viewtopic.php?p=6161#p6161
The frame is a bug in PDFsharp. It's a bug in Adobe Reader up to 10.0.3 not to display the frame.
Update: The bug was fixed a long time ago and links created with recent versions will not have frames around them.
I resolved this issue by:
1.) Downloading the latest release of PDFSharp from CodePlex
2.) Modifying the PdfLinkAnnotations.cs line 120 from new PdfLiteral("<</Type/Border>>");
to new PdfLiteral("<</Type/Border/W 0>>");
.
3.) Compiling PDFSharp project
4.) Change your project that uses PDFSharp to use the freshly compiled .dll.
Hope this simple all inclusive explanation helps others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With