English 中文(简体)
如何在代表一个数据表格的铁路中创建多页 PDF? (包括每个新页的列标题)?
原标题:How to create a multipage PDF in Rails representing one table of data (including column headers on each new page)?

如何在代表一张数据表格的铁路中创建一个多页 PDF? 我查看了许多关于 wind-pdf、pdfkit和虾的例子,但我还没有看到任何具体解决溢出到后续页面的文字,也没有看到需要用每个新页面重复页头。 感谢您的帮助 。

问题回答

我用普瑞恩来生成我的pdfs, 并且可以得到你想要的效果,像这样:

def render_photo_table(pdf)
  ps = self.photos.map do |photo|
    [photo.filename, photo.image_height, photo.image_width]
  end
  ps.insert(0, [ Filename ,  Height ,  Width ])
  pdf.table(ps) do |table|
    table.header = true
  end
end

这将产生每页顶部的页眉( 以数组位置 0 设置 ) 。

却找到相当容易的方法(在头痛后)来做这件事。

在项目上方放置浮动位置标记 div, 以便您获得起始坐标( 我称之为 ID 项) 。

然后用数据最高层次的 divs 和等级 < code> 无法破解的 。

还包含强制分页符的等级 :

.page-breaker {
  display: block;
  clear: both;
  page-break-after: always;
}

然后,在

<script>
// Very top of items
var current_top = $( #item_top ).offset().top;
// Check distance from top of page to bottom of item
// If greater than page size put page break and headers before
// Reset top of page to top of item.
$( .unbreakable_section ).each(function(index) {
  var item_bottom = $(this).offset().top + $(this).outerHeight(true);
  if ((item_bottom - current_top) > 1250) {
    $(this).before("<div class= page-breaker ></div>");
    $(this).before("Headings Div here");
    current_top = $(this).offset().top - 48; // item - header height
  }
});

</script>

这将测量自上页分页以来的垂直空格, 并新建一页, 如果空格超过页面高度, 则在页面上方放置一个页眉 。 ( 大约( 1250 ), 这对我来说足够接近 -- 页面上有页脚, 因此高度可能随您的设置而变化 ) 。

测试了100页文件的预期效果。

我们为此写了内部密码

如果您有网页,例如:

<div class="mypage">
  <div class="mypage_footer"></div>
</div>

外边有:

<div class="mybox">
  <table><tbody><tr><td>omg</td></tr></tbody></table>
</div>
<div class="mybox">
  <table><tbody><tr><td>lol</td></tr></tbody></table>
</div>

假设您有固定的页面高度(最好是 A4 大小),您可以使用 jquery 来:

  • Compute remaining space inside mypage by subtracting the $(element).height() of the page s children from the height of mypage
  • While there is remaining space, pick a mybox from outside the page and place it inside the page
  • If there is no more space, create a copy of the first page and repeat.




相关问题
Tools to generate reportanalytics feeds from google

Can you recommend any programmable tools/extensions that can be used to generate reports out of google analytics feed on th fly? Essentially some kind of pdf generator from feed, not sure though. Or ...

Asynchronous generation of PDF - error handling

We have some code that uses a third party component to generate a PDF from a URL that we pass it (the URL being a page within our application). In the code, we instantiate the PDF generator and it ...

HTML to PDF vs. Programmatically creating PDF via PHP

I have a PHP application that needs to generate some PDF invoices and PDF timesheets with nice headers/footers. Some Stackoverflow users recommend using TCPDF to create the PDF documents. In my ...

Open PDF Programmatically in One Page View

I have a 2005 Reporting Services report that I display as a PDF through the report viewer control. I would like to know how I can have the PDF be viewed in the "one page at a time mode". Right now it ...

iTextSharp : pdfPTable overlapping with other content

I am using iTextsharp to generate a PDF document from C# application. I am having a PdfPTable to display some tabular data. My problem in the table is overlapping with the other paragraph .Is there ...

(pdflib) Table of contents with dynamic page numbers

I m on pdflib 7 under php5 and I m drawing a statistical report with several sub topics over several pages. Now, I want to include a table of contents on the first page where every sub topic is ...

热门标签