Using lists in prawn

后端 未结 7 1045
深忆病人
深忆病人 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 16:07

    I just had a similar problem and solved it within Prawn a slightly different way than using a table:

    ["Item 1","Item 2","Item 3"].each() do |list-item|
    
      #create a bounding box for the list-item label
      #float it so that the cursor doesn't move down
      float do
        bounding_box [15,cursor], :width => 10 do
          text "•"
        end
      end
    
      #create a bounding box for the list-item content
      bounding_box [25,cursor], :width => 600 do
        text list-item
      end
    
      #provide a space between list-items
      move_down(5)
    
    end
    

    This could obviously be extended (for example, you could do numbered lists with an each_with_index() rather than each()). It also allows for arbitrary content in the bounding box (which isn't allowed in tables).

提交回复
热议问题