[Interest] Creating pdf with QTextDocument with chart
Duane
duane.hebert at group-upc.com
Mon Oct 26 16:54:45 CET 2015
On 26/10/2015 11:36 AM, Jason H wrote:
>
>> 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).
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
I don't think 4.8 has the ability to paint images in a document. It
looks like Qt5 would make a lot of this simpler.
What I have now is class that uses QTextDocument to build reports
containing tables and text. This can be saved as PDF. We have some
software we're updating that uses libharu to generate reports as PDFs.
These contain charts, text and tables. It would be quicker to add
something to my QTextDocument based class. But this is looking less
likely...
More information about the Interest
mailing list