Giter Site home page Giter Site logo

pdf-extract-s3's Introduction

pdf-extract-s3

AWS Lambda for extracting PDF to s3

Pseudo Code/Logic

  1. Download pdf to /tmp folder - since AWS Lambda is readonly file system
  2. Use the file name as folder and rename file to index.pdf as a convention
  3. Run poppler to:
  • extract embedded images with pattern: index-#pagenumber_#imagenumber.jpg
  • extract text and coordinates to: index.xml
  • convert pdf to 1600px jpg with pattern: jpeg-1600-page-#pagenumber.jpg
  • convert pdf to ppm with pattern: ppm-page-#pagenumber.ppm
  1. Upload to predefined s3 bucket - see Configuration

Input/Parameters

This can come in as query string in API Gateway.

url

Required. The url of pdf to download.

dest

Optional. The destination path to store into your bucket. Default is url path.

dpi

Optional. The dpi of the output jpeg. Default is 150 for smaller web size.

Output

  1. Error message as string.
  2. JSON result: { path: the path for directory listing, files: array of all files }

Configuration

Lambda method must have access to specific s3 bucket.

AWS_DEFAULT_BUCKET

Environment variable of destination bucket which can be configured in AWS API Gateway.

To build your own poppler:

  1. Start an AWS EC2 micro instance
  2. Follow instruction: https://github.com/pjfoley/poppler-for-lambda
  3. Edit: build.sh and update poppler version to latest: poppler-0.37.0.tar.xz to poppler-0.45.0.tar.xz or latest.
  4. Run yum update below to get cairo, jpeg, and png libs before build.
sudo yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel libpng-devel

AWS API Gateway body mapping template

application/json -> Select -> Method Request passthrough

pdf-extract-s3's People

Contributors

noogen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.