powershell script convert doc to pdf


hi, i've came across script convert doc/docx files contained in folder , subfolders, seems it's wrong it. it's shows following error when launch it. appreciated!!!!

el valor no está dentro del intervalo esperado. (value not in expected range)
en línea: 12 carácter: 5
+     $doc.exportasfixedformat($pdf_filename, [microsoft.office.interop ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + categoryinfo          : operationstopped: (:) [], argumentexception
    + fullyqualifiederrorid : system.argumentexception


$documents_path = 'c:\pruebas'

$word_app = new-object -comobject word.application

# filter find .doc .docx documents
get-childitem -path $documents_path -filter *.doc? -recurse | foreach-object {

    $doc = $word_app.documents.open($_.fullname)

    $pdf_filename = "$($_.directoryname)\$($_.basename).pdf"
  
    $doc.exportasfixedformat($pdf_filename, [microsoft.office.interop.word.wdexportformat]::wdexportformatpdf, $false, [microsoft.office.interop.word.wdexportoptimizefor]::wdexportoptimizeforprint, [microsoft.office.interop.word.wdexportrange]::wdexportfromto, 1, 1, [microsoft.office.interop.word.wdexportitem]::wdexportdocumentcontent, $false, $false, [microsoft.office.interop.word.wdexportcreatebookmarks]::wdexportcreatenobookmarks, $false, $true, $false, $null)
    
    $doc.close()
}

$word_app.quit()

this simplified format:

$path = 'd:\test' $wd = new-object -comobject word.application get-childitem -path $path -include *.doc, *.docx -recurse | 	foreach-object { 		$doc = $wd.documents.open($_.fullname) 		$pdf = $_.fullname -replace $_.extension, '.pdf' 		$doc.exportasfixedformat($pdf,17,$false,0,3,1,1,0,$false, $false,0,$false, $true) 		$doc.close() 	} $wd.quit() 

i pretty sure same thing.

$path = 'd:\test' $wd = new-object -comobject word.application get-childitem -path $path -include *.doc, *.docx -recurse | 	foreach-object { 		$doc = $wd.documents.open($_.fullname) 		$pdf = $_.fullname -replace $_.extension, '.pdf' 		$doc.exportasfixedformat($pdf,17) 		$doc.close() 	} $wd.quit() 

 


\_(ツ)_/



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Indexing Server

Schannel Issue

oclist /xml or /?