2012-07-05 2 views
7

내 .Net 응용 프로그램에서 PDF 문서를 프로그래밍 방식으로 Word 형식으로 변환해야합니다.Acrobat SDK를 사용하여 PDF를 Word로 변환하는 방법은 무엇입니까?

몇 가지 제품을 평가 한 결과 Acrobat X Pro을 발견했습니다. 이는 Word/Excel 형식으로 문서를 저장할 수있는 저장 옵션을 제공합니다. Acrobat SDK를 사용하려고했지만 시작할 위치에서 적절한 설명서를 찾을 수 없습니다.

IAC 샘플을 조사했지만 메뉴 항목을 호출하고 다른 이름으로 저장 옵션을 실행하는 방법을 이해할 수 없었습니다.

답변

0

Acrobat PDF 클라이언트를 사용하지 않는 경우 Adobe는 PDF에서 Word 로의 변환을 지원하지 않습니다. SDK를 사용하거나 명령 줄을 호출해서는 안됩니다. 수동으로 만 할 수 있습니다.

+0

솔루션을 나 나 프로그램이 달성 할 수있는 방법을 보여줍니다. Acrobat X Pro를 사용하고 있다면 WinPython x64 2.7.6.3 (무료)을 설치 한 후에 스크립트를 사용해 볼 수 있습니다. – Subhobroto

13

Acrobat X Pro에서는이 작업을 수행 할 수 있지만 C#에서는 javascript API를 사용해야합니다.

AcroPDDoc pdfd = new AcroPDDoc(); 
pdfd.Open(sourceDoc.FileFullPath); 
Object jsObj = pdfd.GetJSObject(); 
Type jsType = pdfd.GetType(); 
//have to use acrobat javascript api because, acrobat 
object[] saveAsParam = { "newFile.doc", "com.adobe.acrobat.doc", "", false, false }; 
jsType.InvokeMember("saveAs",BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance,null, jsObj, saveAsParam, CultureInfo.InvariantCulture); 

희망이 있습니다.

+0

안녕하세요, 저는 똑같은 말을하지 않았습니다 .. 감사합니다. 대답. 그러나 그 과정은 끝내는 데 꽤 많은 시간이 걸리는 것으로 보입니다. 만약 내가 1000 파일을 커버해야한다, 그것은 6 시간 이상 걸릴 것입니다 .. 거기에 이것에 대한 빠른 방법은 무엇입니까? –

+0

파일의 잠금을 해제하기 위해 끝에 pdfd.Close()를 추가했습니다. – r03

1

WinPython x64 2.7.6.3 및 Acrobat X Pro를 사용하여 비슷한 점을 보였고 JSObject 인터페이스를 사용하여 PDF를 DOCX로 변환했습니다. 기본적으로 jle's과 같은 솔루션입니다.

다음은 DOCX에 PDF 파일의 집합을 변환 코드의 전체 조각이어야한다 : 하나 JLE에 의해 게시

# gets all files under ROOT_INPUT_PATH with FILE_EXTENSION and tries to extract text from them into ROOT_OUTPUT_PATH with same filename as the input file but with INPUT_FILE_EXTENSION replaced by OUTPUT_FILE_EXTENSION 
from win32com.client import Dispatch 
from win32com.client.dynamic import ERRORS_BAD_CONTEXT 

import winerror 

# try importing scandir and if found, use it as it's a few magnitudes of an order faster than stock os.walk 
try: 
    from scandir import walk 
except ImportError: 
    from os import walk 

import fnmatch 

import sys 
import os 

ROOT_INPUT_PATH = None 
ROOT_OUTPUT_PATH = None 
INPUT_FILE_EXTENSION = "*.pdf" 
OUTPUT_FILE_EXTENSION = ".docx" 

def acrobat_extract_text(f_path, f_path_out, f_basename, f_ext): 
    avDoc = Dispatch("AcroExch.AVDoc") # Connect to Adobe Acrobat 

    # Open the input file (as a pdf) 
    ret = avDoc.Open(f_path, f_path) 
    assert(ret) # FIXME: Documentation says "-1 if the file was opened successfully, 0 otherwise", but this is a bool in practise? 

    pdDoc = avDoc.GetPDDoc() 

    dst = os.path.join(f_path_out, ''.join((f_basename, f_ext))) 

    # Adobe documentation says "For that reason, you must rely on the documentation to know what functionality is available through the JSObject interface. For details, see the JavaScript for Acrobat API Reference" 
    jsObject = pdDoc.GetJSObject() 

    # Here you can save as many other types by using, for instance: "com.adobe.acrobat.xml" 
    jsObject.SaveAs(dst, "com.adobe.acrobat.docx") # NOTE: If you want to save the file as a .doc, use "com.adobe.acrobat.doc" 

    pdDoc.Close() 
    avDoc.Close(True) # We want this to close Acrobat, as otherwise Acrobat is going to refuse processing any further files after a certain threshold of open files are reached (for example 50 PDFs) 
    del pdDoc 

if __name__ == "__main__": 
    assert(5 == len(sys.argv)), sys.argv # <script name>, <script_file_input_path>, <script_file_input_extension>, <script_file_output_path>, <script_file_output_extension> 

    #$ python get.docx.from.multiple.pdf.py 'C:\input' '*.pdf' 'C:\output' '.docx' # NOTE: If you want to save the file as a .doc, use '.doc' instead of '.docx' here and ensure you use "com.adobe.acrobat.doc" in the jsObject.SaveAs call 

    ROOT_INPUT_PATH = sys.argv[1] 
    INPUT_FILE_EXTENSION = sys.argv[2] 
    ROOT_OUTPUT_PATH = sys.argv[3] 
    OUTPUT_FILE_EXTENSION = sys.argv[4] 

    # tuples are of schema (path_to_file, filename) 
    matching_files = ((os.path.join(_root, filename), os.path.splitext(filename)[0]) for _root, _dirs, _files in walk(ROOT_INPUT_PATH) for filename in fnmatch.filter(_files, INPUT_FILE_EXTENSION)) 

    # patch ERRORS_BAD_CONTEXT as per https://mail.python.org/pipermail/python-win32/2002-March/000265.html 
    global ERRORS_BAD_CONTEXT 
    ERRORS_BAD_CONTEXT.append(winerror.E_NOTIMPL) 

    for filename_with_path, filename_without_extension in matching_files: 
     print "Processing '{}'".format(filename_without_extension) 
     acrobat_extract_text(filename_with_path, ROOT_OUTPUT_PATH, filename_without_extension, OUTPUT_FILE_EXTENSION) 
관련 문제