andruhovski icon

Python

andruhovski | PRO | 05/04/18 03:55:03 PM UTC | 0 ⭐ | 574 👁️ | Never ⏰ | []
text |

1.5 KB

|

None

|

0 👍

/

0 👎

import asposepdfcloud
from asposepdfcloud.apis.pdf_api import PdfApi
from asposepdfcloud.rest import ApiException
 import shutil
from shutil import copyfileobj
 class ExtractImageDemo(object):
    def __init__(self):
        # Get App key and App SID from https://aspose.cloud
        self.pdf_api_client = asposepdfcloud.api_client.ApiClient(
            app_key='10388331c432cb6cc0a71dfee12990f0',
            app_sid='f0556c59-e91b-44e2-847c-81049efd43bd')
        self.pdf_api = PdfApi(self.pdf_api_client)
     def getExtractedImage(self):
        file_name = 'Demo Catalog.pdf'
        opts = {
            "storage": "First Storage"
        }
         try:
            response = self.pdf_api.get_images(file_name, 1, **opts)
            if (response is not None and response.status == "OK"):
                images = [img for img in response.images.list if img.height==324 and img.width==243]  
                print("Found: %d images" % len(images))
                for imageItem in images:
                    imageNum=int(imageItem.links[0].href[1:])
                    image_from_pdf = self.pdf_api.get_image(file_name,1,imageNum,**opts)
                    print(image_from_pdf)
                    # with open("c:\\tmp\\python_demo"+imageItem.links[0].href[1:], 'wb') as out_file:
                    #     shutil.copyfileobj(image_from_pdf, out_file)
         except ApiException as e:
            print(e)
  textExtractor = ExtractImageDemo()
textExtractor.getExtractedImage()

Comments