Пример #1
0
def pdf2doc(file, filename, output_file, output_name):
    try:

        # upload soruce file to storage

        remote_name = file
        strformat = 'doc'
        request_upload = groupdocs_conversion_cloud.UploadFileRequest(
            remote_name, filename)
        response_upload = file_api.upload_file(request_upload)
        # Convert PDF to Word document
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = remote_name
        settings.format = strformat
        settings.output_path = output_name

        loadOptions = groupdocs_conversion_cloud.PdfLoadOptions()
        # Convert PDF to Word document
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = remote_name
        settings.format = strformat
        settings.output_path = output_name

        loadOptions = groupdocs_conversion_cloud.PdfLoadOptions()
        loadOptions.hide_pdf_annotations = True
        loadOptions.remove_embedded_files = False
        loadOptions.flatten_all_fields = True

        settings.load_options = loadOptions

        convertOptions = groupdocs_conversion_cloud.DocxConvertOptions()
        convertOptions.from_page = 1
        convertOptions.pages_count = 10

        settings.convert_options = convertOptions

        request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
        response = convert_api.convert_document(request)

        print("Document converted successfully: " + str(response))
        # upload source file to storage

        request_download = groupdocs_conversion_cloud.DownloadFileRequest(
            output_name)
        response_download = file_api.download_file(request_download)
        copyfile(response_download, f"{output_file}")

    except groupdocs_conversion_cloud.ApiException as e:
        print("Exception when calling get_supported_conversion_types: {0}".
              format(e.message))
    return render_template("index.html", script=f'<script>x=null</script>')
Пример #2
0
    def Run(self):
        # Create instance of the API
        api = Common_Utilities.Get_ConvertApi_Instance()

        try:
            settings = groupdocs_conversion_cloud.ConvertSettings()
            settings.storage_name = Common_Utilities.myStorage
            settings.file_path = "converted/topdf/password-protected.pdf"
            settings.format = "docx"

            loadOptions = groupdocs_conversion_cloud.PdfLoadOptions()
            loadOptions.password = "******"
            loadOptions.hide_pdf_annotations = True
            loadOptions.remove_embedded_files = False
            loadOptions.flatten_all_fields = True

            settings.load_options = loadOptions

            convertOptions = groupdocs_conversion_cloud.DocxConvertOptions()
            convertOptions.from_page = 1
            convertOptions.pages_count = 1

            settings.convert_options = convertOptions
            settings.output_path = "converted\\todocx"

            request = groupdocs_conversion_cloud.ConvertDocumentRequest(
                settings)
            response = api.convert_document(request)

            print("Document converted successfully: " + str(response))
        except groupdocs_conversion_cloud.ApiException as e:
            print("Exception while calling API: {0}".format(e.message))
Пример #3
0
    def Run(self):
        # Create instance of the API
        api = Common_Utilities.Get_ConvertApi_Instance()

        try:
            settings = groupdocs_conversion_cloud.ConvertSettings()
            settings.storage_name = Common_Utilities.myStorage
            settings.file_path = "conversions\\password-protected.docx"
            settings.format = "jpeg"

            loadOptions = groupdocs_conversion_cloud.DocxLoadOptions()
            loadOptions.password = "******"

            settings.load_options = loadOptions

            convertOptions = groupdocs_conversion_cloud.JpegConvertOptions()
            convertOptions.gray_scale = True
            convertOptions.from_page = 1
            convertOptions.pages_count = 1
            convertOptions.quality = 100
            convertOptions.rotate_angle = 90
            convertOptions.use_pdf = False

            settings.convert_options = convertOptions
            settings.output_path = "converted\\tojpeg"

            request = groupdocs_conversion_cloud.ConvertDocumentRequest(
                settings)
            response = api.convert_document(request)

            print("Document converted successfully: " + str(response))
        except groupdocs_conversion_cloud.ApiException as e:
            print("Exception while calling API: {0}".format(e.message))
