User Profile
singhn83
Copper Contributor
Joined 3 years ago
User Widgets
Recent Discussions
Re: Unable to print to pdf double copies (to a single file) using powershell
Varun_Ghildiyal I am able to print using Microsoft Print to PDF option when using GUI. Shouldn't that work when use powershell? I get the following error Cannot convert argument "image", with value: "System.Drawing.Printing.PrintPageEventArgs", for "DrawImage" to type "System.Drawing.Image": "Cannot convert the "System.Drawing.Printing.PrintPageEventArgs" value of type "System.Drawing.Printing.PrintPageEventArgs" to type "System.Drawing.Image"." At line:29 char:5 + $args.Graphics.DrawImage($page, 0, 0, $page.Width, $page.Height) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument The property 'HasMorePages' cannot be found on this object. Verify that the property exists and can be set. At line:30 char:5 + $args.HasMorePages = $true + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException1.2KViews0likes1CommentUnable to print to pdf double copies (to a single file) using powershell
Hi, I am trying to print a single file with 1 page pdf to 2 pages pdf (single file). However, the below code only produces a blank file. Can someone help me debug or guide me how to fix the issue? # Load Assembly [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") # Microsoft Print to PDF $filePath = "C:\Users\Worksheets\Print Font Type\01-A\A\01-A.pdf" $printerName = "Microsoft Print to PDF" $printerPort = "PORTPROMPT:" $numCopies = 2 # Create a PrinterSettings object and set the number of copies $printerSettings = New-Object System.Drawing.Printing.PrinterSettings #$printerSettings.Copies = $numCopies # Create a PrintDocument object and set the file name and printer $printDoc = New-Object System.Drawing.Printing.PrintDocument $printDoc.DocumentName = $filePath $printDoc.PrinterSettings = $printerSettings # Set the printer to Microsoft Print to PDF and print the document $printDoc.PrinterSettings.PrinterName = $printerName $printDoc.PrinterSettings.PrintToFile = $true $printDoc.PrinterSettings.PrintFileName = "$filePath" $printDoc.PrinterSettings.Copies = $numCopies # PrinterPort doesn't work #$printDoc.PrinterSettings.PrinterPort = $printerPort $printDoc.Print() # Wait for the print job to complete Start-Sleep -Seconds 101.4KViews0likes3Comments
Recent Blog Articles
No content to show