pdftk 1.41 for Mac OS X 10.6

Important update: If you’ve downloaded the package before and you’re experiencing “segmentation fault”s with certain PDF files, please download the updated package below. Thanks to commenter Azhrei, we were able to fix a problem with one of the libraries, and all should work fine now!


Due to my being a remote employee, I get to juggle with PDF files quite a bit. A great tool for common PDF manipulations (changing page order, combining files, rotating pages etc) has proven to be pdftk. Sadly, a current version for Mac OS X is not available on their homepage. In addition, it is annoying (to say the least) to compile, which is why all three third-party package management systems that I know of (MacPorts, fink, as well as homebrew), last time I checked, did not have it at all, or their versions were broken.

Now I wouldn’t be a geek if that kept me from compiling it myself. I took some hints from anoved.net who was nice enough to also provide a compiled binary, but sadly did not include the shared libraries it relies on.

Instead, I made an installer package that’ll install pdftk itself as well as the handful of libraries you need into /usr/local. Once you ran this, you can open Terminal.app, and typing pdftk should greet you as follows:

$ pdftk
SYNOPSIS
       pdftk <input PDF files | - | PROMPT>
            [input_pw <input PDF owner passwords | PROMPT>]
            [<operation> <operation arguments>]
            [output <output filename | - | PROMPT>]
            [encrypt_40bit | encrypt_128bit]
(...)

You can download the updated package here: pdftk1.41_OSX10.6.dmg

(MD5 hash: ea945c606b356305834edc651ddb893d)

I only tested it on OS X 10.6.2, if you use it on older versions, please let me know in the comments if it worked.



Categories: Mozilla Crosspost, OSU OSL Crosspost, Tech Talk | Tags: , ,

52 Responses to “pdftk 1.41 for Mac OS X 10.6”

