How to limit a document to N pages?

I want my document to have at most N pages, even if the content would create much more pages.
Is there a way to achieve this? It should just generate the normal document until page number N and then finish, similar to cropping an image, I want to crop the document to N pages.

I tested with typst 0.15.1. You can use something like
typst compile main.typ cropped.pdf --pages 1-2
Give it a try maybe

1 Like

Thank you. This would be the correct answer! Unfortunately, I’m using typst-python and it is not supported there, I think. But maybe in the future.

1 Like

Back in the day we had the perfect word processor appropriately named WordPerfect. It has this amazing feature called

Make it fit and you chose how many pages you wanted your document to occupy. It did this by fiddling with margins, font size, line spacing etc.

So my question is, is it possible for this functionality to be created in Typst with some fancy code?

1 Like

Before deciding to crop, I tried to implement this, I found a code here in the forum that binary searches in a given range. I had min: 30% width and max: 100% width. If the block fits completely on the page and has some value within the range: use the max possible width value (a smaller width with same aspect ratio would also result in a smaller height). Otherwise: break the full block on the next page and use 100% width. This worked when no pagebreak was required. But it was not possible to create pagebreaks from this code. This would be my prefered solution since it minimizes the widthspace per column. But due to the missing pagebreak it did not work at all.

1 Like