{"action":"created","issue":{"url":"https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf/issues/1627","repository_url":"https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf","labels_url":"https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf/issues/1627/labels{/name}","comments_url":"https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf/issues/1627/comments","events_url":"https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf/issues/1627/events","html_url":"https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1627","id":31261496,"number":1627,"title":"Auto page size based on content size","user":{"login":"kachkaev","id":608862,"avatar_url":"https://avatars.githubusercontent.com/u/608862?v=3","gravatar_id":"","url":"https://api.github.com/users/kachkaev","html_url":"https://github.com/kachkaev","followers_url":"https://api.github.com/users/kachkaev/followers","following_url":"https://api.github.com/users/kachkaev/following{/other_user}","gists_url":"https://api.github.com/users/kachkaev/gists{/gist_id}","starred_url":"https://api.github.com/users/kachkaev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kachkaev/subscriptions","organizations_url":"https://api.github.com/users/kachkaev/orgs","repos_url":"https://api.github.com/users/kachkaev/repos","events_url":"https://api.github.com/users/kachkaev/events{/privacy}","received_events_url":"https://api.github.com/users/kachkaev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf/milestones/2","html_url":"https://github.com/wkhtmltopdf/wkhtmltopdf/milestones/future","labels_url":"https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf/milestones/2/labels","id":566785,"number":2,"title":"future","description":"planned for sometime in the future","creator":{"login":"ashkulz","id":854352,"avatar_url":"https://avatars.githubusercontent.com/u/854352?v=3","gravatar_id":"","url":"https://api.github.com/users/ashkulz","html_url":"https://github.com/ashkulz","followers_url":"https://api.github.com/users/ashkulz/followers","following_url":"https://api.github.com/users/ashkulz/following{/other_user}","gists_url":"https://api.github.com/users/ashkulz/gists{/gist_id}","starred_url":"https://api.github.com/users/ashkulz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashkulz/subscriptions","organizations_url":"https://api.github.com/users/ashkulz/orgs","repos_url":"https://api.github.com/users/ashkulz/repos","events_url":"https://api.github.com/users/ashkulz/events{/privacy}","received_events_url":"https://api.github.com/users/ashkulz/received_events","type":"User","site_admin":false},"open_issues":20,"closed_issues":1,"state":"open","created_at":"2014-02-12T03:12:22Z","updated_at":"2016-06-01T10:32:05Z","due_on":null,"closed_at":null},"comments":52,"created_at":"2014-04-10T17:01:45Z","updated_at":"2016-09-20T19:24:46Z","closed_at":null,"body":"It would be nice to be able to set something like ```--auto-size``` when calling wkhtmltopdf to generate a PDF with one page of a minimum possible size. This can be currently done [using a workaround](http://code.google.com/p/wkhtmltopdf/issues/detail?id=612), and means to avoid such hack would be useful.\r\n\r\nPDFs with sizes that depend on the content are widely used in latex documents. One can render an HTML page and then embed the resulting PDF as a figure."},"comment":{"url":"https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf/issues/comments/248406038","html_url":"https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1627#issuecomment-248406038","issue_url":"https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf/issues/1627","id":248406038,"user":{"login":"nielsbartels","id":6429814,"avatar_url":"https://avatars.githubusercontent.com/u/6429814?v=3","gravatar_id":"","url":"https://api.github.com/users/nielsbartels","html_url":"https://github.com/nielsbartels","followers_url":"https://api.github.com/users/nielsbartels/followers","following_url":"https://api.github.com/users/nielsbartels/following{/other_user}","gists_url":"https://api.github.com/users/nielsbartels/gists{/gist_id}","starred_url":"https://api.github.com/users/nielsbartels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nielsbartels/subscriptions","organizations_url":"https://api.github.com/users/nielsbartels/orgs","repos_url":"https://api.github.com/users/nielsbartels/repos","events_url":"https://api.github.com/users/nielsbartels/events{/privacy}","received_events_url":"https://api.github.com/users/nielsbartels/received_events","type":"User","site_admin":false},"created_at":"2016-09-20T19:24:45Z","updated_at":"2016-09-20T19:24:45Z","body":"Read this topic. PhantomJS does not (yet) give me a perfect PDF. So I needed to stick with wkhtmltopdf in this case. \r\n\r\nAnyway. I was searching for a solution for a PDF page with the width of an A4 (210mm) and a variable height. The source is a HTML page with various height / content, but a fixed width (A4 format / 210mm). This width is forced with CSS.\r\n\r\nFirst I tried to generate one PDF document with the default page breaks and I was looking for another fix or tool to merge them together. I couldn't find a solution so the hack I used is to convert the page to a JPG with \"wkhtmltoimage\".  Please note, this isn't exact science, but hey it works for me :-) I was using PHP in this case, but this could be implemented everywhere.\r\n\r\n```\r\n<?php\r\n// Convert the HTML page to a JPG with an A4 width\r\nshell_exec('wkhtmltoimage --width 793 htmlsource.htlm screenshot.jpg');\r\n?>\r\n```\r\nSince I was working in PHP I can easily grap the image height with the PHP method get image size:\r\n\r\n```\r\n<?php\r\n// Get the size from the image (also check if the conversion was a success ;-) not added in the code below). This is just an example.\r\n$size = getimagesize('screenshot.jpg');\r\n?>\r\n```\r\n\r\nTo use these dimensions again with wkhtmltopdf I converted the 'pixels' to 'cm' and gave it as parameters in the wkhtmltopdf command.\r\n\r\n```\r\n// Formula to convert pixels to CM.\r\n$width = $size[0] * 2.54 / 96;\r\n$height = $size[1] * 2.54 / 96;\r\n\r\n// The final command for my PDF the statements on the end are optional. Just a copy paste from my code.\r\nshell_exec(\"/usr/local/bin/wkhtmltopdf -O portrait --page-width \".$width.\"cm --page-height \".$height.\"cm --no-outline -B 0mm -L 0mm -R 0mm -T 0mm '$htmlPath' $pdfPath 2>&1\");\r\n```\r\n\r\nI had an exact match. I am sure someone could do better, but hey I am in a hurry :-) Hopes it helps someone somewhere!"}}
{"actor":{"display_login":"nielsbartels"}}