Document Builder

Now that PDFDocument is available, it occurred to me that Xojo does not include a simple way to build a document. For example, if I wanted to construct a document the way I would in a word processor, I’d add sections, paragraphs, and tables, and each element would have settings that controlled how and where it appeared, would automatically wrap, include optional widow control for paragraphs, headers/footers for sections, etc.

To take a simple case, how would you easily create this paragraph in PDFDocument?

This is an example paragraph. It does not have any fancy features like indenting or outdenting but what it does have is styling. For example, that italicized word and bolding that starts in the middle of a sentence and wraps around to subsequent lines with additional text appearing after it.

Before I take the plunge and build such a thing, I wonder if there is already a class or module that does this?

My (limited) understanding is that Xojo’s PDF implementation is at a very low level, as it is integrated into the Graphics classes. So I wouldn’t expect anything fancy to have already been built. You’re probably the first.

Thanks. I just don’t want to recreate the wheel if there is already a project out there.

Did you try our DynaPDF Plugin?

We can process styled text there directly. Below a screenshot from sample app.

That’s helpful, thanks. I was looking for something that could leverage the new PDFDocument as native code or built into Xojo.

For that you need to have a very precise Stringwidth function, so you can process chunks of text, break lines and switch styles.
I don’t expect PDFDocument does that yet.

No, and supporting that is a big job because, potentially, each character has to be measured within its styling to support proper wrapping.

Would you try to support hyphenation and justification?

In this fantasy world where I’m actually working on this and I have unlimited time? Absolutely! :slight_smile:

It’s a lot of work. I did the one half to convert style command from Xojo to DynaPDF and then let DynaPDF do the heavy work internally.

See also my new blog post: DynaPDF vs. PDFDocument in Xojo