I am also trying to do this. I am struggling with adding the page content and get an empty PDF file as a result. Here is my script so far - maybe together we can figure this out!
function ConvertTo-PDF {
param(
$OriginalFilePath
)
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.IO
$PrinterSettings = new-Object System.Drawing.Printing.PrinterSettings
$PrinterSettings.PrinterName = 'Microsoft Print to PDF'
$PrinterSettings.PrintToFile = $true
$PrintDocument = New-Object System.Drawing.Printing.PrintDocument
$PrintDocument.DocumentName = $OriginalFilePath
$PrintDocument.PrinterSettings = $PrinterSettings
$PictureByteArray = [System.IO.File]::ReadAllBytes($OriginalFilePath)
#add the page content to the file - this isn't working
#$streamToPrint = New-Object System.IO.StreamReader $OriginalFilePath
#$PrintDocument.add_PrintPage($PrintPageHandler)
#$PrintDocument.add_PrintPage($OriginalFilePath)
#another attempt to add the page content - also not working
#$PrintDocument.add_PrintPage({
# Create an ImageConverter to convert our byte array into a Bitmap for drawing
# $ImageConverter = New-Object System.Drawing.ImageConverter
# [Drawing.Bitmap]$ProfileImg = $Imageconverter.ConvertFrom($PictureByteArray)
# Set an arbitrary width to scale the image to
# $Width = $ProfileImg.Width
# Calculate the relationship between height and width to calculate with new width
# $ProfileScale = [double]$ProfileImg.Height / [double]$ProfileImg.Width
# Create source rectangle representing full size of image
# $ProfileRectSrc = New-Object Drawing.RectangleF(0, 0, $ProfileImg.Width, $ProfileImg.Height)
# Change scale of destination rectangle based on the calculated width
# $ProfileRectDest = New-Object Drawing.RectangleF([System.Drawing.PointF]::new(10,10), [System.Drawing.Size]::new($Width, [int]($Width * $ProfileScale)))
# $_.Graphics.DrawImage($ProfileImg, $ProfileRectDest, $ProfileRectSrc, [Drawing.GraphicsUnit]::Pixel)
#})
$file=[io.fileinfo]$OriginalFilePath
$OutputFile = [io.path]::Combine($file.DirectoryName, $file.BaseName) + '_1.pdf'
$PrintDocument.PrinterSettings.PrintFileName = $OutputFile
$PrintDocument.Print()
$PrintDocument.Dispose()
}
ConvertTo-PDF 'C:\Original.pdf'