Search code examples
node.jsherokuphantomjsbuildpackpage-break-inside

Page-break-inside support in phantomjs on heroku


I have a NodeJS app using PhantomJS to generate PDF files. My app is deployed to Heroku and I'm using this phantom build pack. Unfortunately this build pack does not support the page-break-inside: avoid CSS property.

I did a research and found 2 hacks on this GitHub issue page. I've tried both of them, but unfortunately I can't use the CSS one, due to my page structure and the JavaScript one isn't page-breaking properly.

One of the guys in the GitHub link above mentioned that this problem is fixed if I compile from source, but I have no idea how I can compile from source on Heroku App and is it even possible. All the buildpacks I found are using the binaries.

It's really important for my app to break pages properly, but I can't find a way to get this feature working. Any suggestion/guide about how to fix my issue will be greatly appreciated!


Solution

  • I've downloaded it to my machine(Debian 7.6.0) and compiled PhantomJS using this guide. So I executed:

    sudo apt-get update
    sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev libxft-dev
    git clone git://github.com/ariya/phantomjs.git
    cd phantomjs
    git checkout 1.9
    ./build.sh
    

    And then I took the binary from /bin folder and added it to custom buildpack. I added this buildpack to heroku, but it crashed with the following error:

    /phantomjs: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./phantomjs)
    

    So I did on my machine

    ldd bin/phantomjs
    

    and I took all dependencies:

        root@deepsypotato:/home/viktor# ldd phantomjs.1
        linux-vdso.so.1 =>  (0x00007fffe9f74000)
        libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007fd914fcd000)
        libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007fd914d96000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd914b91000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd914989000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd91476d000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd914465000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd9141e3000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd913fcd000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd913c41000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fd915283000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fd913a2a000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fd913800000)
    

    then I copied libstdc++.so.6 from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 and added it to my custom buildpack and now its working flawlessly :).