Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert PDF to Word

I have a folder containing some .doc,.docx documents. I am able to convert these to *.pdf using powershell

$wdDocument.ExportAsFixedFormat( ..... )

I have another folder having*.pdf documents. I want to convert *.PDF to .doc/.docx using powershell and Acrobat PRO?

Acrobat PRO( 10 ) is installed in the system(I don't know how to call Acrobat from powershell).

OS: Windows 7 Pro(x64) MS-Office : 2010

like image 345
avinandan012 Avatar asked Jan 08 '23 04:01

avinandan012


1 Answers

You can try opening the document in Word, and then saving as. I'm not sure of what (if any) Acrobat APIs are available, but Word is pretty smart about opening PDF documents that conform to the PDF ISO Standard, which Adobe submitted in I think 2006 to become a standard. That's not your question though!

$filePath = "C:\Temp\MyPdfDocument.pdf"
    $wd = New-Object -ComObject Word.Application
$wd.Visible = $true
$txt = $wd.Documents.Open(
    $filePath,
    $false,
    $false,
    $false)

$wd.Documents[1].SaveAs("C:\Temp\MyPdfDocument.docx")
$wd.Documents[1].Close()

Don't forget to kill off the Word interop after that... I'm not sure if this is the BEST way, but it ought to work.

like image 115
PSGuy Avatar answered Jan 16 '23 02:01

PSGuy