none
Printing to PDF via script is printing blank documents RRS feed

  • Question

  • I am trying to use powershell to print each item (.tif files) in a directory as PDF's, while retaining their original file names. I would like this to happen with no user intervention. I am using Microsoft Print to PDF.  

    I found the following script which i was planning to modify for my scenario - https://social.technet.microsoft.com/Forums/ie/en-US/04ddfe8c-a07f-4d9b-afd6-04b147f59e28/automating-printing-to-pdf?forum=winserverpowershell

    function ConvertTo-PDF {
    param(
    $TextDocumentPath
    )

    Add-Type -AssemblyName System.Drawing
    $doc = New-Object System.Drawing.Printing.PrintDocument
    $doc.DocumentName = $TextDocumentPath
    $doc.PrinterSettings = new-Object System.Drawing.Printing.PrinterSettings
    $doc.PrinterSettings.PrinterName = 'Microsoft Print to PDF'
    $doc.PrinterSettings.PrintToFile = $true
    $file=[io.fileinfo]$TextDocumentPath
    $pdf= [io.path]::Combine($file.DirectoryName, $file.BaseName) + '.pdf'
    $doc.PrinterSettings.PrintFileName = $pdf
    $doc.Print()
    $doc.Dispose()

    However when i do this, it outputs a blank pdf file with the correct name. Any ideas? 

    Tuesday, July 16, 2019 6:25 PM

All replies

  • You cannot print a TIFF as a text document. It must be printed with an imaging program.


    \_(ツ)_/

    Tuesday, July 16, 2019 8:01 PM