5
votes

I'm working on a project that require generating a PDF file from HTML content. I'm using wkhtmltopdf which I believe is the best solution I've came accross so far.

I was wondering if there was a way of generating only a one page PDF.

I have a HTML rendered interface and I want the user to get the same result (let's say 90% similar) on the resulting PDF file.

In the following example the content is still on the first page but wkhtmltopdf generates a second one that contains nothing :

enter image description here

I would like to get a one page PDF no matter the content of the page. I'm using the version 0.12 of wkhtmltopdf and I could not find in the documentation any option that allow to enter the desired number of pages.

I don't know if some of you already encountered such issue and if the solution would be an option flag that I don't know ? Or maybe there is another way ?

2

2 Answers

3
votes

I'm generating some multi page PDFs. In some cases only the first page is needed. So I'm using pdftk to output only the first page.

I'm using a command like:

wkhtmltopdf http://stackoverflow.com temp.pdf
pdftk temp.pdf cat 1 output output.pdf
rm temp.pdf
0
votes

I'm using wkhtmltopdf and works perfectly for one page only HTML pages.

It can be a problem with the height of some HTML element you have there. I think you should take a look on there. Another attempt should be try to change the page-size to one bigger. In that case, you need to do something like this before you generate the stream

string switches = "";
switches += "--print-media-type ";
switches += "--page-size Letter ";
p.StartInfo.Arguments = switches + " " + url + " " + fileName;