Skip to content

Commit

Permalink
Now supporting also CheckBoxes and Promises.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpisto committed Apr 20, 2015
1 parent a6c8c5a commit 8debea5
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 58 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
<img src="http://res.cloudinary.com/tpisto/image/upload/v1428317033/pdf-fill-form-logo_rlfj7o.png" width="400"><br/>
**pdf-fill-form** is Node.js native C++ library for filling PDF forms. Created PDF file is returned back as Node.js Buffer object for further processing or saving - *whole process is done in memory*. Library offers methods to return filled PDF also as PDF file where pages are converted to images.
PDF Fill Form (**pdf-fill-form**) is Node.js native C++ library for filling PDF forms. Created PDF file is returned back as Node.js Buffer object for further processing or saving - *whole process is done in memory*. Library offers methods to return filled PDF also as PDF file where pages are converted to images.

Libary uses internally Poppler QT4 for PDF form reading and filling. Cairo is used for PDF creation from page images (when parameter { "save": "imgpdf" } is used).
##Features
* Supports reading and writing the following PDF form field types: TextField and Checkbox
* You can write following files:
* PDF
* PDF where pages are converted to images
* All the work is done in memory - no temporary files created
* Results are returned in Node.js Buffer -object
* Not using the PDFtk -executable - instead we use the Poppler library

##Examples
###Using promises
```javascript
var pdfFillForm = require('pdf-fill-form');

pdfFillForm.read('test.pdf')
.then(function(result) {
console.log(result);
}, function(err) {
console.log(err);
});
```
```javascript
var pdfFillForm = require('pdf-fill-form');
var fs = require('fs');

pdfFillForm.write('test.pdf', { "myField": "myField fill value" }, { "save": "pdf" } )
.then(function(result) {
fs.writeFile("test123.pdf", result, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
}, function(err) {
console.log(err);
});

```
###Using callbacks
To **read** all form fields:

```javascript
Expand Down Expand Up @@ -78,6 +116,7 @@ $ npm install pdf-fill-form
##Todo
* Tests
* Refactoring
* Support for other form field types than CheckBox and TextField

##Authors
- [Tommi Pisto](https://github.com/tpisto)
Expand Down
44 changes: 40 additions & 4 deletions lib/pdf-fill-form.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
(function () {
(function () {
"use strict";

var makePromises = function(myLib) {

// Read promise (sync)
myLib.read = function(fileName) {
return new Promise(function(resolve, reject) {
try {
var myFile = myLib.readSync(fileName);
resolve(myFile);
}
catch(error) {
reject(error);
}
});
}

// Write promise (async)
myLib.write = function(fileName, fields, params) {
return new Promise(function(resolve, reject) {
try {
myLib.writeAsync(fileName, fields, params, function(err, result) {
if(err) { reject(err); }
else {
resolve(result);
}
});
}
catch(error) {
reject(error);
}
});
}

return myLib;
}

try {
try {
module.exports = require(__dirname +'/../build/Debug/pdf_fill_form');
module.exports = makePromises(require(__dirname +'/../build/Debug/pdf_fill_form'));
} catch (e) {
module.exports = require(__dirname+'/../build/Release/pdf_fill_form');
module.exports = makePromises(require(__dirname+'/../build/Release/pdf_fill_form'));
}
} catch (e) {
console.log(e);
module.exports = require(__dirname+'/../build/default/pdf_fill_form');
module.exports = makePromises(require(__dirname+'/../build/default/pdf_fill_form'));
}
})();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": [
"pdf", "forms", "poppler", "qt4", "cairo"
],
"version": "0.1.3",
"version": "1.0.0",
"repository": {
"type": "git",
"url": "git://github.com/tpisto/pdf-fill-form.git"
Expand Down
Loading

0 comments on commit 8debea5

Please sign in to comment.