dommmel / fill-pdf Goto Github PK
View Code? Open in Web Editor NEWA node module to fill out pdf forms (utf8 compatible).
License: MIT License
A node module to fill out pdf forms (utf8 compatible).
License: MIT License
pdftk
has a generate_fdf
operation which appears to be completely different from this module's generateFdf
. Renaming it would be best, but a comment in the code or a note on the README would help too.
For me it's working when i don't use any form Data, but as soon as i try to do something like this:
var formData={Nachname:"hallasdasdo"};
fillPdf.generatePdf(formData,file, function(output) {
console.log("output");
console.log(output);
fs.writeFile(fileDestination, output, pdfCompleteCallback)
});
I get this Error:
stderr: Unhandled Java Exception in create_output():
stderr: java.lang.ArrayIndexOutOfBoundsException: 0
at pdftk.com.lowagie.text.pdf.DocumentFont.fillEncoding(pdftk)
at pdftk.com.lowagie.text.pdf.DocumentFont.doType1TT(pdftk)
at pdftk.com.lowagie.text.pdf.DocumentFont.(pdftk)
at pdftk.com.lowagie.text.pdf.AcroFields.getAppearance(pdftk)
at pdftk.com.lowagie.text.pdf.AcroFields.setField(pdftk)
at pdftk.com.lowagie.text.pdf.AcroFields.setFields(pdftk)
Any Ideas?
Could you please add release notes detailing what breaking changes came with version 1.0.0?
I've seen people add a CHANGELOG.md
and/or add release notes here.
Can i use it on windows platform?
Hey there,
I'm getting a very vague error when trying to fill a pdf - Error: spawn pdftk ENOENT
For reference, I am able to pass the same data to pdf-fill-form with no issue. I would rather use your library, since the only dependency is pdftk, and that makes it easy to run on an AWS Lambda instance.
Any idea what could be going on/how to fix? I can provide more information if necessary
I've been getting this error on one of our servers and I'm really confused about it. Here is the full dump
{ [Error: Command failed: gs -dNOCACHE -sDEVICE=pdfwrite -sOutputFile=/tmp/116419-18385-13yaogd.pdf -dbatch -dNOPAUSE -dQUIET /tmp/116419-18385-1c8wdss.pdf -c quit
GPL Ghostscript 9.10: Unrecoverable error, exit code 1
]
killed: false,
code: 1,
signal: null,
cmd: 'gs -dNOCACHE -sDEVICE=pdfwrite -sOutputFile=/tmp/116419-18385-13yaogd.pdf -dbatch -dNOPAUSE -dQUIET /tmp/116419-18385-1c8wdss.pdf -c quit' }
[Error: Non 0 exit code from pdftk spawn: 1]
{ [Error: Command failed: gs -dNOCACHE -sDEVICE=pdfwrite -sOutputFile=/tmp/116419-18385-w4famo.pdf -dbatch -dNOPAUSE -dQUIET /tmp/116419-18385-gssdlb.pdf -c quit
GPL Ghostscript 9.10: Unrecoverable error, exit code 1
]
killed: false,
code: 1,
signal: null,
cmd: 'gs -dNOCACHE -sDEVICE=pdfwrite -sOutputFile=/tmp/116419-18385-w4famo.pdf -dbatch -dNOPAUSE -dQUIET /tmp/116419-18385-gssdlb.pdf -c quit' }
Can you please update the iconv version? There are some bugs preventing the current version from working on Node 6.2.
Also, it might be possible to switch to iconv-lite, depending on what features are in use.
I had an issue when passing an absolute path to the generatePdf
function. My path looked something like this /srv/www/api/services/../../assets/template.pdf
because this path is generated dynamically using __dirname
, I temp. fixed this issue by removing __dirname
from the generatePdf
in https://github.com/dommmel/fill-pdf/blob/master/index.js#L60 , but I didn't raise a pull request because I didn't test it thoroughly.
HINT: I can't use relative paths, because fill-pdf
module is installed locally in a different folder than where it is installed on my production env. but my api code / folder structure is the same, that's why am forming the path to the .pdf template from the service.
Cant get it to work properly with special characters lite åäö. Works fine with normal latin characters.
After some digging I think the problem is with pdftk and how it handles fonts, but im not certain.
php-pdftk is solving it with need_appearances I think.
https://github.com/mikehaertl/php-pdftk
Have tested with /test/resources/test.pdf
pdftk 2.02
fill-pdf 0.5.0
Hello,
I can't check thecheckboxes of this PDF: https://www.formulaires.service-public.fr/gf/cerfa_14952.do
The name of the checkboxes are:
FieldName: topmostSubform[0].Page1[0].Case_?_cocher12[0]
FieldName: topmostSubform[0].Page1[0].Case_?_cocher29[0]
FieldName: topmostSubform[0].Page2[0].Case_?_cocher8[0]
FieldName: topmostSubform[0].Page2[0].Case_?_cocher14[0]
I tried to set the values to "On", "Yes", "checked", 1.
Thanks for solving this ;)
any idea/solution?
Hi, thanks for the module.
It took me a while to figure out how to flatten the generated pdf.
it would be nice to have an example that involves passing args to pdftk and optionally available options and what they do.
😃
pdftk /Users/Desktop/medical/node_modules/fill-pdf/test.pdf fill_form - output /var/folders/bg/z3yjjyjj1g3d3w3sxdvsjyy80000gn/T/11686-1158-1knf4m9.pdf
process just hangs, am I missing something?
I was trying to fill a PDF form and I have got this exception, but I couldn't figure out what is happening. I tried to open the PDF form and manually fill it with the same data and I didn't notice any issue, except I found it is formatting my inputs (i.e if I type 9999999999 in phone number, it replaces it with (999) 999-9999)
stderr: Unhandled Java Exception:
java.lang.ClassCastException: com.lowagie.text.pdf.PRIndirectReference cannot be cast to com.lowagie.text.pdf.PdfNumber
at com.lowagie.text.pdf.PdfReader.getNormalizedRectangle(pdftk)
at com.lowagie.text.pdf.AcroFields.getAppearance(pdftk)
at com.lowagie.text.pdf.AcroFields.setField(pdftk)
at com.lowagie.text.pdf.AcroFields.setFields(pdftk)
debug: Generating - Error:
Error: Non 0 exit code from pdftk spawn: 2
at ChildProcess.<anonymous> (/var/tmp/sharpone/node_modules/fill-pdf/index.js:68:16)
at ChildProcess.emit (events.js:98:17)
at Process.ChildProcess._handle.onexit (child_process.js:820:12) [Error: Non 0 exit code from pdftk spawn: 2]
It throws this error: { "code": "EPIPE", "errno": "EPIPE", "syscall": "write" }
Hello! I faced with issue that parenthesis not escaped by your module.
I not sure is it issue or not. Probably I need escape them from my side, before pass field values to your module.
What do you think about it?
Is it make sense escape parenthesis in the line 22, e.g:
var value = data[name].toString().replace('\r\n','\r').replace(/(?=[()])/g, '\\');
Thanks!
I'd like to add a digital signature to a template PDF as well as the form fields. I appreciate creating the digital signature is out of the scope of this project (I've already written such logic using canvas) but I'd like to insert the generated signature image into the PDF in a fixed location.
Right now the directory where template files are supposed to be located is hardcoded to the ./app
directory of the project root.
https://github.com/dommmel/fill-pdf/blob/master/index.js#L58
I think it would be wise to be able to specify where the templates are located yourself, using __dirname
etc. might be a bit bothersome but it makes for a much more flexible project.
However, this would be a breaking change so I would really like input from @dommmel before I start working on a pull request.
I'm facing issue with pdftk on mac. Apparently it cannot generate pdf:
fillPdf.generatePdf({ name: 'alex' }, `${__dirname}/fixtures/form.pdf`, (err, output) => {
if (err) {
console.log(err)
} else {
console.log(output)
}
})
{ Error: ENOENT: no such file or directory, open '/tmp/119219-94314-hv0ys2.14oi.pdf'
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/tmp/119219-94314-hv0ys2.14oi.pdf' }
Error: ENOENT: no such file or directory, open '/tmp/119219-94314-hv0ys2.14oi.pdf'
pdftk is installed:
pdftk --version
pdftk 2.02 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit: www.pdftk.com
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Is it possible to mark checkboxes with the package in it's current version?
Before fill-pdf hits 1.0.0, there are few major items that, I believe, should probably be ironed out:
generateFdf()
to not use so many Buffer objects, it is quite costly especially when creating larger FDF documents.generatePdf()
returns a Buffer object, of the entire PDF, from readFile of the temporary result PDF. It would be nice to support 3 possible return modalities:
__dirname
, however this should probably be extended to fetch from anywhere in the filesystem.pdftk
can take care of 90% of the end-users use case, and GhostScript might be more of a superfluous dependency(it can be quite costly since the OS needs to setup another child_process for it)Let me know what you think.
You forgot to add this dependency in your package.json
npm install --save iconv
Is there a way to pass in a readStream or something from an API instead of a local path? thanks!
Any possible way to set font size? I have a form with limited room for input, and need to lower the font size to get data to fit.
I'm doing some form filling and have to accommodate Japanese text. This does not seem to be supported with the default options.
let FillData = {
text: 'ベルゼルグ王国第一王女 アイリス'
}
fillPdf.generatePdf(FillData, Form.path, function(err, output) {
if ( !err ) {
res.type("application/pdf");
res.send(output);
}
});
This will output a pdf with my text field filled with:
ã…Žã…«ã‡¼ã…«ã‡°ç”‰åł½ç¬¬ä¸•ç”‰å¥³ ㇢㇤ㅪㇹ
How do I configure this to allow the correct encoding?
This library has been great, but I couldn't get it to work with checkboxes? I was using your example pdf, and the checkboxes were not being selected.
I provided a small snippet of what I've been testing and when setting PHD to 'Yes' it does not select the checkbox still.
router.get('/test.pdf', function (req, res) {
let formData = {
Name_Last: 'Doe',
Name_First: 'John',
Name_Middle: '(Sir) Francis',
Telephone_Home: 1112223333,
Sex: 'MALE',
Address_2: '232343423',
City: 'Annapolis',
STATE: 'MD',
ZIP: 22334,
PHD: 'Yes',
TRADE_CERTIFICATE: 'Yes',
PARENS: 'a)\n>>\n<<\n/T (Name_Last)\n/V (VALUE NOT ESCAPED)\n>>\n<<\n/T (asdf)\n/V ('
};
fillPdf.generatePdf(formData, `${__dirname}/test.pdf`, function (err, output) {
if (!err) {
res.type("application/pdf");
res.send(output);
}
});
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.