def cloud_convert(app_sid, app_key):
    convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(app_sid, app_key)     # Create instance of the API
    file_api = groupdocs_conversion_cloud.FileApi.from_keys(app_sid, app_key)

    try:
        # upload source file to storage
        filename = input("Please enter the complete and correct file path of the required pdf: ")
        remote_name = filename
        output_name = remote_name.split('.')[0] + "docx"
        remote_name = filename
        strformat = 'docx'

        request_upload = groupdocs_conversion_cloud.UploadFileRequest(remote_name, filename)
        file_api.upload_file(request_upload)

# Extract Text from PDF document
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = remote_name
        settings.format = strformat
        settings.output_path = output_name
        request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
        response = convert_api.convert_document(request)
        print("Document converted successfully: " + str(response))

    except groupdocs_conversion_cloud.ApiException as e:
        print("Exception when calling get_supported_conversion_types: {0}".format(e.message))
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "WordProcessing/four-pages.docx"
        settings.format = "pdf"
        settings.convert_options = groupdocs_conversion_cloud.PdfConvertOptions(
        )

        watermark = groupdocs_conversion_cloud.WatermarkOptions()
        watermark.text = "Sample watermark"
        watermark.color = "Red"
        watermark.width = 100
        watermark.height = 100
        watermark.background = True

        settings.watermark_options = watermark
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Pdf/sample.pdf"
        settings.format = "docx"

        loadOptions = groupdocs_conversion_cloud.PdfLoadOptions()
        loadOptions.password = ""
        loadOptions.hide_pdf_annotations = True
        loadOptions.remove_embedded_files = False
        loadOptions.flatten_all_fields = True

        settings.load_options = loadOptions
        settings.convert_options = groupdocs_conversion_cloud.DocxConvertOptions(
        )
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
Пример #7
0
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Presentation/with_notes.pptx"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.PresentationLoadOptions()
        loadOptions.default_font = "Helvetica"
        loadOptions.font_substitutes = {
            "Tahoma": "Arial",
            "Times New Roman": "Arial"
        }

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
    def Run(self):
        # Create instance of the API
        api = Common_Utilities.Get_ConvertApi_Instance()
        
        try:
            settings = groupdocs_conversion_cloud.ConvertSettings()
            settings.storage_name = Common_Utilities.myStorage;
            settings.file_path = "conversions\\sample.docx"
            settings.format = "txt"
            
            loadOptions = groupdocs_conversion_cloud.DocxLoadOptions()
            loadOptions.hide_word_tracked_changes = True
            loadOptions.default_font = "Arial"
            
            settings.load_options = loadOptions;
            
            convertOptions = groupdocs_conversion_cloud.TxtConvertOptions()
            convertOptions.from_page = 1
            convertOptions.pages_count = 1
    
            settings.convert_options = convertOptions
            settings.output_path = None  # leave OutputPath will result the output as document IOStream
            
            request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
            response = api.convert_document_download(request)

            print("Document converted successfully: " + str(len(response)))
        except groupdocs_conversion_cloud.ApiException as e:
            print("Exception while calling API: {0}".format(e.message))
