node-pdftk icon indicating copy to clipboard operation
node-pdftk copied to clipboard

function updateInfo only accepts a file path or JSON

Open meinte opened this issue 5 years ago • 5 comments

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.

meinte avatar Aug 23 '19 06:08 meinte

I have written a serialiser for the pdftk info format (from object to string and vice versa). Which makes it easier to add bookmarks and change other meta data. So I could create a PR, but hesitate to alter the updateInfo function signature > seems the core of most functions is that it will treat a bare string as if it is a pathname.

meinte avatar Aug 23 '19 06:08 meinte

PR created here; https://github.com/jjwilly16/node-pdftk/pull/29

meinte avatar Aug 24 '19 12:08 meinte

Sorry for the delay. Hopefully I will get to this sometime this week

jjwilly16 avatar Sep 16 '19 14:09 jjwilly16

Sorry, again for taking so long with this. Hope you're still interested.

After reviewing the code, I really like the better handling of the updateInfo method. I personally have never really used it, so didn't realize how many fields could be passed through.

The only thing I don't like is exposing the PdfTk class. Would it make sense to add two additional methods instead? Maybe updateInfoFromString and updateInfoUtf8FromString? Then the argument could be treated differently and we wouldn't be breaking any existing conventions.

jjwilly16 avatar May 11 '20 16:05 jjwilly16

Ah yes, I agree. I haven't looked at this thing in ages, but your suggestion sounds like a good solution.

meinte avatar May 17 '20 10:05 meinte