I am in the early stages of moving from iTextSharp to iText7, but am failing early. This is the code snippet:
$lib="C:\bob\pshell\iText7\itext7.7.1.1\lib\net40\itext.kernel.dll"
[System.Reflection.Assembly]::LoadFrom($lib)
$reader= New-Object itext.kernel.pdf.PdfReader "<valid pdf>"
$PDFdocument = New-Object itext.kernel.pdf.PdfDocument($reader)
This produces an error:
New-Object : Exception calling ".ctor" with "1" argument(s): "Cannot open document."
The $reader object seems valid, and returns a length and IsOpenedWithFullPermission returns $true. I have successfully used similar code to create and write to a PDF, but cannot create a PDFDocument from a PDFReader object. Am I missing something simple? Thanks
PdfDocumentclass. It's as if you didn't read the documentation. You want to read a document in order to create another document, so where is thePdfWriter? You have to pass aPdfWriterinstance to the constructor of thePdfDocument. - Bruno Lowagie