2012-07-05 8 views
7

मेरा .NET एप्लिकेशन को पीडीएफ दस्तावेज को प्रोग्राम प्रारूप में वर्ड प्रारूप में बदलने की जरूरत है।एक्रोबैट एसडीके का उपयोग कर पीडीएफ में वर्ड को कैसे परिवर्तित करें?

मैंने कई उत्पादों का मूल्यांकन किया और Acrobat X Pro पाया, जो विकल्प के रूप में सहेजता है जहां हम दस्तावेज़ को Word/Excel प्रारूप में सहेज सकते हैं। मैंने एक्रोबैट एसडीके का उपयोग करने की कोशिश की लेकिन कहां से शुरू करना उचित दस्तावेज नहीं मिला।

मैं उनके आईएसी नमूना में देखा लेकिन नहीं समझ सकता है कैसे मेनू आइटम कहते हैं और यह अमल विकल्प के रूप में बचाने के लिए बनाने के लिए।

उत्तर

0

एडोब, वर्ड रूपांतरण के लिए PDF का समर्थन नहीं करता जब तक कि आप अपने एक्रोबेट पीडीएफ ग्राहक का उपयोग कर रहे हैं। Maeaning आप इसे अपने एसडीके के साथ नहीं कर सकते हैं और न ही कमांड लाइन को कॉल करके। आप इसे मैन्युअल रूप से कर सकते हैं।

+0

समाधान या तो jle द्वारा पोस्ट की गई या मुझे इस प्रोग्राम के रूप में प्राप्त करने के लिए तरीके दिखा। यदि आपके पास एक्रोबैट एक्स प्रो है, तो आप मेरी स्क्रिप्ट को आजमा सकते हैं क्योंकि इसे WinPython x64 2.7.6.3 इंस्टॉल करने के बाद बॉक्स से बाहर काम करना चाहिए (जो मुफ़्त है) – Subhobroto

13

आप एक्रोबेट एक्स प्रो के साथ ऐसा कर सकते हैं, लेकिन आप सी # में जावास्क्रिप्ट एपीआई का उपयोग करने की जरूरत है।

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 फाइलों को कवर करना है, तो इसमें 5 घंटे से अधिक समय लगेगा .. क्या इसके लिए एक तेज तरीका है? –

+0

मैंने फ़ाइल को अनलॉक करने के अंत में एक pdfd.Close() जोड़ा। – r03

1

मैं बहुत WinPython 64 2.7.6.3 और एक्रोबेट एक्स Pro का उपयोग कुछ इसी तरह किया था और JSObject इंटरफेस का इस्तेमाल किया DOCX को पीडीएफ़ कन्वर्ट करने के लिए। अनिवार्य रूप से jle's के समान समाधान।

निम्नलिखित कोड की एक पूरी टुकड़ा है कि DOCX के लिए पीडीएफ़ का एक सेट धर्मान्तरित होना चाहिए:

# 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) 
संबंधित मुद्दे

 संबंधित मुद्दे