2

我正在创建一个包含 7 列表格的多页 PDF。

当我在我的开发计算机(Mac OS X 10.8、ruby 1.9.2、Rails 3.2.6)上创建 PDF 时,它会正确下载和呈现。

如果我在暂存服务器上创建 PDF,当我尝试在预览中查看它时收到以下错误消息“它可能已损坏或使用预览无法识别的文件格式。”

如果我在生产服务器上创建 PDF,它可以正常工作。

我尝试删除表中的所有列,然后一次将它们添加回来,看看是哪个导致了问题,但这并没有明显的原因。

认为这可能是表格宽度问题,我尝试将其更改为横向并减小字体大小,但仍然没有区别。

即使它在生产服务器上工作,我也想深入了解它,以防它也开始在那里发生。此外,如果无法在暂存时对其进行测试,我的客户将无法签署更新。

这是代码

@locations.each do |location|
    modules_marked = 10 # this is calculated in the actual code
    exams_marked = 10 # this is calculated in the actual code

    total_delegates += CourseDelegate.for_location(location).count
    total_modules += modules_marked
    total_exams += exams_marked

    entry = []
    entry << location.name[0..5]
    entry << location.division.name
    entry << location.operating_unit_number
    entry << location.purchase_order
    entry << CourseDelegate.for_location(location).count
    entry << modules_marked
    entry << exams_marked

    entries << entry
end

table(entries, :header => true, :width => bounds.width) do 
    row(0).font_style = :bold
    row(entries.count - 1).font_style = :bold

    cells.border_width = 0.1
    cells.border_color = "808080"

    cells.size = 8
    column(1).width = 60
    column(2).width = 60
    column(3).width = 50
    column(4).width = 50
    column(5).width = 50
    column(6).width = 50
    column(0).align = :left
    column(1).align = :left
    column(4).align = :center
    column(5).align = :center
    column(6).align = :center
end

即使用硬编码的单个字母替换所有条目仍然会导致崩溃发生。

更新:我应该提到,当我在文本查看器中查看损坏的 PDF 文件时,它看起来好像文件只是在中途停止并且缺少结尾,这就是它没有在任何 PDF 查看器中显示的原因。

4

0 回答 0