gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.21k stars 69 forks source link

general usage question: control of content flow inside column box #262

Closed adas172002 closed 11 months ago

adas172002 commented 11 months ago

Hello,

I am looking for a way to control flow of content inside columns box. What I mean by that is a way to tell HexaPDF to put part of content I have inside columns box with columns: 4 argument to start on top of next column. If I understand correctly the way columns box works, I can specify column box height on initialisation and box will be rendered in a way to fill each column and keep them same height not larger than specified on init height: ddd argument. Is there a way to achieve this with children: [] argument?

gettalong commented 11 months ago

You can insert an empty box that automatically fills the remaining height of the column to achieve a column break:

require 'hexapdf'

HexaPDF::Composer.create('columns.pdf') do |c|
  c.document.config['debug'] = true
  c.column(columns: 4, equal_height: true, height: 200, style: {margin: [0, 0, 20]}) do |col|
    col.lorem_ipsum(sentences: 2)
    col.lorem_ipsum(sentences: 1)
    col.lorem_ipsum(sentences: 3)
    col.lorem_ipsum(sentences: 2)
  end
  c.column(columns: 4, equal_height: true, height: 200) do |col|
    col.lorem_ipsum(sentences: 2)
    col.box(:base)
    col.lorem_ipsum(sentences: 1)
    col.box(:base)
    col.lorem_ipsum(sentences: 3)
    col.box(:base)
    col.lorem_ipsum(sentences: 2)
    col.box(:base)
  end
end

Will get you this result: image

adas172002 commented 11 months ago

Hi Thomas,

You are quick in responses! And they work :-)

Thanks!