【问题标题】:Rails PDFKit Appearance Bug with Bootstrap带有 Bootstrap 的 Rails PDFKit 外观错误
【发布时间】:2013-09-06 21:22:20
【问题描述】:

我用 jQuery 获取我的 DOM 并发送一个 AJAX 请求来创建 PDF:

// store html in variable
var html = '<html>' + $('html').html() + '</html>';

// create pdf
$.ajax({           
    url: '/quotes/generate_pdf', 
    data: { html : html, quote_id : quote_id },
    type: "POST",
    cache: false,           
    success: function(data) {

    },
    error: function() {
        alert('An error occurred, please refresh the page and try again');
    }   
 });

然后,在 Rails 中:

def generate_pdf
  if request.post?  
    kit = PDFKit.new(params[:html])
    kit.stylesheets << RAILS_ROOT + '/public/stylesheets/portal/pdf.css'
    file = kit.to_file(RAILS_ROOT + '/pdfs/' + params[:quote_id] + '.pdf')
    render :text => '1'
  end
end

pdf.css 是我页面中的样式表合并到一个文件中。

生成的 PDF 看起来很完美,只是由于某种原因在其顶部有某种灰色叠加层。在花时间尝试查看导致它的原因之后,它似乎是 bootstrap.css 内的东西,但我不知道是什么,所以只是希望其他人解决了同样的问题,但我似乎找不到任何东西。

当在 Adob​​e Reader 中打开 PDF 时,它似乎是完美的一秒钟,但随后出现了覆盖,所以我认为这是软件的问题,但在不同的程序中打开它具有相同的结果,并且缩略图预览也有叠加层,另外,当我发现它是引导程序中的某些东西时,它消除了有问题的软件。

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap ruby-on-rails-2 pdfkit


    【解决方案1】:

    无奈之下,我去了 Bootstrap 自定义页面 (http://getbootstrap.com/customize/?id=6470483) 并重新下载了文件并在我的pdf.css 中使用了非缩小版本,它似乎工作正常。

    我只勾选了第一列的前五个复选框:

    Print media styles
    Typography
    Code
    Grid system
    Tables
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-05
      • 2017-04-26
      • 2013-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多