首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

使用ITextSharp编辑PDF格式的超链接和锚点

关于使用ITextSharp编辑PDF格式的超链接和锚点,以下是完善且全面的答案:

  1. 超链接

超链接是指在PDF文档中,通过链接可以跳转到其他文档、网页或其他位置的功能。在ITextSharp中,可以使用PdfAction和PdfAnnotation来实现超链接。

以下是一个示例代码,演示如何在PDF文档中添加超链接:

代码语言:csharp
复制
using System;
using System.IO;
using iTextSharp.text.pdf;

namespace ITextSharpExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // 创建一个新的PDF文档
            Document document = new Document();
            PdfWriter.GetInstance(document, new FileStream("output.pdf", FileMode.Create));
            document.Open();

            // 添加一个超链接到其他PDF文档
            Chunk link = new Chunk("点击这里跳转到其他PDF文档");
            PdfAction action = PdfAction.GotoLocalPage(1, new PdfDestination(PdfDestination.FIT), document);
            link.Action = action;
            document.Add(link);

            // 添加一个超链接到网页
            link = new Chunk("点击这里跳转到网页");
            action = PdfAction.GotoEmbedded("http://www.example.com", false, false);
            link.Action = action;
            document.Add(link);

            // 关闭文档
            document.Close();
        }
    }
}
  1. 锚点

锚点是指在PDF文档中,通过链接可以跳转到文档中的指定位置的功能。在ITextSharp中,可以使用PdfDestination来实现锚点。

以下是一个示例代码,演示如何在PDF文档中添加锚点:

代码语言:csharp
复制

using System;

using System.IO;

using iTextSharp.text;

using iTextSharp.text.pdf;

using iTextSharp.text.pdf.draw;

namespace ITextSharpExample

{

代码语言:txt
复制
class Program
代码语言:txt
复制
{
代码语言:txt
复制
    static void Main(string[] args)
代码语言:txt
复制
    {
代码语言:txt
复制
        // 创建一个新的PDF文档
代码语言:txt
复制
        Document document = new Document();
代码语言:txt
复制
        PdfWriter.GetInstance(document, new FileStream("output.pdf", FileMode.Create));
代码语言:txt
复制
        document.Open();
代码语言:txt
复制
        // 添加一个标题,作为锚点的目标位置
代码语言:txt
复制
        Paragraph header = new Paragraph("这是一个标题,作为锚点的目标位置");
代码语言:txt
复制
        string targetName = "target";
代码语言:txt
复制
        PdfDestination destination = new PdfDestination(PdfDestination.FIT, header.GetTop(document));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.FITH, header.GetTop(document)));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.FITV, header.GetTop(document)));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.FITB, header.GetTop(document)));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.FITBH, header.GetTop(document)));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.FITBV, header.GetTop(document)));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new PdfDestination(PdfDestination.XYZ, header.GetTop(document), header.GetLeft(document), 1));
代码语言:txt
复制
        destination.AddFirst(new P
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

3分14秒

02.多媒体信息处理及编辑技术

43秒

Quivr非结构化信息搜索

5分33秒

JSP 在线学习系统myeclipse开发mysql数据库web结构java编程

领券