ruby-on-railsrubypdfprawnprawnto

Prawn: css like overflow: hidden for bounding boxes with images


I want to clip an image if it goes beyond the dimensions of a bounding box. Just like how CSS overflow: hidden would do it. Eg.

pdf.grid([0, 0], [3, 27]).bounding_box do
 pdf.image image_file
end

Now currently, this image would overflow outside the bounding box if its larger than it. Is there any way to clip the image when it goes beyond the bounding box. ? I know this is possible for text when using text_box.


Solution

  • you can set the size of the image or get the image to scale so it fits within a certain area while maintaining proportions, do not believe you can crop an image.

    If your page is not dynamic, that is the image area will always be the same this should be OK.

    pdf.image "image_file_path_&_name", :position => :center, :fit => [100,450];

    This is based on v0.8.4.