【发布时间】:2019-02-07 09:14:10
【问题描述】:
我有多个由不同用户评论的 .pdf 文档副本。我想将所有这些 cmets 合并成一个新的 pdf “合并”。
我在一个名为 document 的类中编写了这个 sub,其属性为“path”和“directory”。
Public Sub MergeComments(ByVal pdfDocuments As String())
Dim oSavePath As String = Directory & "\" & FileName & "_Merged.pdf"
Dim oPDFdocument As New iText.Kernel.Pdf.PdfDocument(New PdfReader(Path),
New PdfWriter(New IO.FileStream(oSavePath, IO.FileMode.Create)))
For Each oFile As String In pdfDocuments
Dim oSecundairyPDFdocument As New iText.Kernel.Pdf.PdfDocument(New PdfReader(oFile))
Dim oAnnotations As New PDFannotations
For i As Integer = 1 To oSecundairyPDFdocument.GetNumberOfPages
Dim pdfPage As PdfPage = oSecundairyPDFdocument.GetPage(i)
For Each oAnnotation As Annot.PdfAnnotation In pdfPage.GetAnnotations()
oPDFdocument.GetPage(i).AddAnnotation(oAnnotation)
Next
Next
Next
oPDFdocument.Close()
End Sub
此代码导致我无法解决的异常。
iText.Kernel.PdfException: 'Pdf 间接对象属于其他 PDF 文档。将对象复制到当前 pdf 文档。'
我需要更改哪些内容才能执行此任务?还是我完全放弃了我的代码块?
【问题讨论】: