Problem Summary:
Following the most basic example, my PDF's that are generated are displaying blank, and if I open them in a text editor it's displaying the full HTML code as if I chose "view source" on the webpage.
Gemfile
gem "wicked_pdf"
gem "wkhtmltopdf-binary"
awards_controller.rb
...
def show
@award = Award.find(params[:id])
respond_to do |format|
format.html
format.pdf{
render pdf: @award.id
}
end
end
...
show.pdf.erb
<div>
Hello World from the SHOW method
</div>
Spin up the server, navigate to localhost:3020/awards/1.pdf in both Chrome and Firefox shows an error of either "Failed to load PDF document" or "This PDF document may not be displayed properly". As I said, if I save the .pdf file and open it in a text editor it shows the html.
wkhtmltopdf seems to be installed correctly because I can go into my terminal and use
wkhtmltopdf http://localhost:3020/awards award.pdf
Likewise from my rails console I can use
system "wkhtmltopdf http://localhost:3020/awards award.pdf"
Any suggestions are appreciated.
Have you restarted your server?
I ran into the very same problem, a simple restart of the httpd server fixed the issue.
Hah... Wow. I could have sworn I restarted the server, but when I spun it up this morning it worked as expected. Thanks for the input, I'll close the issue.
Restarting the server is just a temporarily fixed. However, I think the problem failed to load PDF document might be caused by something else. In my case, not sure if it is caused by the file size of the pdf file. My real example, I have 3 pdf files to be rendered. At the same time of deployment, there is only one of them randomly failed to load while the other two are always fine. I've checked file size of the one (~= 500KB) which is failed to load, and it appears that it is much bigger than the other two (<= 150KB). I'm concerning about the file size as I used to see somebody else mentioned about it, too. I'm still finding a permanent solution to fix such this issue.
Updated! It seems like my server does not limit the file size to be rendered, so I think maybe there might be something else that cause the problem.
my-ubuntu-server:~$ ulimit -aH
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 7862
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 4096
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) 7862
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
I've just posted my issue in stackoverflow, too.
https://stackoverflow.com/questions/52049427/wicked-pdf-failed-to-load-pdf-document
Most helpful comment
Have you restarted your server?
I ran into the very same problem, a simple restart of the httpd server fixed the issue.