Пример #9
0
    def Run(self):
        # Create instance of the API
        api = Common_Utilities.Get_ConvertApi_Instance()
        
        try:
            settings = groupdocs_conversion_cloud.ConvertSettings()
            settings.storage_name = Common_Utilities.myStorage;
            settings.file_path = "conversions\\password-protected.docx"
            settings.format = "html"
            
            loadOptions = groupdocs_conversion_cloud.DocxLoadOptions()
            loadOptions.password = "******"
            
            settings.load_options = loadOptions;
            
            convertOptions = groupdocs_conversion_cloud.HtmlConvertOptions()
            convertOptions.fixed_layout = True
            convertOptions.use_pdf = False
            
            settings.convert_options = convertOptions
            settings.output_path = None  # leave OutputPath will result the output as document IOStream
            
            request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
            response = api.convert_document_download(request)

            print("Document converted successfully: " + str(len(response)))
        except groupdocs_conversion_cloud.ApiException as e:
            print("Exception while calling API: {0}".format(e.message))
    def Run(self):
        # Create instance of the API
        api = Common_Utilities.Get_ConvertApi_Instance()

        try:
            settings = groupdocs_conversion_cloud.ConvertSettings()
            settings.storage_name = Common_Utilities.myStorage
            settings.file_path = "conversions\\password-protected.docx"
            settings.format = "jpeg"

            loadOptions = groupdocs_conversion_cloud.DocxLoadOptions()
            loadOptions.password = "******"

            settings.load_options = loadOptions

            convertOptions = groupdocs_conversion_cloud.PdfConvertOptions()
            convertOptions.bookmarks_outline_level = 1
            convertOptions.center_window = True
            convertOptions.compress_images = False
            convertOptions.display_doc_title = True
            convertOptions.dpi = 1024
            convertOptions.expanded_outline_levels = 1
            convertOptions.fit_window = False
            convertOptions.from_page = 1
            convertOptions.pages_count = 1
            convertOptions.grayscale = True
            convertOptions.headings_outline_levels = 1
            convertOptions.image_quality = 100
            convertOptions.linearize = False
            convertOptions.margin_top = 5
            convertOptions.margin_left = 5
            convertOptions.password = "******"
            convertOptions.unembed_fonts = True
            convertOptions.remove_unused_streams = True
            convertOptions.remove_unused_objects = True
            convertOptions.remove_pdfa_compliance = False
            convertOptions.height = 1024

            settings.convert_options = convertOptions
            settings.output_path = "converted\\topdf"

            request = groupdocs_conversion_cloud.ConvertDocumentRequest(
                settings)
            response = api.convert_document(request)

            print("Document converted successfully: " + str(response))
        except groupdocs_conversion_cloud.ApiException as e:
            print("Exception while calling API: {0}".format(e.message))
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(Common.GetConfig())
        
        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "WordProcessing/four-pages.docx"
        settings.format = "xlsx"
        settings.convert_options = groupdocs_conversion_cloud.SpreadsheetConvertOptions()        
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
        
Пример #12
0
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Presentation/uses-custom-font.pptx"
        settings.format = "pdf"
        settings.output_path = "converted"
        settings.fonts_path = "font/ttf"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
    def Run(self, strformat, convertOptions):
        # Create instance of the API
        api = Common_Utilities.Get_ConvertApi_Instance()
        
        try:
            settings = groupdocs_conversion_cloud.ConvertSettings()
            settings.storage_name = Common_Utilities.myStorage;
            settings.file_path = "conversions\\sample.docx"
            settings.format = strformat
            settings.convert_options = convertOptions
            settings.output_path = "converted\\" + strformat
        
            request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
            response = api.convert_document(request)

            print("Document converted successfully: " + str(response))
        except groupdocs_conversion_cloud.ApiException as e:
            print("Exception while calling API: {0}".format(e.message))
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(Common.GetConfig())
        
        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Presentation/with_hidden_page.pptx"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.PresentationLoadOptions()
        loadOptions.show_hidden_slides = True

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
Пример #15
0
def doc2pdf(file, filename, output_file, output_name):
    request_upload = groupdocs_conversion_cloud.UploadFileRequest(
        file, filename)
    response_upload = file_api.upload_file(request_upload)
    # Create necessary API instances
    apiInstance = groupdocs_conversion_cloud.ConvertApi.from_keys(
        app_sid, app_key)

    # Prepare convert settings
    settings = groupdocs_conversion_cloud.ConvertSettings()
    settings.file_path = file
    settings.format = "pdf"

    load_options = groupdocs_conversion_cloud.DocxLoadOptions()
    load_options.password = "******"
    convert_options = groupdocs_conversion_cloud.PdfConvertOptions()
    convert_options.center_window = True
    convert_options.compress_images = False
    convert_options.display_doc_title = True
    convert_options.dpi = 1024.0
    convert_options.fit_window = False
    convert_options.from_page = 1
    convert_options.grayscale = False
    convert_options.image_quality = 100
    convert_options.linearize = False
    convert_options.margin_top = 5
    convert_options.margin_left = 5
    convert_options.unembed_fonts = True
    convert_options.remove_unused_streams = True
    convert_options.remove_unused_objects = True
    convert_options.remove_pdfa_compliance = False

    settings.load_options = load_options
    settings.convert_options = convert_options
    settings.output_path = "converted"
    result = apiInstance.convert_document(
        groupdocs_conversion_cloud.ConvertDocumentRequest(settings))
    request_download = groupdocs_conversion_cloud.DownloadFileRequest(
        f"converted/{output_name}")
    response_download = file_api.download_file(request_download)
    copyfile(response_download, f"{output_file}")
    # Convert
    return render_template("index.html", script=f'<script>x=null</script>')
