IText7Module.psm1
Function createNewPDF { param($fileName) $pdfWriter = [iText.Kernel.Pdf.PdfWriter ]::new($fileName) $pdfDocument = [iText.Kernel.Pdf.PdfDocument ]::new($pdfWriter) $document = [itext.Layout.Document ]::new($pdfDocument) return @{document = $document;pdfDocument = $pdfDocument; pdfWriter = $pdfWriter} } Function closePDF { param($pdfDocProperties) $pdfDocProperties.pdfDocument.Close() $pdfDocProperties.pdfWriter.Close() } Function initialiseIText7 { $pdfFileName = "$($env:TEMP)\testIText7.pdf" $pdfDocProps = createNewPDF -fileName $pdfFileName $document = $pdfDocProps.document $paragraph = [iText.Layout.Element.Paragraph]::new("dummy report") $null = $document.Add($paragraph) closePDF $pdfDocProps Write-Host "iText7 Test PDF document created successfully - iText7Module is available" } # important: update the FunctionsToExport in themodule .psd1 file to make sure that any additional functions are available in the module Export-ModuleMember -Function initialiseIText7 |