Search code examples
pdfruby-on-rails-3pdf-generationprawnprawnto

Using whole space of pdf file


I am using prawn to create pdf file but it always leaves some spaces/margins around the page. Can't we use whole space of the pdf file not leaving any margins around?

Thanks !!!


Solution

  • Are you referring to the page bounds ?

    The general space that is consumed on the page can be shown by the example code:

    require 'prawn/core'
    require 'prawn/layout'
    
    Prawn::Document.generate('padded_box.pdf') do
      stroke_bounds
      text "Margin box"
      padded_box(25) do
        stroke_bounds
        text "Bounding box padded by 25 on all sides from the margins"
        padded_box(50) do
          stroke_bounds
          text "Bounding box padded by 50 on all sides from the parent bounds"
        end
      end
    end
    

    This will draw the bounds of the page showing the margin. There is a gap, which is the margins typically defined for the printing area