Пример #16
0
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(Common.GetConfig())
        
        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Text/sample.txt"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.TxtLoadOptions()
        loadOptions.leading_spaces_sptions = "ConvertToIndent"
        loadOptions.detect_numbering_with_whitespaces = True

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Email/sample.msg"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.EmailLoadOptions()
        loadOptions.time_zone_offset = "05:00:00"

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Email/embedded-image-and-attachment.eml"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.EmailLoadOptions()
        loadOptions.convert_attachments = True

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Text/sample.txt"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.TxtLoadOptions()
        loadOptions.encoding = "shift_jis"

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
Пример #20
0
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Html/sample.html"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.HtmlLoadOptions()
        loadOptions.page_numbering = True

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "WordProcessing/with_tracked_changes.docx"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.WordProcessingLoadOptions()
        loadOptions.hide_word_tracked_changes = True

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
Пример #22
0
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Spreadsheet/sample.xlsx"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.SpreadsheetLoadOptions()
        loadOptions.show_grid_lines = True
        loadOptions.one_page_per_sheet = True

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Cad/Sample.dwg"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.CadLoadOptions()
        loadOptions.width = 1920
        loadOptions.height = 1080

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
Пример #24
0
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "WordProcessing/password-protected.docx"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.DocxLoadOptions()
        loadOptions.password = "******"
        convertOptions = groupdocs_conversion_cloud.PdfConvertOptions()
        convertOptions.center_window = True
        convertOptions.compress_images = False
        convertOptions.display_doc_title = True
        convertOptions.dpi = 1024.0
        convertOptions.fit_window = False
        convertOptions.from_page = 1
        convertOptions.grayscale = False
        convertOptions.image_quality = 100
        convertOptions.linearize = False
        convertOptions.margin_top = 5
        convertOptions.margin_left = 5
        convertOptions.password = "******"
        convertOptions.unembed_fonts = True
        convertOptions.remove_unused_streams = True
        convertOptions.remove_unused_objects = True
        convertOptions.remove_pdfa_compliance = False

        settings.load_options = loadOptions
        settings.convert_options = convertOptions
        settings.output_path = None  # set OutputPath as None will result the output as document file

        # Convert
        result = apiInstance.convert_document_download(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result)
Пример #25
0
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(Common.GetConfig())
        
        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "Email/sample.msg"
        settings.format = "pdf"

        loadOptions = groupdocs_conversion_cloud.EmailLoadOptions()
        fieldLabel = groupdocs_conversion_cloud.FieldLabel()
        fieldLabel.field = "From"
        fieldLabel.label = "Sender"
        loadOptions.field_labels = [fieldLabel]

        settings.load_options = loadOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
