Skip to content

Instantly share code, notes, and snippets.

@TiloGit
Created October 3, 2022 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiloGit/0fcc7a06f34e923ad6fb97591a5c2fcc to your computer and use it in GitHub Desktop.
Save TiloGit/0fcc7a06f34e923ad6fb97591a5c2fcc to your computer and use it in GitHub Desktop.
Generate PDF files from text in powershell
#################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"
}
@TiloGit
Copy link
Author

TiloGit commented Oct 3, 2022

above doesn't check the printer queue so the sleep would need to be optimized to avoid collision.

@TiloGit
Copy link
Author

TiloGit commented Oct 3, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment