将pdf转换为Word文档

时间:2010-08-05 07:29:13

标签: .net pdf ms-word converter

感谢你们给出的答案...... 在这里,我想再问一个问题:

在.net中将 PDF文档转换为Word文档的最佳方法是什么?

1 个答案:

答案 0 :(得分:2)

将运行文件夹中的所有pdf保存到docx。

将powershell脚本转换为C#。

在AcrobatX Pro中测试。

Pdf2Docx.ps1:

$TypeExt="docx"
$closeDocParam = $true;

Get-ChildItem -Filter *.pdf |Where {

# logical document

    $AVDoc = New-Object -ComObject AcroExch.AVDoc;    

    $AVDoc.Open($_.Fullname, "") | Out-Null;
# physical document

    $PDDoc = $AVDoc.GetPDDoc();                           
    $JavaScriptObject = $PDDoc.GetJSObject();                        
# get the bridge JavaScript Object

    $T = $JavaScriptObject.GetType();

    $T.InvokeMember("SaveAs",

        [Reflection.BindingFlags]::InvokeMethod -bor `
            [Reflection.BindingFlags]::Public       -bor `
            [Reflection.BindingFlags]::Instance          ,

        $null,
        $JavaScriptObject,
        @([IO.Path]::ChangeExtension($_.Fullname, $TypeExt), ("com.adobe.acrobat."+$TypeExt)));

        $T.InvokeMember("closeDoc", 

        [Reflection.BindingFlags]::InvokeMethod -bor `
            [Reflection.BindingFlags]::Public       -bor `
            [Reflection.BindingFlags]::Instance          ,

            $null, 
            $JavaScriptObject, 
            $closeDocParam) | Out-Null;

    $PDDoc.Close()  | Out-Null;
    $AVDoc.Close(1) | Out-Null;
}