logo
down
shadow

wicked_pdf on Rails 4 not generating pdf


wicked_pdf on Rails 4 not generating pdf

By : C. Otter
Date : November 17 2020, 01:00 AM
it helps some times you should rename the view into print_view.pdf.erb as you allow both formats in the controller
And for getting the pdf you also have call the same url with the .pdf extension e.g /objects/print_view.pdf
code :


Share : facebook icon twitter icon
Rails 3 ActionMailer and Wicked_PDF

Rails 3 ActionMailer and Wicked_PDF


By : Ali
Date : March 29 2020, 07:55 AM
wish helps you WickedPDF can render to a file just fine to attach to an email or save to the filesystem.
Your method above won't work for you because generate_pdf is a method on the mailer, that returns a mail object (not the PDF you wanted)
code :
def email_invoice(invoice)
  @invoice = invoice
  attachments["invoice.pdf"] = WickedPdf.new.pdf_from_string(
    render_to_string(:pdf => "invoice",:template => 'documents/show.pdf.erb')
  )
  self.instance_variable_set(:@lookup_context, nil)
  mail :subject => "Your Invoice", :to => invoice.customer.email
end
def email_invoice(invoice)
  @invoice = invoice
  mail(:subject => 'Your Invoice', :to => invoice.customer.email) do |format|
    format.text
    format.pdf do
      attachments['invoice.pdf'] = WickedPdf.new.pdf_from_string(
        render_to_string(:pdf => "invoice",:template => 'documents/show.pdf.erb')
      )
    end
  end
end
wicked_pdf with rails 3.1 and ruby 1.9.2

wicked_pdf with rails 3.1 and ruby 1.9.2


By : Alexis Boissonnat
Date : March 29 2020, 07:55 AM
To fix the issue you can do i had a before_filter in my application controller that was checking every request with the mentioned format for authentication and i was missing pdf format there, so as soon as i put the :pdf in the list of formats for each incoming request it worked fine.
Rails 4 wicked_pdf generate blank pdf while generating from model

Rails 4 wicked_pdf generate blank pdf while generating from model


By : user3802682
Date : March 29 2020, 07:55 AM
wish of those help A good test is just put a simple line of text in your template and see if you get a PDF with that line. Strip everything back so you just generating a PDF with no coming locals, just that 1 string and let me know.
Here is how I set up mine and it works fine, it might click something :)
code :
 def generate_pdf_voucher(voucher, dir_name)
    view = ActionView::Base.new(Rails.root.join('app/views'))
    view.class.include ApplicationHelper
    view.class.include Rails.application.routes.url_helpers

    pdf = view.render :pdf => a_name,
                      :template => 'layouts/pdfs/voucher_pdf',
                      :layout => 'layouts/pdfs/pdf.html.erb',
                      :header => {:right => '[page] of [topage]'},
                      :locals => {:@voucher => voucher}
    # then save to a file
    pdf = WickedPdf.new.pdf_from_string(pdf)

    save_path = Rails.root.join('public', 'pdfs', dir_name, "#{voucher[:user].id.to_s}.pdf")
    File.open(save_path, 'wb') do |file|
      file << pdf
    end
end
High CPU Usage when generating PDFs in Rails with Wicked_PDF gem

High CPU Usage when generating PDFs in Rails with Wicked_PDF gem


By : Bigboss
Date : March 29 2020, 07:55 AM
wish helps you Putting this in a controller seems ill-advised because the minute you deploy this the request will take a significant time to generate and block other incoming requests for other pages.
You should separate this into two concerns. One job that generates the HTML, which could be this controller, and then a background task to convert that HTML into PDF format.
code :
class RendersReportPdf
  def self.call player_ids
    html = ReportsController.render :director_report_pdf, assigns: { players: Player.where(id: player_ids }
    pdf = WickedPdf.new.pdf_from_string html    
    temp = Tempfile.new("#{Time.now.to_i}.pdf")
    temp.write(pdf)
    temp.close
    temp.path
    # Probably upload this to S3 or similar at this point
    # Notify the user that it's now available somehow
  end
end
PDF files not generating for more than 200 pages with footer using wicked_pdf

PDF files not generating for more than 200 pages with footer using wicked_pdf


By : user3471795
Date : March 29 2020, 07:55 AM
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org