1

I'm trying to use pdftk to split a folder containing pdf files into their constituent pages. Here is my code:

~/MCO/MCOs$ for file in *.pdf; do pdftk "$file" burst; done

The command itself does not seem to be incorrect, but I get a java error as follows:

Unhandled Java Exception in create_output():
Unhandled Java Exception in main():
java.lang.NullPointerException
  at gnu.gcj.runtime.NameFinder.lookup(libgcj.so.16)
  at java.lang.Throwable.getStackTrace(libgcj.so.16)
  at java.lang.Throwable.stackTraceString(libgcj.so.16)
  at java.lang.Throwable.printStackTrace(libgcj.so.16)
  at java.lang.Throwable.printStackTrace(libgcj.so.16)

There seems to be some recognition of this issue, but it is unclear how/if it has been resolved.

I'm trying to get my output such that for an example file 'ad.pdf' is split into 'ad.pdf_01' and 'ad.pdf_02' if it contains two pages.

4
  • Is the issue specific to when pdftk is run in a loop, or do you get the same error when run singly? Jan 27, 2017 at 21:09
  • Specifically when it is run in a loop. Jan 27, 2017 at 21:18
  • According to the issue you linked it has been resolved in pdftk 2.01, what version are you using? Jan 28, 2017 at 19:02
  • @steeldrivers answer worked for me. It was probably an issue of overwriting to the same file while it was still open. Jan 30, 2017 at 15:16

2 Answers 2

2

The issue seems to be that pdftk burst defaults to naming its output files as pg_0001.pdf, pg_0002.pdf and so on regardless of the input file name.

Exactly why that causes errors is not clear - possibly it starts to process the next file before the previous output file(s) have been closed. In any case, overwriting files is obviously not desirable in this case - so the solution is to change the output on a per-file basis.

According to the pdftk manual page:

                    To name these pages yourself, supply a
printf-styled format string via the output section.  For
example, if you want pages named: page_01.pdf, page_02.pdf,
etc., pass output page_%02d.pdf to pdftk.

so for example you could do

for file in *.pdf; do pdftk "$file" burst output "${file%.pdf}-%02d.pdf"; done

which for inputs fileA.pdf, fileB.pdf will result in output files fileA-01.pdf, fileA-02.pdf, ... fileB-nm.pdf (removing and re-adding the .pdf extension after the numeric suffix).

If you really want ad.pdf --> ad.pdf_01 that would be "${file}_%02d".

1

I would

  • Make sure your pdftk is at version 2.01 because the issue should be fixed, according to the issue you linked.
  • Try with a different JRE installed, link OpenJDK or Oracle JRE.
  • Try Sejda, command line, open source and does split PDF files (among the other things), you can customize output names.

Unfortunately that's a uncaught NullPointerException and there isn't any details so it's hard to tell what is going wrong.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .