Skip to content
This repository has been archived by the owner on Dec 5, 2018. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lubos committed Oct 26, 2015
1 parent 370d5cd commit bf35742
Show file tree
Hide file tree
Showing 312 changed files with 109,697 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
@@ -1,2 +1,17 @@
# aws-lambda-wkhtmltopdf
Convert HTML to PDF using Webkit (QtWebKit) on AWS Lambda

## Input
{
"html" : "<!DOCTYPE html><html><body>Hello world</body></html>"
}

## Output
{
"filename": "8rqj9td0pvjf9a4i.pdf"
}

## Configuration

1. Open `config.js` and set `dstBucket` variable to name of S3 bucket where you want function to save output PDF files.
2. Make sure AWS Lambda function has `PutObject` access to S3 bucket
6 changes: 6 additions & 0 deletions config.js
@@ -0,0 +1,6 @@
dstBucket = 'your-s3-bucket-name';

process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];

module.exports = function() {
};
44 changes: 44 additions & 0 deletions index.js
@@ -0,0 +1,44 @@
var wkhtmltopdf = require('wkhtmltopdf');
var fs = require('fs');
var AWS = require('aws-sdk');
var config = require('./config.js');

var s3 = new AWS.S3();

exports.handler = function(event, context) {
return_data = {};
if (event.html) {

var output_filename = Math.random().toString(36).slice(2) + '.pdf';
var output = '/tmp/' + output_filename;

writeStream = fs.createWriteStream(output);

wkhtmltopdf(event.html, function(code, signal) {

s3.putObject({
Bucket : dstBucket,
Key : output_filename,
Body : fs.createReadStream(output),
ContentType : "application/pdf"
}, function(error, data) {

if (error != null) {
console.log("error: " + error);
} else {
console.log('upload done...');
}
return_data = {
filename : output_filename
};
// context.succeed("File has been uploaded");
context.done(null, return_data);
});

}).pipe(writeStream);
} else {
console.log('error');
context.done('unable to get the html', {});
}

};
68 changes: 68 additions & 0 deletions node_modules/aws-sdk/.jshintrc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions node_modules/aws-sdk/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions node_modules/aws-sdk/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bf35742

Please sign in to comment.