PDA

View Full Version : Printing in Qt window with dotted lines produce huge PDF file and slow



lni
13th February 2014, 10:38
Hi,

I have grid lines with dotted line style, when print it into PDF in Windows, it creates huge PDF file (~100MB) and take ages to finish.

Printing solid line style is reasonable fast and file is less than 200k.

In linux, all are good.

Any one has any suggestions what may be wrong?

Thanks!

lni
14th February 2014, 08:24
Anyone please?

wysota
14th February 2014, 09:43
Do you use the exact same settings for printing on Windows and Linux? Looks like on Windows your code rasterizes every dot in a line.

lni
15th February 2014, 16:36
Yes, all codes are identical. Just recompile them.

I use Adobe Acrobat when printing to PDF on Windows.

I saw someone asking the same question at

http://stackoverflow.com/questions/18780563/printing-in-qt-on-windows-dotted-lines-lead-to-big-files

anda_skoa
15th February 2014, 17:26
I use Adobe Acrobat when printing to PDF on Windows.

Can you be a bit more specific who Adobe Acrobat is involved here?
Do you print using a PDF Pseudo printer provided by Adobe Acrobat?

Cheers,
_

lni
16th February 2014, 04:20
Can you be a bit more specific who Adobe Acrobat is involved here?
Do you print using a PDF Pseudo printer provided by Adobe Acrobat?

Cheers,
_

Yes, I use PDF Pseudo printer provided by Adobe Acrobat.

wysota
16th February 2014, 11:07
Yes, I use PDF Pseudo printer provided by Adobe Acrobat.

So shouldn't you be asking this question on Adobe forums? :)

Why don't you use PDF printing facilities built into Qt?

lni
17th February 2014, 04:03
So shouldn't you be asking this question on Adobe forums? :)

Why don't you use PDF printing facilities built into Qt?

I am using the one built by Qt.

When click "Print", It pops up a dialog to select a printer, and I can select a real printer, or "Adobe PDF" virtual printer. Then QGraphicsScene::render is called to print the content.

Do I use it wrong?

Thanks

ChrisW67
17th February 2014, 04:36
You are asking Qt to send the output to a printer. Qt does not care that is is not a physical printer or what that printer does with it. If Adobe's Distller chooses to make a high resolution raster image of a page that has nothing to do with Qt.

If you ask Qt to render directly to a PDF, with QPrinter::setOutputFormat() and QPrinter::setOutputFileName(), then you are likely to get a different result because Qt has some control. Try this experiment:


#include <QApplication>
#include <QPainter>
#include <QPrinter>
#include <QPen>

int main(int argc, char **argv)
{
QApplication app(argc, argv);
QPrinter printer(QPrinter::HighResolution);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("test.pdf");
QPainter p(&printer);
QRect rect = printer.pageRect();
rect.moveTo(0, 0);
p.setPen(QPen(Qt::DashLine));
p.drawRect(rect);
for (int i = 0; i < rect.height(); i += rect.height() / 50) {
p.drawLine(QPoint(0, i), QPoint(rect.width(), i));
}
p.end();

return 0;
}