2014-10-02 44 views
1

我需要將pdf文件保存爲docx(使用AcrobatPro)。我可以用下面的方法做到這一點,但我找不到在這個過程中如何禁用OCR的方式。AcrobatPro - 保存爲docx時禁用OCR

private AcroPDDoc pdf = new AcroPDDoc(); 

public void ConvertToDocx(string inputPath, string outputPath) 
{  
    pdf.Open(inputPath); 

    var jsObj = pdf.GetJSObject(); 
    var type = pdf.GetType(); 

    object[] saveAsParams = { outputPath, "com.adobe.acrobat.docx", "", false, false }; 
    type.InvokeMember("saveAs", BindingFlags.InvokeMethod | BindingFlags.Instance, null, jsObj, saveAsParams, CultureInfo.InvariantCulture); 

    pdf.Close(); 
} 
+0

它看起來像的Acrobat正在從系統註冊表(HKEY_CURRENT_USER \ S)進行轉換設置OFTWARE \ Adob​​e \ Adob​​e Acrobat \ 11.0 \ AVConversionFromPDF \ cSettings \ c0 \ cSettings),因此作爲臨時解決方案,我可以通過註冊表鍵bRunOCR和bIncludeComments – Iale 2015-02-27 10:26:52

+0

修改轉換設置,如果您找到解決方案,您是否可以回答自己的問題? – 2016-04-01 12:33:58

+0

@JayNirgudkar我已發佈我的答案 – Iale 2016-04-21 08:37:14

回答

1

的Acrobat正在從系統註冊表中的轉換設置(HKEY_CURRENT_USER\SOFTWARE\Adobe\Adobe Acrobat\11.0\AVConversionFromPDF\cSettings\c0\cSettings)

下面是簡單的類處理Acrobat中的註冊表設置

public class RegistrySettings 
{ 
    public int IncludeComments { get; set; } 
    public int RunOcr { get; set; } 

    private const string ConversionKey = @"HKEY_CURRENT_USER\SOFTWARE\Adobe\Adobe Acrobat\11.0\AVConversionFromPDF\cSettings\c0\cSettings"; 
    private const string RunOcrValueName = "bRunOCR"; 
    private const string IncludeCommentsValueName = "bIncludeComments"; 

    public static RegistrySettings CreateWithDisabledOcr() 
    { 
     return new RegistrySettings() {IncludeComments = 0, RunOcr = 0}; 
    } 

    public static RegistrySettings Parse() 
    { 
     var runOcr = (int) Registry.GetValue(ConversionKey, RunOcrValueName, null); 
     var comments = (int) Registry.GetValue(ConversionKey, IncludeCommentsValueName, null); 

     return new RegistrySettings() {IncludeComments = comments, RunOcr = runOcr}; 
    } 

    public void Save() 
    { 
     Registry.SetValue(ConversionKey, RunOcrValueName, RunOcr); 
     Registry.SetValue(ConversionKey, IncludeCommentsValueName, IncludeComments); 
    } 
} 

用法:

public static void DisableOcr() 
{ 
    RegistrySettings registry; 
    try 
    { 
     registry = RegistrySettings.Parse(); 
    } 
    catch (Exception ex) 
    { 
     Console.WriteLine(ex.Message); 
     return; 
    } 
    registry.RunOcr = 0; 
    registry.IncludeComments = 0; 
    registry.Save(); 
}