dart_pdf icon indicating copy to clipboard operation
dart_pdf copied to clipboard

PDF page content in two columns

Open OlegBezr opened this issue 1 year ago • 13 comments

Hi, thank you for supporting this amazing package!

I want to show the content of my pdf in two-column style (the content starts at the top of the left column, goes to its bottom, then continues at the top of the right column). It should be similar to columns in Word. Is this feature currently supported? If not, do you think it would be easy to add it on my own or does it sound like a very complicated change?

OlegBezr avatar Oct 02 '23 17:10 OlegBezr

whoa, this is not as easy, at it seem as first.

There is an mechanism for spanning widgets to automatically stop rendering overflowing content on multipages and serving the overflowed content for the subsequent page.

But here we would need to implement something similar inside a multi-column widget.

The Widget would render content vertically until it consumed the maximal available height. Remaining content would render in the second column ... until the last column overflows.

Then the whole widget overflows and its remaining content is rendered on the next page ...

ilaurillard avatar Oct 05 '23 15:10 ilaurillard

Do you think this could be done with modifications to pdf.Wrap and pdf.Multipage? Or would it require figuring out a completely new widget?

OlegBezr avatar Oct 05 '23 16:10 OlegBezr

I think you need a new widget, that imitates the multipage behaviour, only that it would need to create columns on the same page first, and only if the last (2nd or 3rd or nth) column is full, spans to the next page ...

ilaurillard avatar Oct 05 '23 19:10 ilaurillard

Had a try yesterday .. but unfortunately it seems really complicated (at least for me)

The problem is, multipage let a widget calculate its total size and than renders it on multiple pages, when it overflows. But we need to know the remaining space in the widget layout, for the widget to let the content flow into columns at specific positions. Multipage mechnism passes an infinite height constraint to the widget - even if the remaining space is known at this point - so the widget cannot know itself, if it should overflow.

ilaurillard avatar Oct 06 '23 07:10 ilaurillard

Another approach would be, to introduce a new type of page ("n-column-page")

ilaurillard avatar Oct 06 '23 07:10 ilaurillard

Sorry for late reply. Thank you for your advice! I will attempt to implement a "n-column-page" in personal fork

OlegBezr avatar Oct 18 '23 08:10 OlegBezr

I have hacked together some kind of multi column page ...

Feel free to have a look at this:

ilaurillard avatar Oct 21 '23 12:10 ilaurillard

image

ilaurillard avatar Oct 21 '23 12:10 ilaurillard

Have you looked into Partitions instead? It can build columns that continue on multiple pages, the flow needs to be changed but it's a better approach to duplicating MultiPage.

Partitions could have a flow parameter that would take horizontal or vertical. Could be Left to Right too.

This widget can already deal with different widths columns, with fixed size or Flexible.

DavBfr avatar Oct 21 '23 13:10 DavBfr

Oh .. you may be right .. i will have a look, thank you

ilaurillard avatar Oct 21 '23 19:10 ilaurillard

Well in fact .. i had a look .. but couldn't figure out, how i would transfer overflowing content into the next child/partition ...

Suppose i have two partitions, i put all my content into the first partition. MultiPage would try to render the partitions and now needs to put the overflowing (spanning) stuff into the next partition - but should not create a second page yet .... am i missing something?

...

ilaurillard avatar Oct 21 '23 19:10 ilaurillard

Also not sure how to implement this with partitions. @ilaurillard, I ended up using your implementation, it works greatly for my use case. Thank you a ton!

OlegBezr avatar Nov 03 '23 02:11 OlegBezr