Last active
October 3, 2022 22:03
-
-
Save TiloGit/32c7cd250727832c5b209234974d4fc1 to your computer and use it in GitHub Desktop.
Generate PDF files from Powershell text with dummy filler file (with PDF sharp DLL)
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
## the PDF | |
$ExecuteStarTime = get-date | |
Add-Type -Path .\PdfSharp.dll #### got PdfSharp.dll from ngut download https://www.nuget.org/packages/PdfSharp/ (open with 7zip) | |
$img = [PdfSharp.Drawing.XImage]::FromFile("C:\test-trex-fs-root\TILOPDF\TSOsou\dummy.png") | |
##now loop | |
10001..10500 | % { | |
$doc = New-Object PdfSharp.Pdf.PdfDocument | |
$doc.Info.Title = "Content File $($_)" | |
$doc.Info.Author = "$($env:username)" | |
$doc.Info.Subject = "This is Test Content File" | |
$msg = "$(Get-Date -format s) This is Test Content File $($_) from $($env:username) on $($env:COMPUTERNAME) at $(get-date -format "yyyyMMdd_HHmmssffff")" | |
$page = $doc.AddPage() | |
$gfx = [PdfSharp.Drawing.XGraphics]::FromPdfPage($page) | |
$font = New-Object PdfSharp.Drawing.XFont("Arial", 10, [PdfSharp.Drawing.XFontStyle]::BoldItalic) | |
$rect = New-Object PdfSharp.Drawing.XRect(10,10,$page.Width, $page.Height) | |
$gfx.DrawImage($img, 0, 25, $page.Width, $page.Height) | |
$gfx.DrawString($msg, $font, [PdfSharp.Drawing.XBrushes]::Black, $rect, [PdfSharp.Drawing.XStringFormats]::TopLeft) | |
$doc.Save("C:\test-trex-fs-root\TILOPDF\fileContent\ContentFile$_.pdf") | |
} | |
$ExecuteDuration = New-TimeSpan $ExecuteStarTime | |
Echo "End after duration: $("{0:N5}" -f $ExecuteDuration.TotalMinutes) Minutes" | |
Echo "End after duration: $("{0:N5}" -f $ExecuteDuration.TotalSeconds) Seconds" | |
##### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment