7

Currently when converting the PDF from given URL, like:

wkhtmltopdf http://superuser.com/ superuser.pdf

where it consist multiple A4 pages (so sometimes images are cut in the middle of the page).

My question is:

How do I convert HTML page into PDF format where the height is endless?

My preference is that you still should have editable/searchable document, not just an static image.


What I've tried already:

2
+50

The wkhtmltopdf 0.9.6 Manual documents this parameter :

    --page-height      <unitreal>      Page height (default unit millimeter)

Therefore defining an enormously long page can be done via :

--page-height 10000cm
--page-height 100m

which both define a page of height of 100 meters (I mention both in case your wkhtmltopdf does not support m).

Not using wkhtmltopdf, I do not know if there is some upper limit to page-height, but you can find that empirically.

In addition you can try to add --disable-smart-width (width is not an error) and try for the moment the less ambitious --page-height 100cm.

In this man page there is a comment about disable-smart-width that it's only available using patched QT.

There is also another comment:

On the wkhtmltopdf website you can download a static version of wkhtmltopdf at http://code.google.com/p/wkhtmltopdf/downloads/list. This static binary will work on most systems and comes with a build in patched QT.

The project has moved elsewhere, so you might hunt there for such a version, or ask in the forums.

  • Tested: wkhtmltopdf http://superuser.com/ superuser.pdf --page-height 100m, but doesn't seems to work as expected as I still see 3 separate pages. Tested with v0.12.2.1. – kenorb Oct 4 '15 at 12:40
  • Try to add --disable-smart-width (width is not an error) and try for the moment the less ambitious --page-height 100cm. – harrymc Oct 6 '15 at 5:46
  • I've already tried, but it's saying: Unknown long argument --disable-smart-width. – kenorb Oct 6 '15 at 8:32
  • This then relates to another version of wkhtmltopdf. My last suggestion is to test the beta version including seeing if some pertinent invocation parameter was added (and especially disabling anything with "smart"). If no go, ask in wkhtmltopdf Spport. – harrymc Oct 6 '15 at 9:58
  • Tested with the latest dev version from the sources (0.12.3-dev-8f03630), the option still doesn't work on OSX (saying it's unknown). The only reference for this option is in imagearguments.cc. Maybe it works only for the images (not PDF)? – kenorb Oct 6 '15 at 16:39
1

You should do it as below:

$ wkhtmltoimage http://superuser.com/ superuser.png
loaded the Generic plugin 
Loading page (1/2)
Rendering (2/2)                                                    
Warning: Received createRequest signal on a disposed ResourceObject's NetworkAccessManager. This might be an indication of an iframe taking too long to load.
Done                                                               
$ geo=$(file superuser.png | awk '{print $5"x"$7}' | sed -e 's/,//')
$ convert superuser.png -page $geo superuser.pdf

Convert is performed from the ImageMagick package. The disadvantage of using the method above is that the PDF output would have a static image.

1

Looking again inside the code it seems you still cannot select an infinite roll.

So you can simply use the imagemagick command mogrify with the option -append on the downloaded file (or even +append if you want to append them horizontally).

wkhtmltopdf http://superuser.com/ superuser.pdf
mogrify -append superuser.pdf

from man mogrify

-append
append an image sequence top to botto (use +append for left to right)

If you want to create a new file you can use from the same suite convert.

convert -density 200 superuser.pdf -append superuser.vertical.pdf
  • I've tried, but the output PDF contain static low-quality image. I've also tried adding: -units PixelsPerInch -density 300 or -units PixelsPerInch -resample 300, but the output PDF is still a low-quality image. – kenorb Oct 4 '15 at 13:01
  • The convert command is really sensible to the position of the parameters. You can try convert -density 300 supersuser.pdf -append su.vertical.pdf... or even more hight density values, and parameters. (Let me know) – Hastur Oct 4 '15 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.