如何使用PDFsharp将注释从一个PDF添加到另一个PDF?

问题描述 投票:-1回答:1

这里,我检查源PDF文件是否包含注释,然后尝试通过循环获取每个注释,并尝试将其添加到新的PDF页面。但是它显示了无法修改文档的错误。

是否有使用PDFsharp的方法将注释从一个PDF页面复制到另一PDF页面?

这是我的代码:

PdfDocument DocumentReader_Po = new PdfDocument();
pdfPage_Po = Pdocument.AddPage();
pdfPage_Po = Pdocument.AddPage();
pdfPage_Po.Width = PageSizeConverter.ToSize(PdfSharp.PageSize.Letter).Width;
pdfPage_Po.Height = PageSizeConverter.ToSize(PdfSharp.PageSize.Letter).Height;
form = XPdfForm.FromFile(sourceFile);
if (form.Page.HasAnnotations)
{
    for (int j = 0; j < form.Page.Annotations.Count; j++)
    {
        var annot = form.Page.Annotations[j];
        var subType = annot.Elements.GetString(PdfAnnotation.Keys.Subtype);
        if (subType == "/Text")
        {
            pdfPage_Po.Annotations.Add(annot); 
        }
    }
}
c# model-view-controller pdfsharp
1个回答
0
投票

您从一个文档中获取注释,然后尝试将其添加到新文档中。

野蛮猜测:您无法将文档元素分配给新文档,因为该元素的“所有者”已经设置。

创建注释的副本(没有“所有者”的深层副本,并尝试将副本添加到新文档。

© www.soinside.com 2019 - 2024. All rights reserved.