Advertisement
andruhovski

Python

May 4th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import asposepdfcloud
  2. from asposepdfcloud.apis.pdf_api import PdfApi
  3. from asposepdfcloud.rest import ApiException
  4.  
  5. import shutil
  6. from shutil import copyfileobj
  7.  
  8. class ExtractImageDemo(object):
  9. def __init__(self):
  10. # Get App key and App SID from https://aspose.cloud
  11. self.pdf_api_client = asposepdfcloud.api_client.ApiClient(
  12. app_key='10388331c432cb6cc0a71dfee12990f0',
  13. app_sid='f0556c59-e91b-44e2-847c-81049efd43bd')
  14. self.pdf_api = PdfApi(self.pdf_api_client)
  15.  
  16. def getExtractedImage(self):
  17. file_name = 'Demo Catalog.pdf'
  18. opts = {
  19. "storage": "First Storage"
  20. }
  21.  
  22. try:
  23. response = self.pdf_api.get_images(file_name, 1, **opts)
  24. if (response is not None and response.status == "OK"):
  25. images = [img for img in response.images.list if img.height==324 and img.width==243]
  26. print("Found: %d images" % len(images))
  27. for imageItem in images:
  28. imageNum=int(imageItem.links[0].href[1:])
  29. image_from_pdf = self.pdf_api.get_image(file_name,1,imageNum,**opts)
  30. print(image_from_pdf)
  31. # with open("c:\\tmp\\python_demo"+imageItem.links[0].href[1:], 'wb') as out_file:
  32. # shutil.copyfileobj(image_from_pdf, out_file)
  33.  
  34. except ApiException as e:
  35. print(e)
  36.  
  37.  
  38. textExtractor = ExtractImageDemo()
  39. textExtractor.getExtractedImage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement