I’m trying to convert a pdf to a docx
My code:
$filePath = "C:\Users\Larso\Downloads\Install.pdf" $wd = New-Object -ComObject Word.Application $wd.Visible = $true $txt = $wd.Documents.Open( $filePath, $false, $false, $false) $wd.Documents[1].SaveAs("C:\Users\Larso\Downloads\Install.docx") $wd.Documents[1].Close()
i get error:
New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). At line:2 char:11 + $wd = New-Object -ComObject Word.Application + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand The property 'Visible' cannot be found on this object. Verify that the property exists and can be set. At line:3 char:1 + $wd.Visible = $true + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound You cannot call a method on a null-valued expression. At line:4 char:1 + $txt = $wd.Documents.Open( + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Cannot index into a null array. At line:10 char:1 + $wd.Documents[1].SaveAs("C:\Users\Larso\Downloads\Install.docx") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray Cannot index into a null array. At line:11 char:1 + $wd.Documents[1].Close() + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray
what did i do wrong or am missing?