PowerShell Eror: Method invocation failed because ... [PDF.COM] does not contain method

Hello,

I'm trying to do a simple print/conversion from pdf to text and I'm getting the below errors when I try to execute the following code:

$PDFCreator = New-Object -ComObject PDFCreator.JobQueue
$PDFCreator.Initialize()
$PJ = $PDFCreator.PrintFileSwitchingPrinters('C:\Users\ivaar\OneDrive\Documents\GitHub\PowerShell\ACA-guide.pdf', $TRUE)
$PJ.SetProfileByGuid('TextCon')
$PJ.ConvertTo('C:\Users\ivaar\OneDrive\Documents\GitHub\PowerShell\Converted-Guide.txt')
$PDFCreator.ReleaseCom()



Method invocation failed because [pdfforge.PDFCreator.UI.COM.Queue] does not 
contain a method named 'PrintFileSwitchingPrinters'.
At C:\Users\ivaar\OneDrive\Documents\GitHub\PowerShell\TestTwo.ps1:5 char:1
+ $PJ = $PDFCreator.PrintFileSwitchingPrinters('C:\Users\ivaar\OneDrive ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
You cannot call a method on a null-valued expression.
At C:\Users\ivaar\OneDrive\Documents\GitHub\PowerShell\TestTwo.ps1:6 char:1
+ $PJ.SetProfileByGuid('TextCon')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
You cannot call a method on a null-valued expression.
At C:\Users\ivaar\OneDrive\Documents\GitHub\PowerShell\TestTwo.ps1:7 char:1
+ $PJ.ConvertTo('C:\Users\ivaar\OneDrive\Documents\GitHub\PowerShell\Co ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Hi,

PrintFileSwitchingPrinters is part of PDFCreator.PDFCreatorObj, not PDFCreator.JobQueue.
https://docs.pdfforge.org/pdfcreator/4.0/en/pdfcreator/com-interface/

Best regards

Robin

Thanks for the response! Now that I'm using PDFCreator.PDFCreatorObj I'm still getting the following error:

Exception calling "PrintFile" with "1" argument(s): "The following file cannot be printed: C:\Users\ivaar\OneDrive\Documents\GitHub\PowerShell\ACA-guide.pdf

With this code:
$PDFCreator = New-Object -ComObject PDFCreator.PDFCreatorObj $PDFCreator.PrintFile('C:\Users\ivaar\OneDrive\Documents\GitHub\PowerShell\ACA-guide.pdf')

I'm a bit of a newbie here so how would I go about printing/converting the pdf file to .txt format? It seems that the JobQueue methods aren't compatible with the PDFCreatorObj methods. There aren't any security issues with the .pdf file since I'm able to print/convert it manually in PDFCreator without using COM.

Hi @Robinusmaximus

I believe you're getting the error because the default printing application for pdf files isn't correctly configured. (At least that seems to be the issue on my system.)
Please right-click on a pdf file and see if there is a "Print" context menu entry.
On my system, a print entry is configured for .txt and .png files and both file types are printable using $PDFCreator.PrintFile().

(Of course, I might be wrong here. I'm not very experienced with the COM Interface.)