Active 6 years ago. Viewed 8k times. Any help is appreciated. Improve this question. Ammar Ammar 1, 12 12 silver badges 23 23 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. This is the answer Johny Johny 1, 10 10 silver badges 26 26 bronze badges. The question is now, can I have multiple formats for the PDF that the user can choose between? I think you can, but then you have to pass it somehow as parameters. Roney Michael 3, 4 4 gold badges 28 28 silver badges 45 45 bronze badges.
Sign up or log in Sign up using Google. For more information about wkhtmltopdf , see the project's homepage. The wkhtmltopdf binary is run outside of your Rails application; therefore, your normal layouts will not work.
If you plan to use any CSS, JavaScript, or image files, you must modify your layout so that you provide an absolute reference to these files. This is very quick for small assets, but large ones can take a long time. It is best to precompile assets used in PDF views. This will help avoid issues when it comes to deploying, as Rails serves asset files differently between development and production config. In this case, you can use that standard Rails helpers and point to the current CDN for whichever framework you are using.
For jQuery, it would look somethng like this, given the current versions at the time of this writing. NOTE: Certain options are only supported in specific versions of wkhtmltopdf. By default, it will render without a layout layout: false and the template for the current controller and action. Some of the options above are being passed to wkhtmltopdf binary. They can be used to control the options used in Webkit rendering before generating the PDF. You can see the complete list of options under "Global Options" in wkhtmltopdf usage docs.
A bit of javascript can help you number your pages. If you do not have explicit page breaks and therefore do not have any "page" class , you can also use wkhtmltopdf's built in page number generation by setting one of the headers to "[page]":.
If you would like to have WickedPdf automatically generate PDF views for all or nearly all pages by appending. If you want to turn on or off the middleware for certain URLs, use the :only or :except conditions like so:. This will render the pdf to a string and include it in the email. This is very slow so make sure you schedule your email delivery in a job.
StackOverflow questions with the tag "wicked-pdf". Now you can use a debug param on the URL that shows you the content of the pdf in plain html to design it faster.
To get around this, you can load your assets like so in your templates:. If one image from your HTML cannot be found relative or wrong path for example , others images with right paths may not be displayed in the output PDF as well it seems to be an issue with wkhtmltopdf.
Asked 3 years, 5 months ago. Active 3 years, 5 months ago. Viewed times. Improve this question. Pirun Seng Pirun Seng 2 2 silver badges 16 16 bronze badges. Add a comment. Active Oldest Votes. Use the below bit of code and pass your instance variable in the locals. Improve this answer. Maxence Maxence 1, 2 2 gold badges 13 13 silver badges 27 27 bronze badges. Thanks, but I want to download, not upload. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password.
0コメント