Git Product home page Git Product logo

node-pdftk's People

Contributors

adrien2p avatar bsdkurt avatar estacioneto avatar individual11 avatar jjwilly16 avatar mattvague avatar msteinerweb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-pdftk's Issues

if pdftk waring, this program will throw err

i think this is a mistake in output method. when pdftk throw a waring, even if i set ignoreWarnings() , but not use, this programe still throw err . and then ,i found this code have mistake.

 if (!(this._ignoreWarnings && data.toString().toLowerCase().includes('error'))) {

it should be

 if (!(this._ignoreWarnings && !data.toString().toLowerCase().includes('error'))) {

miss '!' before data.toString()

More Verbose Logging

Is your feature request related to a problem? Please describe.
Every once in a while, when calling .output(), node-pdftk throws an error and the only information in the error message is the string "2" causing our logs to read ERROR: 2.

Describe the solution you'd like
A way to turn on more verbose logging to investigate the cause of the error. Is there a way to do this currently?

cat command creates empty PDF

Describe the bug
When I try to concatenate PDFs in an Express application, the resulting PDF is empty:

const documents = new Map();
documents.set('A', 'input1.pdf')
documents.set('B', 'input2.pdf')

const input_obj = Object.fromEntries(documents);
const cat_str = [ ... documents.keys()].join(' ');
const output = 'output.pdf';

pdftk
    .input(input_obj)
    .cat(cat_str)
    .output(output)
    .then(buffer => {
        // Do stuff with the output buffer
        documents.set('output', output)
        res.json(Object.fromEntries(documents))
    })
    .catch(err => {
        // handle errors
        res.json(err)
    });

The equivalent pdftk command on the command line succeeds:

pdftk A=input1.pdf B=input2.pdf cat A B output output.pdf

To Reproduce
Steps to reproduce the behavior:

  1. Run the above code
  2. Try opening output.pdf

Expected behavior
The generated file contains all input PDFs in the specified order.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Ubuntu
  • Version: 20.04.4 LTS (64-bit)

Additional context
N/A

EPIPE error on windows

Describe the bug
So I followed the examples quite thoroughly. However the .output() call fails with the following exception:

(node:21488) UnhandledPromiseRejectionWarning: Error: write EPIPE
    at Socket._writeGeneric (net.js:768:25)
    at Socket._write (net.js:787:8)
    at doWrite (_stream_writable.js:396:12)
    at writeOrBuffer (_stream_writable.js:382:5)
    at Socket.Writable.write (_stream_writable.js:290:11)
    at Socket.write (net.js:711:40)
    at _Promise ([...]\node_modules\node-pdftk\index.js:360:33)

it's thrown from the line child.stdin.write(this.stdin);

any ideas what could be causing it?

pdftk installed but showing as uninstalled

const pdftk = require('node-pdftk');
pdftk.configure({
bin: 'C:/Program Files (x86)/PDFtk Server/bin',
Promise: require('bluebird'),
ignoreWarnings: true,
});

pdftk
.input([textfile, change,log])
.output()
.then(buf => {
let path = './merged.pdf';
fs.open(path, 'w', function (err, fd) {
fs.write(fd, buf, 0, buf.length, null, function (err) {
fs.close(fd, function () {
console.log('wrote the file successfully');
});
});
});
});

This is my code. But the error i am getting is : pdftk was called but is not installed on your system.

I installed both pdftk and pdftk server. I set the pdftk_path variable to 'C:/Program Files (x86)/PDFtk Server/bin', in my environment variables too.

I configured the same through options. But still i am getting the error.

Please help me

Accept number inputs

Is your feature request related to a problem? Please describe.
Currently, this pdftk library will throw an error upon inputting a JSON with number property (e.g. {"some_field": 1}).

Describe the solution you'd like
It would be good if the library will accept numbers, by converting it to string automatically. This should be achievable by using JS's Number.prototype.toString() or some other way.

Describe alternatives you've considered
At least, it should be documented clearly that pdftk doesn't take numbers

using array input cat command fails for empty arguments

When using an array as input for cat command (no handles), these problems occur:
no argument given for catCommand
pdftk.input([a, b]).cat()
throws error (split method called on undefined)

empty string as catCommand
pdftk.input([a, b]).cat('')
only first file "a" used, all others ignored.

pdftk.input([a, b]).cat(' ')
only first file "a" used, all others ignored.

pdftk.input([a, b]).cat([])
works as expected

.cat() with Buffers

the .cat() method isn't working with buffers as input.

" does not exist at Function.input (/node_modules/node-pdftk/index.js:88:68) at pdftk.input.stamp.output.then.catch.then.buffer (/index.js:108:6) at <anonymous>

when outputting the used buffers as files and then cat, it works as expected.

pdftk .input({ A: fs.readFileSync('./page1.pdf'), B: './page2.pdf', }) .cat('A B')

Cannot select multiple options on listbox

Describe the bug

  • It's not possible to select multiple options from listbox

To Reproduce

  • Select a pdf that has a form with listbox field
  • Fill the form with node-pdftk
  • Attempt to select one option (works fine)
pdftk
        .input('./my.pdf')
        .fillForm({
'listbox': 'option1'
})

Matching FDF for field fill

<<
/V (option1)
/T (listbox)
>> 
  • Attempt 1 to select two options (not working)
pdftk
        .input('./my.pdf')
        .fillForm({
'listbox': 'option1,option2'
})

Matching FDF

<<
/V (\(item1,item2\))
/T (listbox)
>> 
  • Attempt 2 to select two options (not working)
pdftk
        .input('./my.pdf')
        .fillForm({
'listbox': ['option1','option2']
})

Matching FDF

<<
/V (item1,item2)
/T (listbox)
>>

Expected behavior

  • both options should be selected in the pdf

Desktop :

  • OS: Linux Debian
  • Version 11
  • node-pdftk version: 0.14.0

Additional context

  • Seamlessly, it's not possible to select multiple options of listbox with FDF, even after testing with pdftk from the cli it was not possible to select multiple options.
  • Apparently with XFDF it's possible to select multiple options for a listbox with the following xml
<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields>
<field name="listbox">
<value>option1</value>
<value>option2</value>
</field>
</fields>
</xfdf>

PDFs created with `node-pdftk` do not open on Chrome for iOS

Describe the bug
PDFs do not open on iOS Chrome. I've tested Safari on iOS, Chrome and Firefox on Android, Chrome, Firefox and Chromium Edge on Windows and Mac, and Safari on Mac. All work, just not that iOS Chrome.

I'm porting code from an old PHP app, and the PDFs the PHP version creates will open in iOS Chrome.

To Reproduce
Steps to reproduce the behavior:

const buffer: Buffer = await pdftk
  .input(blankPdfPath)
  .fillForm(data)
  .flatten()
  .output();

Buffer is then uploaded to S3.

I tested that the PDF that's input can be opened in Chrome just fine.

PDF does not open. It downloads and asks what to open the file with (choosing Chrome again does not work).

Expected behavior
PDF should open in Chrome.

System info that creates PDF:

  • Node version: 12
  • OS: Ubuntu
  • OS Version: 18.04, I believe

System info trying to open PDF:

  • OS: iOS
  • OS Version: 13
  • Browser: Chrome
  • Browser Version: any

Any other info?
I don't know what else might help you here... do you want one of the generated PDFs or the input PDF?

problem with euro sign when fill form

Hello. When I try to send euro sign €, the result is ¬

I try to type it directly
const data = {
value: '10 €'
}

or like this
const data = {
value:'10 '+ String.fromCharCode(8364)
}

I'have the problème on Windows 10 and on Linux Alpine.

I try with node-pdftk 2.0.1 and 1.3

ps: It work in PHP with php-pdftk and the same pdf in input.

How to split the pdf into pages

Any sample code snippet to use this package to split the pdf into separate pages ?
It will be very useful if we can get one ..

Thank you !

Cannot set the checkbox when filling PDF.

Describe the bug
Cannot set the checkbox when filling PDF.

To Reproduce
I have dumbed the avalaible fields.

$ pdftk some_pdf.pdf dump_data_fields_utf8
---
FieldType: Button
FieldName: Zaškrtávací pole 01
FieldFlags: 0
FieldJustification: Left
FieldStateOption: Ano0
FieldStateOption: Ano1
FieldStateOption: Ano2
FieldStateOption: Ano3
FieldStateOption: Ano4
FieldStateOption: Ano5
FieldStateOption: Ano6
FieldStateOption: Off

trying to set it using :

pdftk
            .input(originalPdfPath)
            .fillForm({
               'Zaškrtávací pole 01' : 'Ano0',
               'Textové pole3' : 'Test using UTF8 field name',
             })
            .output()
            .then(buffer => {

                return buffer;
            }).catch((e) => {
                console.error(e)
            })
  • The textfield 'Textové pole3' gets filled (so i guess UTF8 is not a problem)
  • the checkbox doesn't, even after renaming it to "field1" etc.

Expected behavior
Fill the checkbox

Desktop (please complete the following information):

  • Windows 10

Null values FDF bug fixes not deployed to npm in 2.1.2

Describe the bug
Hi @jjwilly16

first of all thank you very much for this great package.
In version 2.1.2, a bugfix was pushed that ignores null fields in the payload with 5c91fe8

Unfortunately it seems as if this change was not published to npm in 2.1.2
To Reproduce
Steps to reproduce the behavior:

  1. Create a new dummy project in a temporary directory with
npm init -y
  1. Install node-pdftk package
npm i node-pdftk

and verify in package_lock.json that the currently installed version is 2.1.2

"node-pdftk": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/node-pdftk/-/node-pdftk-2.1.2.tgz",
      "integrity": "sha512-xapuoppEweAHOLdolxinm3kmEGtQSrWxu5M3fnu+Y3ABpVGx+Xc4NpeGahTVRdFMGhufLyyoBNnUJPUwXVNU9A=="
    }
  1. Navigate to node_modules/node-pdftk/index.js and search for the generateFdfFromJSON method (starts at line 188).

Note that in line 204, we have the following if statement

if (data.hasOwnProperty(prop)) {

However I think it should actually be

if (data.hasOwnProperty(prop) && data[prop] !== null && data[prop] !== undefined) {

because there is a commit as of Github version 2.1.2 which fixes the FDF null bug: 5c91fe8

Because of this the FDF form filling still fails if any of the fields is null with the 2.1.2 version of this package installed via npm

Expected behavior
The bugfix that is already on master should also be pushed to npm so that FDF files can be generated even if fields are null.

The solution would be to push the latest changes to npm.

Does pdftk use iText java lib

Hi,
This is not an issue but a question. I was getting an exception using pdftk v 2.02 and the stacktrace has reference to the iText lib author Lowagie.

Unhandled Java Exception in create_output():
java.lang.ArrayIndexOutOfBoundsException: 0
at pdftk.com.lowagie.text.pdf.DocumentFont.fillEncoding(pdftk)

On googling I found Lowagie himself commenting that pdftk is using an obsolete version of iText lib.
My question is, is the pdftk version 2 still using iText lib as I got the above exception with pdftk version 2? If yes, which version of iText is being used in the current version of pdftk?

Thanks
Shaleen

function updateInfo only accepts a file path or JSON

Describe the bug
The function 'updateInfo' will assume that if the parameter 'data' is a string, that it is in fact a path to a file which contains the info to be updated. If it is not a string it will assume it's an object which can be serialised to something pdftk can work with through 'generateInfoFromJSON'.

The issue is two fold; Firstly, I would like to have a way to provide a string that is simply passed on, instead of treated as if it is a path. I could serialise it into a JSON, but herein lies the second issue; the function 'generateInfoFromJSON' does not fully support everything that can be thrown at pdftk (notably; bookmarks)

To Reproduce
Pass a string to 'updateInfo'; it tries to load it as a file.

Expected behavior
I would like to be able to pass a string and simply be passed to pdftk, either because of the addition of a flag ('isFile'?) or some other mechanism. Alternatively, 'generateInfoFromJSON' could be changed to support all the info that can be supported.

App crashes when deploying to heroku

I have this working fine locally, but it's crashing after deploying to heroku. Is it possible to get it working with Heroku?

Ideally I would have a PDF form auto generated this way.

Stamp Method does not call Then or Catch

I have the following piece of code:


addWatermark: (input, output, cb) => {
        pdftk
            .input(input)
            .stamp('./pdftools/logo.pdf')
            .output(output)
            .then((buffer) => {
                logger.info('WATTERMARK-APPLYING-LOG: going to call watermarkCallback');
                cb("", "pdf has been branded", "");
            })
            .catch((err) => {
                logger.info("PDF-BRANDING - WATTERMARK-APPLYING-ERROR: " + err);
                cb(err, null, err);
            });

    }

It's a pretty straight forward piece of code, no magic, nothing really to it, just vanilla node-pdftk.
It executes the input method, then the stamp one, and the output.
The problem is that it never reaches the Then, and Catch methods. It just falls outside the method.

I tried many different approaches, but I cannot seem to find the reason.

Input, output, and cb params are loaded correctly, but yet, Then and Catch do not work.

I'm using node-pdfk v 1.3.0

edit: I've updated to node-pdftk v 1.3.1 (latest) and the bug continues.

pdftk error if permissions passed as concatenated string

Describe the bug
When you set permissions in pdftk if number of permissions are more then one, pdftk return error about unexpected data in output section.
For example:

Error: Unexpected data in output section:
      FillIn CopyContents
Exiting.
Errors encountered.  No output created.
Done.  Input errors, so no output created.

It occurs when permission array passed in spawn like concatenated string.

To Reproduce
Steps to reproduce the behavior:

const pdftk = require('node-pdftk');

// Works
pdftk
    .input(['Turgor.pdf'])
    .allow(['FillIn'])
    .output('Turgor_secured.pdf')
    .then(() => {
        console.log('done 1 ');
    })
    .catch(err => {
        console.log(1, err);
    });

// Don't works
pdftk
    .input(['Turgor.pdf'])
    .allow(['FillIn', 'CopyContents'])
    .output('Turgor_secured.pdf')
    .then(() => {
        console.log('done 2');
    })
    .catch(err => {
        console.log(2, err);
    });

Expected behavior
Create a pdf file with proper permissios without error.

Output Format?

    return pdftk.input('MASTER_test.pdf').fillForm(data).flatten().output(fileName);

Saves the file locally on the server with fileName
and sends back the buffer but in numerics/numbers 378068704549465410372262.....

was expecting to see something like
%PDF-1.4
%����
1 0 obj

Is the buffer formatted? how do we get from numbers to ASCII text

I tried

private bin2string(array) {
        var result = "";
        for (let idx = 0; idx < array.length; idx++) {
            result += String.fromCodePoint(array[idx]);
        }
        return result;
    }

Which is close I get
%PDF-1.4
%âãÏÓ <<-- this is wrong
1 0 obj

Thanks

Bursting a PDF with owner password set and warnings ignored throws error

Describe the bug
When attempting to burst a PDF that has an owner password set, node-pdftk throws an error with the warning from pdftk even though ignoreWarnings is set to true and pdftk returns a 0 exit code from the same command.

To Reproduce
Grab this PDF to use for input in the below code: http://www.orimi.com/pdf-test.pdf
Code to reproduce:

const pdftk = require('node-pdftk')
pdftk.configure({ignoreWarnings: true})
pdftk.input('/tmp/pdf-test.pdf').burst().then(() => console.log('Success')).catch((err) => console.error(err))

Output:

Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: { error: [Function: debugDomainError] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] } }
> WARNING: The creator of the input PDF:
   /tmp/pdf-test.pdf
   has set an owner password (which is not required to handle this PDF).
   You did not supply this password. Please respect any copyright.

Running pdftk /tmp/pdf-test.pdf burst outputs the warning but returns a 0 exit code.

Expected behavior
An error shouldn't be thrown since I'm ignoring warnings.

Tests?

Hey there,

Library looks nice! I'd like to use it for a project, but I'm a little hesitant because I don't see any tests. Is this something you'd accept a PR for?

MacOS note re: pdftk version

PDFTk unfortunately does not link to the most recent MacOS version from their home page. So if a user of your library uses MacOS >= 10.11, PDFTk won't work at all but they'll likely blame the wrapper.

The correct PDFTk version is at https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg

I emailed the author to update his page but this has been an open issue for a year: https://stackoverflow.com/questions/39750883/pdftk-hanging-on-macos-sierra

Insert Images

Is your feature request related to a problem? Please describe.
I was wondering if it would be possible to insert images.

Describe the solution you'd like
Pass a dataUri or ArrayBuffer on the data object and insert the image.

Thanks for all your work on this library. It works great!

Function generateFdfFromJSON throwing First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object Error

I'm using the fillForm method, passing one JSON Object as designed. My node-pdftk version is 5.5.1, node -v: 8.9.3.
It keeps throwing the following error, with the following stack, no matter how hard I try to stick to the pattern:

TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object. at Function.Buffer.from (buffer.js:202:9) at Function.generateFdfFromJSON (/src/node_modules/node-pdftk/index.js:181:28) at PdfTk.fillForm (/src/node_modules/node-pdftk/index.js:439:52) at Object.fillForm (/src/routes/pdf/pdf_worker.js:33:14) at Object.createContractJob (/src/routes/core/flag_step.js:301:24) at callback (/src/routes/listeners/robot_signals.js:21:14) at SubscriptionDefinition.invokeSubscriber (/src/node_modules/postal/lib/postal.js:172:19) at /src/node_modules/postal/lib/postal.js:529:21 at /src/node_modules/postal/lib/postal.js:418:5 at arrayEach (/src/node_modules/lodash/lodash.js:537:11) at Function.forEach (/src/node_modules/lodash/lodash.js:9359:14) at /src/node_modules/postal/lib/postal.js:538:7 at /src/node_modules/lodash/lodash.js:4944:15 at baseForOwn (/src/node_modules/lodash/lodash.js:3001:24) at /src/node_modules/lodash/lodash.js:4913:18 at Function.forEach (/src/node_modules/lodash/lodash.js:9359:14)

As said, the FDF content is in proper json format, here it is:

{ fdf: { city: 'Zug', city_1: 'Zug', city_2: 'Zug', city_3: 'Zug', company_address: 'Gubelstrasse 12, 6300', company_address_1: 'Gubelstrasse 12, 6300', company_address_2: 'Gubelstrasse 12, 6300', company_address_3: 'Gubelstrasse 12, 6300', zip: '88584', zip_1: 'Gubelstrasse 12, 6300', zip_2: 'Gubelstrasse 12, 6300', zip_3: 'Gubelstrasse 12, 6300', date: 'Fri Jan 05 2018 07:47:39 GMT+0000 (UTC)', date_1: 'Fri Jan 05 2018 07:47:39 GMT+0000 (UTC)', date_2: 'Fri Jan 05 2018 07:47:39 GMT+0000 (UTC)', signature_date: 'Fri Jan 05 2018 07:47:39 GMT+0000 (UTC)', date_end: 'Thu Apr 05 2018 07:47:39 GMT+0000 (UTC)', hour_rate: '30 Euros', client_name: 'André', client_name_1: 'André', client_name_2: 'André', client_name_3: 'André', city_zipcode: '88485000' }, contract_id: '5a4f889b81d40e457ef2dd38' }

How can I fix that?

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.