Created
October 3, 2022 20:19
-
-
Save TiloGit/0fcc7a06f34e923ad6fb97591a5c2fcc to your computer and use it in GitHub Desktop.
Generate PDF files from text in powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################createPrinter | |
# choose a name for your new printer | |
$printerName = 'PrintPDFUnattended' | |
# choose a default path where the PDF is saved | |
$PDFFilePath = "C:\PrinterTemp\PDFResultFile.pdf" | |
New-Item $PDFFilePath -type file -Force | |
# add printerPort | |
Add-PrinterPort -Name $PDFFilePath | |
# add printer | |
Add-Printer -DriverName "Microsoft Print to PDF" -Name $printerName -PortName $PDFFilePath | |
#################createPrinter end | |
##now loop to create files | |
10001..20000 | % { | |
out-printer -name $printerName -inputobject "$(Get-Date -format s) This is Test Content File $($_) from $($env:username) on $($env:COMPUTERNAME) at $(get-date -format "yyyyMMdd_HHmmssffff")" | |
start-sleep -Milliseconds 200 | |
mv $PDFFilePath "..\fileContent\ContentFile$_.pdf" | |
} |
better use PdfSharp.dll solution: https://gist.github.com/TiloGit/32c7cd250727832c5b209234974d4fc1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
above doesn't check the printer queue so the sleep would need to be optimized to avoid collision.