Rails: WickedPDF: Page Breaks

前端 未结 6 2054
灰色年华
灰色年华 2020-12-13 12:55

In my Ruby (1.9.2) Rails (3.0.x) I would like to render a web page as PDF using wicked_pdf, and I would like to control where the page breaks are. My CSS code to control pag

6条回答
  •  半阙折子戏
    2020-12-13 13:51

    Make sure that the stylesheet link tag includes media='print" or media='all' if you are using an external stylesheet:

    <%= stylesheet_link_tag 'retailers_pdf',media: 'all' %>
    

    or

    <%= stylesheet_link_tag 'retailers_pdf',media: 'print' %>
    

    otherwise wicked_pdf will not pick it up.

    Also note that if you are in the middle of a table or div with a border, that the page-break attributes will not work. In this case, it's time to break out jQuery and start splitting things up. This answer: https://stackoverflow.com/a/13394466/2016616 has a good snippet for position measurement. I am working on clean and repeatable table-splitting code and will post it when I have finished it.

提交回复
热议问题