PDA

View Full Version : How to print plot to PDF by paging?



lwz
9th September 2014, 13:15
We can print plot to pdf by paging with QPrinter's newpage function. But it seems we have to paint the whole plot as many times as the number of the pages and it takes much time.

Is there any suggestion ?


In the code , I use QwtPlot's drawItems function to print.

lwz
10th September 2014, 03:40
oh ,it works better to set drawitems‘ param QRectF &。
drawItems( QPainter *, const QRectF &rect,
const QwtScaleMap maps[axisCnt] )ï¼›

But still, plot’s axis would be painted。

Uwe
10th September 2014, 08:40
What exactly do you want to achieve: printing one plot in a huge size distributed over several pages ?

Uwe

lwz
10th September 2014, 09:34
yes, that’s right.

Uwe
10th September 2014, 10:30
In the end all high level APIs of QwtPlotRender end up in calling:


QwtPlotRenderer::render( QwtPlot *plot, QPainter *painter, const QRectF &plotRect )For your use case I would calculate a huge plot size - depending on the number of pages and the size of the plot area on a single page.
For printing a tile of the plot into an area on the current page all you need to do is to adjust top-left of plotRect and setting up a clip rectangle ( QPainter::setClipRect() ) for the tile before calling QwtPlotRenderer::render.

The disadvantage of this method is of course that QwtPlotRenderer::render has to be called several times - once for each page. If this is really a performance issue I would try to identify and avoid performance issues in QwtPlotRenderer::render itself first - before trying to avoid several calls.

Uwe

lwz
10th September 2014, 14:03
thanks for your advice, I‘ll try it。