Pages: [1] 2 3 » Show All

  1. What are the shared libraries that it needs (don’t have my Mac right now to download the dmg and check the installer)?

  2. I made sure to mention that in the README which you also can’t see if you don’t have a Mac handy ;)

    But here they are:

    /usr/local/gcj/lib/libgcc_s.1.dylib
    /usr/local/gcj/lib/libgcj.8.0.0.dylib
    /usr/local/gcj/lib/libgcj.8.dylib
    /usr/local/gcj/lib/libstdc++.6.0.9.dylib
    /usr/local/gcj/lib/libstdc++.6.dylib
    

    Btw, libgcj.8 and libstdc++.6 are symlinks to the respective other file in the list.

  3. How can I trust that this is not a virus?

  4. You could compile it yourself and compare the file hashes :)

  5. You’re awesome, thanks for this!!

  6. You’re welcome! I hope it works for you.

  7. Fred, I found this with a Google search — EXCELLENT! I was dismayed about the issues with GCC, pdftk, and Snow Leopard and not being able to use MacPorts or fink. I then tried compiling myself and failed miserably. I almost gave up hope of having pdftk with OS X 10.6. Thanks so much for “being a geek” and working through the compiling issues! -JW

  8. Thanks Fred, I’ve been looking for something like this. :)

    However, it’s not working for me. :( I’m running the latest 10.6.2 (including the Safari patch that just came out yesterday!) and I’m getting a SIGSEGV when trying to perform a “cat” operation on an input PDF. For example, the following works:

    pdftk existing.pdf output new.pdf

    But this one fails with a SEGV:

    pdftk existing.pdf cat 1-23 output new.pdf

    I’m somewhat new to development on OSX and I can’t find anything like the Linux strace(1) utility so I can’t tell what’s causing the SEGV!? I’ll be doing some more Google’ing on this, but I’ll come back here over the next few days as well.

    Thanks for your work in putting this together! I built gcj on 10.6.2 but got Abort’s when gcj tried to execute ecj1 so after tinkering with it for a few hours I gave up. :(

  9. Azhrei: Oh no! I can reproduce. Thanks for the hint! I’ll look into it and see what I can find out. If you find out what the problem is, please let me know as well!

  10. If you find typing “pdftk” doesn’t work after installing you may need to add “/usr/local/bin/” to your PATH.

    Do this by changing your path reference in your “.profile” file in your home directory. It’s a hidden file if you can’t find it.

    Mine ended up looking like:
    PATH=”/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/mysql/bin:/usr/local/bin”

  11. Actually, it might be better to edit ~/.MacOSX/environment.plist because that file is parsed and variables are created by the window manager. That means the PATH variable will always be up to date, even if not executed from a Terminal.

  12. Thank you!! You’re a legend.

  13. It works on my snow leopard (10.6.2)

  14. error on OSX 10.6.2
    pdftk f1.pdf f2.pdf cat output f3.pdf
    error message:
    segmentation fault

    Any idea?

  15. No, I am sorry. It seems that pdftk is slowly rotting away, and, when compiled with gcj 4.2.1, there seems to be trouble with some PDF files. I am working on an alternative to pdftk, but it’s not quite ready yet.

  16. I just checked out stapler (the project you mentioned) and while it might suffice for what I need, I really like the watermark and other features of PDFTK. :( I might try to revive the PDFTK project by either converting the Java code to C/C++ or perhaps converting the C code into Java? Either of those would eliminate the issues of merging the two languages together…

    I’ll look into this more over the weekend and next week and then report back here with a summary. :)

  17. Woohoo! I think I’ve got a solution!

    I found the following in my crash log directory regarding pdftk:

    0 dyld 0x8fe11f32 misaligned_stack_error + 0
    1 libstdc++.6.dylib 0x05fe6ce3 std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&) + 243 (streambuf:341)
    2 pdftk 0x00013aa7 std::_Rb_tree<int, int, std::_Identity, std::less, std::allocator >::_M_insert_unique(int const&) + 199
    3 pdftk 0x000101c0 TK_Session::TK_Session(int, char**) + 7664
    4 pdftk 0×00013253 main + 467
    5 pdftk 0x00002c09 _start + 208
    6 pdftk 0x00002b38 start + 40

    You’ll notice that this crash says that dyld found a misaligned stack (!) and that error occurred in libstdc++.6.dylib. Well, it turns out that the dtruss was waking up the thread that was waiting so that it could handle the SIGBUS error if it chose, not because it was the one with the problem! (The following lines in the crash log show the semwait() thread.)

    Anyway, I searched my system for “libstdc++.6.dylib” and found it in the /usr/local/gcj/lib directory — that’s the one provided in your bundle. But I also have one in my /usr/lib directory as well (note that I have the Xcode tools installed). Mine looks like this:

    -rwxr-xr-x 1 root wheel 2439888 May 18 2009 /usr/lib/libstdc++.6.0.9.dylib*

    This is on OSX 10.6.2. Well, I deleted the one in /usr/local/gcj/lib just to see if the standard system library might not have the bug and sure enough, it worked!

    I’ve run some tests on PDFTK using the system library and it looks good so far. I’ve used a 24-page PDF as my test input. This is the one that had failures previously. I’ve used a nested loop to test extracting pages from 1-2, 2-3, 3-4, and so on, all the way to 23-24 without a crash. Then I tried 1-3, 2-4, etc. Each time extending the range of the extracted pages. Never crashed!

    I don’t know if /usr/lib/stdc++.6.dylib is part of the base system install or part of Xcode (I suspect it’s part of Xcode because the same library appears under /Developer as well and that’s where Xcode places development libraries).

  18. Very nice, Azhrei! Maybe, if I bundled the system lib with the package instead of my compiled one (both are from the same version of gcc, so I imagine that’d work), the package would be fixed? I’ll do that (though I don’t have a second Mac to try with, so I might have to rely on people’s replies on if it works properly…)

  19. Works for me! I will repackage it, upload it, and update the post. Thanks so much!

  20. Thanks for this. I had a slight hiccup the first time I ran it:


    Referenced from: /usr/local/bin/pdftk
    Reason: no suitable image found. Did find:
    /usr/local/gcj/lib/libgcj.8.dylib: stat() failed with errno=13
    Trace/BPT trap

    I didn’t know what errno=13 meant, but exploring /usr/local/gcj/lib revealed it was not globally readable. So I ran the command


    $ sudo chmod 755 /usr/local/gcj/lib

    After that it worked fine!

  21. Hopefully others will have success. And hopefully the library is already included as part of the base install; we’ll need to hear from others whether that’s the case or not.

    In any case, thanks for doing this build! :)

  22. Matthew: Fixed that, thanks for the heads-up!

  23. Hey, Matthew…

    Are you running 10.6.2? Did you install the Xcode tools? If you look in your /usr/lib directory do you have a file named libstdc++.6.dylib (or something very similar)?

    Thanks. :)

  24. Azhrei: Yes, yes, and yes. I have these files:


    /usr/lib/libstdc++.6.0.9.dylib
    /usr/lib/libstdc++.6.dylib

  25. Azhrei, Matthew: FWIW, the rights issue was me making a mistake with the packaging. I fixed it in the meantime, sorry about that.

Pages: [1] 2 3 » Show All

Leave a Reply

Comments will be closed on August 10, 2011.