Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Auto-expand page height to fit content #1841

Closed
toncid opened this issue Jul 8, 2014 · 2 comments
Closed

Auto-expand page height to fit content #1841

toncid opened this issue Jul 8, 2014 · 2 comments

Comments

@toncid
Copy link

toncid commented Jul 8, 2014

Hello,

I haven't found a way to produce a PDF that would automatically expand page height to content height.

I suggest something along this lines:

$ wkhtmltopdf --page-width '5in' --page-height 'auto'

Internally wkhtmltopdf would execute a simple JavaScript script like (from: http://stackoverflow.com/questions/1145850/how-to-get-height-of-entire-document-with-javascript):

var body = document.body,
  html = document.documentElement;

var height = Math.max(body.scrollHeight, body.offsetHeight, 
                       html.clientHeight, html.scrollHeight, html.offsetHeight);

The script will return page height in pixels and wkhtmltopdf could expand page height accordingly. The result will be a one-page PDF file.

Thoughts?

@ashkulz
Copy link
Member

ashkulz commented Jul 8, 2014

Duplicate of #1627

@toncid
Copy link
Author

toncid commented Jul 8, 2014

Huh, I missed the existing one somehow. Sorry :(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants