【问题标题】:How do I add a link to a file in PdfSharp?如何在 PdfSharp 中添加指向文件的链接?
【发布时间】:2009-03-02 22:05:44
【问题描述】:

我似乎无法让 PdfSharp 显示此注释的图片。它没有 PdfAnnotation.Icon 属性,所以我不能设置它。

XFont font = new XFont("Verdana", 10);
PdfPage page = wDoc.Parent.Page;
XGraphics gfx = wDoc.Parent.gfx;
XRect rec = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 60), new XSize(30, 30)));
PdfRectangle rect = new PdfRectangle(rec);
PdfLinkAnnotation link = PdfLinkAnnotation.CreateFileLink(rect, wDoc.FileLocation);
gfx.DrawString("These files were attached:", font, XBrushes.Black, 30, 50, XStringFormat.Default);

link.Rectangle = new PdfRectangle(rec);
page.Annotations.Add(link);

我已经做到了,并且注释确实存在,只是它是一个空白框!我该如何让它说话,甚至只是显示一张图片?

【问题讨论】:

    标签: c# .net pdfsharp


    【解决方案1】:

    你需要使用page.AddWebLink(AREArect),然后用gfx.drawstring(AREArect)添加文本区域

    【讨论】:

      【解决方案2】:

      Uri 用法示例代码:

      ...
      PdfDocument pdfDoc = PdfReader.Open(myUri.LocalPath, PdfDocumentOpenMode.Import);
      PdfDocument pdfNewDoc = new PdfDocument();
      for (int i = 0; i < pdfDoc.Pages.Count; i++)
      {
         PdfPage page = pdfNewDoc.AddPage(pdfDoc.Pages[i]);
         XFont fontNormal = new XFont("Calibri", 10, XFontStyle.Regular);    
         XGraphics gfx = XGraphics.FromPdfPage(page);
         var xrect = new XRect(240, 395, 300, 20);
         var rect = gfx.Transformer.WorldToDefaultPage(xrect);
         var pdfrect = new PdfRectangle(rect);
      
         //file link
         page.AddFileLink(pdfrect, myUri.LocalPath);
         //web link
         //page.AddWebLink(pdfrect, myUri.AbsoluteUri);
      
      
         gfx.DrawString("MyFileName", fontNormal, XBrushes.Black, xrect, XStringFormats.TopLeft);
      }
      pdfNewDoc.Save(myDestinationUri.LocalPath + "MyNewPdfFile.pdf");
      ...
      

      【讨论】:

        【解决方案3】:

        我不熟悉类 PdfLinkAnnotation。 您可以使用 page.AddDocumentLink、page.AddWebLink 和 page.AddFileLink 来创建链接。 如果您使用这些方法,您可以将图标绘制为图像。

        【讨论】:

          猜你喜欢
          • 2013-12-26
          • 2020-12-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多