Question
Is there a way in Flutter to generate a PDF directly from a Flutter Canvas? Without writing separate drawing/rendering code for PDF export?
Details
We are currently implementing an application in Flutter which provides an editable canvas to the user. Imagine a vector illustration app where the use can freely edit a document.
Due to this we have the following requirements:
- The user can place vector objects (lines, rects, text, more complex figures) on the document, immediately visible on screen
- The user can print the document and/or export it to PDF
Qt for example provides a nice abstraction for this. First of all, QPainter can be used both for on-screen rendering and printing. And second, Qt allows to implement custom paint devices which in the end interprets the Qt drawing calls. This means that in cute objects just need to support a QPainter based rendering method in order to renderable for any output target (screen, pdf, printer, ...).
When looking at Flutter it seems that any flexibel custom rendering (via Canvas) is for screen only. And any print/PDF functionality, such as the "printing" package, uses custom classes for drawing. Thus requiring us to implement the rendering twice, once for screen and ones for printing/PDF. Using different classes for fonts, pens and the drawing API (drawLine, drawText, ...).
I know that I could render the Canvas into a bitmap and could draw that bitmap in the PDF. However, that way we'd loose the vector representation and end up with pixel bitmap, which is no option for us.
At the moment our conclusion is that we would need to implement an own abstraction layer when using Flutter.
Is this right?
Or did we miss something? Di we overlook a way to use the Flutter Canvas rendering calls for printing and PDF export as well?