C#在PDF中怎么添加墨迹注释

发布时间:2022-02-17 13:48:41 作者:iii
来源:亿速云 阅读:162

这篇文章主要介绍“C#在PDF中怎么添加墨迹注释”,在日常操作中,相信很多人在C#在PDF中怎么添加墨迹注释问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”C#在PDF中怎么添加墨迹注释”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

PDF中的墨迹注释(Ink Annotation),表现为徒手涂鸦式的形状;该类型的注释,可任意指定形状顶点的位置及个数,通过指定的顶点,程序将连接各点绘制成平滑的曲线。下面,通过C#程序代码介绍如何在PDF中添加该注释。

一、dll引用

步骤1:在Visual Studio中打开“解决方案资源管理器”- 鼠标右键点击“引用”-“管理NuGet包”。

C#在PDF中怎么添加墨迹注释

步骤2:选择“浏览”-在搜索框中输入搜索内容,选择搜索结果,点击“安装”。

C#在PDF中怎么添加墨迹注释

步骤3:依次点击“OK”-"接受",然后等待程序完成安装。

C#在PDF中怎么添加墨迹注释

或者,通过官方渠道,下载包Spire.PDF for .NET到本地。解压后,将BIN文件夹下的Spire.Pdf.dll文件引用至VS程序。

二、代码示例

添加注释时,除了自定义各个点的位置及数量,也可以设置墨迹颜色、线条宽度、透明度、注释的内容、名称等。下面是代码实现的步骤:

C#

using Spire.Pdf;
using Spire.Pdf.Annotations;
using System.Collections.Generic;
using System.Drawing;

namespace InkAnnotation
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载PDF文档
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("test.pdf");
            //获取第一页
            PdfPageBase pdfPage = pdf.Pages[0];
            //设置墨迹坐标点位置
            List<int[]> inkList = new List<int[]>();           
            int[] intPoints = new int[]
            {
                370,700,
                120,720,
                110,760,
                220,800,
                270,790,
                350,770,
                350,670
            };
            inkList.Add(intPoints);
            //添加墨迹注释到PDF页面
            PdfInkAnnotation inkannotation = new PdfInkAnnotation(inkList);
            inkannotation.Color = Color.MediumVioletRed;
            inkannotation.Border.Width = 6;
            inkannotation.Opacity = 0.5f;
            inkannotation.Text = "This is an ink annotation. ";
            inkannotation.Name = "Manager";     
            pdfPage.AnnotationsWidget.Add(inkannotation);
            //保存文档
            Pdf.SaveToFile("AddInkAnnotation.pdf",FileFormat.PDF);
            System.Diagnostics.Process.Start("AddInkAnnotation.pdf");
        }
    }
}

vb.net

Imports Spire.Pdf
Imports Spire.Pdf.Annotations
Imports System.Collections.Generic
Imports System.Drawing
Namespace InkAnnotation
    Class Program
        Private Shared Sub Main(args As String())
            '加载PDF文档
            Dim pdf As New PdfDocument()
            pdf.LoadFromFile("test.pdf")
            '获取第一页
            Dim pdfPage As PdfPageBase = pdf.Pages(0)
            '设置墨迹坐标点位置
            Dim inkList As New List(Of Integer())()
            Dim intPoints As Integer() = New Integer() {370, 700, 120, 720, 110, 760, _
                220, 800, 270, 790, 350, 770, _
                350, 670}
            inkList.Add(intPoints)
            '添加墨迹注释到PDF页面
            Dim inkannotation As New PdfInkAnnotation(inkList)
            inkannotation.Color = Color.MediumVioletRed
            inkannotation.Border.Width = 6
            inkannotation.Opacity = 0.5F
            inkannotation.Text = "This is an ink annotation. "
            inkannotation.Name = "Manager"
            pdfPage.AnnotationsWidget.Add(inkannotation)
            '保存文档
            pdf.SaveToFile("AddInkAnnotation.pdf", FileFormat.PDF)
        End Sub
    End Class
End Namespace

注释效果:

C#在PDF中怎么添加墨迹注释

到此,关于“C#在PDF中怎么添加墨迹注释”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. C# 添加PDF印章
  2. C# 在PDF页面添加打印按钮

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

pdf

上一篇:Linux中如何使用true命令

下一篇:如何使用自定义注解实现redisson分布式锁

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》