The following straight forward code opens two PDF files and merges the contents into a new file. This code only works under 6.1.1 if I comment out the two Close method calls (pdfDoc.Close() and pdfCoversheet.Close() otherwise an exception is thrown with error
The document cannot be modified. at PdfSharp.Pdf.PdfDocument.Close(). The code worked uncommented under 1.50.5147.
Code:
Dim combinedPdfPath As String = Path.Combine(g_WorkFolder, Path.GetFileNameWithoutExtension(pdfPath) + "_cs.pdf")
If File.Exists(combinedPdfPath) Then
File.Delete(combinedPdfPath)
End If
Using pdfCoversheet As PdfSharp.Pdf.PdfDocument = PdfReader.Open(coverSheetPath, PdfDocumentOpenMode.Import)
Using pdfDoc As PdfSharp.Pdf.PdfDocument = PdfReader.Open(pdfPath, PdfDocumentOpenMode.Import)
Using pdfCombined As New PdfDocument()
pdfCombined.AddPage(pdfCoversheet.Pages(0))
For i As Integer = 0 To pdfDoc.PageCount - 1
pdfCombined.AddPage(pdfDoc.Pages(i))
Next
pdfCombined.Save(combinedPdfPath)
'pdfDoc.Close()
End Using
End Using
'pdfCoversheet.Close()
End Using
Return combinedPdfPath