[Interest] Creating pdf with QTextDocument with chart

Jason H jhihn at gmx.com
Mon Oct 26 16:36:33 CET 2015


> From: Duane <duane.hebert at group-upc.com>
>
> On 26/10/2015 11:04 AM, Michael Sué wrote:
> > Hi,
> >
> > Maybe you can use QPrinter using a QPainter:
> >
> > QPrinter printer;
> > printer.setOutputFileName("file.pdf");
> > QPainter painter(&printer);
> >
> > //paint the widget of your text document
> >
> 
> 
> I was just looking at that.  I think this would work but I'd have to 
> manually do the pagination that QTextDocument is already doing for me.
> What would be the quickest solution would be to somehow paint the chart 
> and insert that into a document.
> 

Yes, the manual pagination is a pain, but it is relatively simple. Depending on how you want to lay it out, it could still be easy. How do you want the chart displayed?
TEXT
CHART
TEXT

TEXT 
TEXT CHART
TEXT

If you can get the chart to be full-width or it's own page, it's simple. Otherwise you have to figure out how to wrap it. But basically given the complete QTextDocument, you copy words from it to a temporary document until the height of the wrapped text exceeds the page height, then you break, reset the page content and continue, until you hit the marker for the chart.

I forget if Qt 4.8 has a Image Provider capability, but you could in 5.x use chart://mycharts/chart_1 as a image URL, and probably still have QTextDocument lay it out for you. Otherwise, you have to convert it to an image and reference that image (probably on disk).





More information about the Interest mailing list