This repository has been archived by the owner on Dec 5, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
312 changed files
with
109,697 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dstBucket = 'your-s3-bucket-name'; | ||
|
||
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT']; | ||
|
||
module.exports = function() { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', {}); | ||
} | ||
|
||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.