rails 3 and PDFkit

前端 未结 2 553
南方客
南方客 2020-12-18 13:55

I\'m trying to follow this tutorial.

When I\'m adding .pdf to my url it does nothing. My controller has:

respond_to :html, :pdf.
         


        
2条回答
  •  情书的邮戳
    2020-12-18 14:20

    Thanks to another stack overflow answer I got part of solution.

    This works:

    html = 'Toto de combats'
    @pdf = PDFKit.new(html)
    
    send_data @pdf.to_pdf, :filename => "whatever.pdf",
                      :type => "application/pdf",
                      :disposition  => "attachement"
    

    You can replace attachement by inline, so the pdf is displayed in your browser.

    In the stack overflow answer I spoke about (I don't remember the link), the .to_pdf was missing, but is mandatory. Otherwise PDF reader doesn't recognize it.

    I'm trying to get this work with a .pdf url.

    Edit 3:

    My problem with .pdf urls is solved. known issue with rails 3.1, but google was unable to find them.

    explanation : explanation

    Workaround (hadn't tryied yet). workaround

提交回复
热议问题