Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用PdfSharp创建批注以突出显示现有PDF的文本_C#_Pdf_Pdf Generation_Pdfsharp - Fatal编程技术网

C# 如何使用PdfSharp创建批注以突出显示现有PDF的文本

C# 如何使用PdfSharp创建批注以突出显示现有PDF的文本,c#,pdf,pdf-generation,pdfsharp,C#,Pdf,Pdf Generation,Pdfsharp,我想知道是否可以使用PdfSharp在现有PDF中创建文本突出显示批注 在PdfSharp中,我看到了PdfTextAnnotation和PdfRubberStampAnnotation的示例,但没有找到文档中提到的以下注释的示例代码 PdfLineAnnotation, PdfSquareAnnotation, PdfCircleAnnotation, PdfMarkupAnnotation, PdfHighlightAnnotation, PdfUnderlineAnnotation, P

我想知道是否可以使用PdfSharp在现有PDF中创建文本突出显示批注

在PdfSharp中,我看到了
PdfTextAnnotation
PdfRubberStampAnnotation
的示例,但没有找到文档中提到的以下注释的示例代码

PdfLineAnnotation, PdfSquareAnnotation, PdfCircleAnnotation, 
PdfMarkupAnnotation, PdfHighlightAnnotation, PdfUnderlineAnnotation,
PdfSquigglyAnnotation, PdfSoundAnnotation, PdfMovieAnnotation.

这些注释是否还需要在PdfSharp中实现?如果有人已经实现了,请告诉我代码示例。

我也遇到了这样的问题,并且在PdfSharp库中没有找到任何其他注释类型。因此,我看了《12.5注释》一文。例如,它说要创建文本标记注释,开发人员需要指定
子类型
四点
条目。请参阅下面的源代码

namespace PdfSharp.Pdf.Annotations
{
    using Extensions;
    using System.Collections.Generic;

    public class PdfHighlightAnnotation : PdfMarkupAnnotation
    {
        public PdfHighlightAnnotation()
        {
            Initialize();
        }

        public PdfHighlightAnnotation(PdfDocument document)
            : base(document)
        {
            Initialize();
        }

        void Initialize()
        {
            Elements.SetName(Keys.Subtype, "/Highlight");
        }
    }

    public class PdfStrikeOutAnnotation : PdfMarkupAnnotation
    {
        public PdfStrikeOutAnnotation()
        {
            Initialize();
        }

        public PdfStrikeOutAnnotation(PdfDocument document)
            : base(document)
        {
            Initialize();
        }

        void Initialize()
        {
            Elements.SetName(Keys.Subtype, "/StrikeOut");
        }
    }

    public abstract class PdfMarkupAnnotation : PdfAnnotation
    {
        protected PdfMarkupAnnotation()
        { }

        protected PdfMarkupAnnotation(PdfDocument document)
            : base(document)
        { }

        public IEnumerable<PdfRectangle> Quadrilaterals
        {
            set {
                var points = new PdfArray();
                foreach (var r in value) {
                    points.Elements.AddRange(ToQuadPoints(r));
                }
                Elements.SetValue("/QuadPoints", points);
            }
        }

        private IEnumerable<PdfItem> ToQuadPoints(PdfRectangle r)
        {
            // Conversion from PdfRectangle coordinates
            //
            // Y ^
            //   |                     (X2 Y2)
            //   |        +-----------+
            //   |        |           |
            //   |        |           |
            //   |        +-----------+
            //   | (X1 Y1)
            //   |                              
            //   +-----------------------------> 
            //                                 X
            // to QuadPoints coordinates (x1 y1 x2 y2 x3 y3 x4 y4)
            //
            // Y ^
            //   | (x4 y4)             (x3 y3)
            //   |        +-----------+
            //   |        |           |
            //   |        |           |
            //   |        +-----------+
            //   | (x1 y1)             (x2 y2)
            //   |                              
            //   +-----------------------------> 
            //                                 X
            //
            return new List<PdfItem> { new PdfReal(r.X1), new PdfReal(r.Y1),
                                       new PdfReal(r.X2), new PdfReal(r.Y1),
                                       new PdfReal(r.X1), new PdfReal(r.Y2),
                                       new PdfReal(r.X2), new PdfReal(r.Y2)};
        }
    }
}

namespace PdfSharp.Extensions
{
    using PdfSharp.Pdf;
    using System.Collections.Generic;

    public static class ArrayElementsExtensions
    {
        public static void AddRange(this PdfArray.ArrayElements elements, IEnumerable<PdfItem> values)
        {
            foreach (var v in values) {
                elements.Add(v);
            }
        }
    }
}
namespace PdfSharp.Pdf.Annotations
{
使用扩展;
使用System.Collections.Generic;
公共类PdfHighlightAnnotation:PdfMarkupAnnotation
{
公共PdfHighlightAnnotation()
{
初始化();
}
公共PdfHighlightAnnotation(PDF文档)
:base(文档)
{
初始化();
}
void Initialize()
{
Elements.SetName(Keys.Subtype,“/Highlight”);
}
}
公共类PdfStrikeOutAnnotation:PdfMarkupAnnotation
{
公共PdfStrikeOutAnnotation()
{
初始化();
}
公共PdfStrikeOutAnnotation(PdfDocument文档)
:base(文档)
{
初始化();
}
void Initialize()
{
Elements.SetName(Keys.Subtype,“/StrikeOut”);
}
}
公共抽象类PdfMarkupAnnotation:PdfAnnotation
{
受保护的PdfMarkupAnnotation()
{ }
受保护的PdfMarkupAnnotation(PdfDocument文档)
:base(文档)
{ }
公共可数四边形
{
设置{
变量点=新的PdfArray();
foreach(var r值){
points.Elements.AddRange(ToQuadPoints(r));
}
元素。设置值(“/QuadPoints”,点);
}
}
私有IEnumerable to quadpoints(PdfRectangle r)
{
//从PdfRectangle坐标转换
//
//Y^
//|(X2-Y2)
//   |        +-----------+
//   |        |           |
//   |        |           |
//   |        +-----------+
//|(X1-Y1)
//   |                              
//   +-----------------------------> 
//X
//至四点坐标(x1 y1 x2 y2 x3 y3 x4 y4)
//
//Y^
//|(x4 y4)(x3 y3)
//   |        +-----------+
//   |        |           |
//   |        |           |
//   |        +-----------+
//|(x1-y1)(x2-y2)
//   |                              
//   +-----------------------------> 
//X
//
返回新列表{new PdfReal(r.X1),new PdfReal(r.Y1),
新PdfReal(r.X2),新PdfReal(r.Y1),
新PdfReal(r.X1),新PdfReal(r.Y2),
新的PdfReal(r.X2),新的PdfReal(r.Y2)};
}
}
}
命名空间PdfSharp.Extensions
{
使用PdfSharp.Pdf;
使用System.Collections.Generic;
公共静态类ArrayElementExtensions
{
公共静态void AddRange(此PdfArray.ArrayElements元素,IEnumerable值)
{
foreach(值中的var v){
增加(五);
}
}
}
}

谢谢您的代码,但是如何使用它呢?我不能让它工作。