FsPdf icon indicating copy to clipboard operation
FsPdf copied to clipboard

Rendering a book

Open kerams opened this issue 2 years ago • 1 comments

Is it possible to render something like a book? Using Catalog.Pages is fundementally the wrong abstraction here, because I don't know the number of pages in advance (without some crazy calculations considering font size, margins, line spacing, etc.) and I don't really care. At most I would want to force page breaks at the end of chapters, but other than that I only have a list of paragraphs/text blocks/other shapes in a chapter that I would like to pack in as tightly as possible.

Does PDF have some instructions that could be surfaced to help with this or do we have to painstakingly implemented page splitting manually? (I know nothing about PDF internals)

kerams avatar Jun 02 '22 17:06 kerams

The PDF format is all about placing content on pages and is too low level to determine how you might want your text laid out. Some software has to exist above it to calculate what fits on a page at a given size and spacing along with various blocks you may or may not want to overlay each other. This is essentially what document publishing software does, so we could define an abstraction like "a list of paragraphs in a chapter of a book" but then the calculation of breaking those into pages has to be done by looking at the size of the target document (letter, A4, etc) and the margins of the pages, and the size of font and then calculating it all out to break it into printable pages for PDF.

There are a few things I've done so far to do that sort of calculation, like for splitting a paragraph into lines, so it's doable, but first step is to define what input type/structure you want and then we can plan out the pipeline to calculate it.

ninjarobot avatar Jun 10 '22 11:06 ninjarobot