dart_pdf
dart_pdf copied to clipboard
PDF page content in two columns
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?
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 ...
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?
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 ...
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.
Another approach would be, to introduce a new type of page ("n-column-page")
Sorry for late reply. Thank you for your advice! I will attempt to implement a "n-column-page" in personal fork
I have hacked together some kind of multi column page ...
Feel free to have a look at this:
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.
Oh .. you may be right .. i will have a look, thank you
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?
...
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!