문제

How can I add a border to an image with Prawn (pdf library)? If this is possible, can you add padding as well?

도움이 되었습니까?

해결책

You can add a border using a bounding_box and stroke_bounds. In this example, I've put a border around an image. I've even given it padding of 15. It should be relatively easy to make this a function where a padding parameter could be used to calculate the difference between the image width and the bounding_box width.

require 'prawn'

Prawn::Document.generate("test.pdf") do
    text "Boxed Image", :align=>:center, :size=>20
    bounding_box([0, cursor], :width => 330) do
        move_down 15
        image "image.jpg", :fit => [300, 600], :position => :center
        move_down 15
        stroke_bounds
    end
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top