Using lists in prawn

后端 未结 7 1017
深忆病人
深忆病人 2021-02-13 15:53

Im using prawn to create pdfs that contain much data in table format and some lists. The problem with the lists is that Im just using text as lists because there is no semantic

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-13 15:56

    An excellent solution that respects the cursor position as well as render like a true list with a small number of lines of code is:

    items = ["first","second","third"]
    def bullet_list(items)
      start_new_page if cursor < 50
      items.each do |item|
        text_box "•", at: [13, cursor]
        indent(30) do
          text item
        end
      end
    end
    

    The start_new_page clause covers scenarios where the bullet line item may need to go onto the next page. This maintains keeping the bullet with the bullet content.

    Example PDF Rendering Screenshot:

    Example Rendered List

提交回复
热议问题