Пример #26
0
    def Run(cls):
        # Create necessary API instances
        apiInstance = groupdocs_conversion_cloud.ConvertApi.from_config(
            Common.GetConfig())

        # Prepare convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = "WordProcessing/four-pages.docx"
        settings.format = "html"
        convertOptions = groupdocs_conversion_cloud.HtmlConvertOptions()
        convertOptions.from_page = 1
        convertOptions.pages_count = 1
        convertOptions.fixed_layout = True
        convertOptions.fixed_layout_show_borders = True
        settings.convert_options = convertOptions
        settings.output_path = "converted"

        # Convert
        result = apiInstance.convert_document(
            groupdocs_conversion_cloud.ConvertDocumentRequest(settings))

        print("Document converted: " + result[0].url)
Пример #27
0
            app_sid, app_key)
        file_api = groupdocs_conversion_cloud.FileApi.from_keys(
            app_sid, app_key)

        # upload soruce file to storage
        filename = '02_pages.pdf'
        remote_name = '02_pages.pdf'
        output_name = 'sample.docx'
        strformat = 'docx'

        request_upload = groupdocs_conversion_cloud.UploadFileRequest(
            path_pdf, path_pdf)
        response_upload = file_api.upload_file(request_upload)

        # Convert PDF to Word document
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = path_pdf
        settings.format = strformat
        settings.output_path = output_name

        loadOptions = groupdocs_conversion_cloud.PdfLoadOptions()
        loadOptions.hide_pdf_annotations = True
        loadOptions.remove_embedded_files = False
        loadOptions.flatten_all_fields = True

        settings.load_options = loadOptions

        convertOptions = groupdocs_conversion_cloud.DocxConvertOptions()
        #convertOptions.from_page = 2
        #convertOptions.pages_count = 2
Пример #28
0
def pdfToDocx(filename, remote_name, output_name):
    app_sid = api_sid
    app_key = api_key
    print("KEYS accepted")
    # no. of pages in pdf file
    print(app.config['UPLOAD_FOLDER'] + remote_name)
    file = PdfFileReader(open(app.config['UPLOAD_FOLDER'] + remote_name, 'rb'))
    page_counts = file.getNumPages()
    print("Number of pages: ", page_counts)
    print("Download path: ", app.config['DOWNLOAD_FOLDER'] + output_name)
    # Create instance of the API
    convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(
        app_sid, app_key)
    file_api = groupdocs_conversion_cloud.FileApi.from_keys(app_sid, app_key)

    try:

        #upload soruce file to storage
        filename = filename
        remote_name = remote_name
        output_name = remote_name.rsplit('.')[0] + '.docx'
        strformat = 'docx'
        print(filename, remote_name, output_name)

        request_upload = groupdocs_conversion_cloud.UploadFileRequest(
            remote_name, filename)
        print("upload request")
        response_upload = file_api.upload_file(request_upload)
        print("uploaded to the cloud")
        #Convert PDF to Word document
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = remote_name
        settings.format = strformat
        settings.output_path = output_name
        print("converted to docx")

        loadOptions = groupdocs_conversion_cloud.PdfLoadOptions()
        loadOptions.hide_pdf_annotations = True
        loadOptions.remove_embedded_files = False
        loadOptions.flatten_all_fields = True

        settings.load_options = loadOptions

        convertOptions = groupdocs_conversion_cloud.DocxConvertOptions()
        convertOptions.from_page = 1
        convertOptions.pages_count = int(page_counts)

        settings.convert_options = convertOptions

        request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
        response = convert_api.convert_document(request)

        print("Document converted successfully: " + str(response))
        # Download request
        request_download = groupdocs_conversion_cloud.DownloadFileRequest(
            output_name)
        response_download = file_api.download_file(request_download)
        print("Response Download ", response_download)
        copyfile(response_download,
                 app.config['DOWNLOAD_FOLDER'] + output_name)

        print("Successful")
    except groupdocs_conversion_cloud.ApiException as e:
        print("Exception when calling get_supported_conversion_types: {0}".
              format(e.message))
        return render_template("api_exception.html")