wkhtmltopdf use 2 file descriptor per page (one each for header and footer) which are required for generating the per-page custom variables.
By default Linux allows users to open up to 1024 files. So in case if your document contains more than 512 pages you have to change this limit up to a higher value.
In Ubuntu you can change the parameter (no files) in /etc/security/limits.conf. Just add these lines to the file.
* hard nofile 65535
* soft nofile 65535
root hard nofile 65535 # Need these two lines as wildcards (above)
root soft nofile 65535 # are not applied to root.