2012-11-02 30 views
3

我有以下功能使用PdfSharp创建网络链接:为什么PdfSharp围绕Web链接创建边框?

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 
    } 

当生成PDF,福昕阅读器查看时,一切都很好:

Foxit Image

但是,Adobe Acrobat Reader软件图10和图11显示了链接区域周围的黑色薄边框:

Acrobat http://dl.dropbox.com/u/6753359/acrobat-bad.PNG

不幸的是,由于Acrobat Reader更标准,所以它必须看起来正确。

有人能告诉我为什么我所有的链接区域都在acrobat reader中获取边框吗?


编辑:我试图让注释双方 annotation.Opacity = 0annotation.Color = XColor.FromArgb(255, 255, 255, 255);无形。前者没有工作(边框仍然出现),后者将边框变成白色,但不能100%工作,因为它会在一些文本行中造成奇怪的现象(例如切断y,p等底部的白线。 )。

回答

5

这是一个已知的问题。

该溶液可以在这里找到: http://forum.pdfsharp.net/viewtopic.php?p=6161#p6161

框架是在PDFsharp的错误。这是10.0.3以前的Adobe Reader中的一个错误,不能显示框架。

+0

看起来我需要为自己编译PdfSharp和Migradoc来解决这个问题(因为我的项目混合了这两者)。谢谢,我试过搜索但找不到那篇文章。 – KallDrexx

2

我解决了这个问题:

1)从CodePlex

2.下载PDFSharp的最新版本)修改PdfLinkAnnotations.cs线120 new PdfLiteral("<</Type/Border>>");new PdfLiteral("<</Type/Border/W 0>>");

3)编制项目PDFSharp

4)改变你的项目,该项目使用PDFSharp使用新编译的.dll。

希望这个简单的全包解释帮助别人。