When using PdfTextElement to layout multiple columns of text in a document, the object (PdfTextElement) should in my view be re-usable to layout the remainder of any text (if any). I did personally find a solution, which involves a bit of type casting, which I think could be supported in a more elegant way.
My approach:
PdfTextElement textElement = PdfTextElement(
text: text,
font: _robotoRegular10,
brush: __textBrush,
format: pdfStringFormat,
);
dynamic layoutResult = textElement.draw(
page: currentPage,
format: pdfLayoutFormat,
bounds: Rect.fromLTWH(
__left, __top + __topContent, __columnWidth, textColHeight),
);
text = layoutResult?.remainder?.trim();
if (text != null && text.isNotEmpty) {
textElement = PdfTextElement(
text: text,
font: _robotoRegular10,
brush: __textBrush,
format: pdfStringFormat,
);
layoutResult = textElement.draw(
page: currentPage,
format: pdfLayoutFormat,
bounds: Rect.fromLTWH(__left + __columnWidth + __columnSpacer,
__top + __topContent, __columnWidth, textColHeight),
);
text = layoutResult?.remainder?.trim();
}
What I would believe to be more elegant:
- have the textElement expose some way of knowing, if there is still remaining text to be layed out (hasMoreText?)
- upon a second call of .draw() on the same, original object, continue with the remainder of the text
Thank you for your consideration :)
kind regards, and stay safe,
Christoph Schwarz