user758105
user758105

Reputation: 77

PDFKit is giving me a 406, and rendering an empty pdf

And with all that I get a blank Pdf sent to the browser and the log output says this

Started GET "/work_orders/6.pdf" for 127.0.0.1 at 2011-05-17 15:51:31 -0400
Processing by WorkOrdersController#show as HTML
Parameters: {"id"=>"6"}
User Load (3.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
SQL (6.0ms)  describe `roles_users`
Role Load (3.0ms)  SELECT `roles`.* FROM `roles` WHERE (`roles`.`id` = 980190962) LIMIT 1
WorkOrder Load (4.0ms)  SELECT `work_orders`.* FROM `work_orders` WHERE (`work_orders`.`id` = 6) LIMIT 1
Completed 406 Not Acceptable in 265ms

I hope you can help me

EDIT: I removed everything from the show action to just

def show
  @work_order = WorkOrder.find_by_id(params[:id])
end

and now I get a 200 but the Page still renders blank

Started GET "/work_orders/6.pdf" for 127.0.0.1 at 2011-05-17 17:15:26 -0400
Processing by WorkOrdersController#show as HTML
Parameters: {"id"=>"6"}
User Load (19.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
SQL (34.0ms)  describe `roles_users`
Role Load (17.0ms)  SELECT `roles`.* FROM `roles` WHERE (`roles`.`id` = 980190962) LIMIT 1
WorkOrder Load (9.0ms)  SELECT `work_orders`.* FROM `work_orders` WHERE (`work_orders`.`id` = 6) LIMIT 1
Rendered work_orders/show.html.erb within layouts/application (10.0ms)
Completed 200 OK in 741ms (Views: 58.0ms | ActiveRecord: 79.0ms)

EDIT2: I rendered without the layout now as well the page is no longer blank but the characters are all screwy

Upvotes: 4

Views: 1419

Answers (1)

Yardboy
Yardboy

Reputation: 2815

If you want PDFKit to handle everything automatically whenever the url ends in .pdf, you will need to also configure the PDFKit middleware.

Source: https://github.com/jdpace/PDFKit

Middleware

PDFKit comes with a middleware that allows users to get a PDF view of any page on your site by appending .pdf to the URL. Middleware Setup

Rails apps

# in application.rb(Rails3) or environment.rb(Rails2)
require 'pdfkit'
config.middleware.use PDFKit::Middleware

With PDFKit options

# options will be passed to PDFKit.new
config.middleware.use PDFKit::Middleware, :print_media_type => true

Upvotes: 1

Related Questions