December 1, 2010

Feoran Feoran
Lab Rat
3 posts

The first image printed to PDF is invisible

 

I’ve been developing an application which user can design a page and print it. My printer function works like this:

  1. QPrinter printer;
  2. // some code to configure the printer
  3. QPainter painter;
  4. painter.begin(&printer);
  5. // some code to paint the pages
  6. painter.end();

And the function that I use to print the images is

  1. painter.drawPixmap();@.
  2. When I show the page in QPrintPreviewDialog, everything is okay. Also when I print the pages there is no problem.
  3. The problem appears when I print the file to PDF. To do this, I change the printer format using @printer.setOutputFormat(QPrinter::PdfFormat);

The first image that I printed to PDF file becomes invisible. When I print a copy of the same image to the same PDF file, it becomes visible. So the problem is only for the first copy of the image, when I paint the the same image second time or third time there is no problem.(These are not the same QPixmap objects. These are different QPixmap objects which are created from the same image file.) After painting an image, if I paint a different image for the first time, it also appears invisible.
I’ve spent a lot of time to solve the problem but still couldn’t find the solution.
I would appreciate any suggestions please.

10 replies

December 1, 2010

Tobias Hunger Tobias Hunger
Robot Herder
3387 posts

Do you have a small example project that shows this issue for us to play with?

This does sound very much like a bug to me, so maybe you should file it here [bugreports.qt.nokia.com]. A small example project attached to the report will help a lot to fix the issue as the developers will take way less time to reproduce the issue.

Thanks!

December 1, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

Tobias, I think that it also can be a problem in code. Not ever heard about problems on printing to pdf, so let’s wait for code sample.

December 2, 2010

stuk stuk
Ant Farmer
561 posts

I have no problem with Pdf

Simple example

  1. QTextEdit document;
  2. document.append("test page");
  3. QPrinter printerPdf(QPrinter::HighResolution);
  4. printerPdf.setPageMargins(20,10,20,20,QPrinter::Millimeter);
  5. printerPdf.setOutputFileName("test.pdf");
  6. document.print(&printerPdf);

December 2, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

stuk, post author said about problems printing images on pdf. Are you print text or images?

December 2, 2010

stuk stuk
Ant Farmer
561 posts

Yes, sorry i post mistake example…something like this..

  1.  
  2. QPixmap pix(":/img/test.jpg");
  3. QPrinter printer;
  4. printer.setOutputFormat(QPrinter::PdfFormat);
  5. printer.setOutputFileName("test.pdf");
  6. QPainter painter;
  7. painter.begin(&printer);
  8. painter.drawPixmap(0,0,100,100,pix);
  9. painter.end();

December 2, 2010

Feoran Feoran
Lab Rat
3 posts

I’ve found that the problem appears when I set the brush to Qt::transparent before painting the pixmap.

  1.     QPrinter printer;
  2.     printer.setOutputFormat(QPrinter::PdfFormat);
  3.     printer.setOutputFileName("output.pdf");
  4.     QPainter painter;
  5.     painter.begin(&printer);
  6.     painter.setBrush(Qt::transparent);
  7.     painter.drawPixmap(0, 0, 100, 100, QPixmap("sample.png"));
  8.     painter.drawPixmap(200, 0, 100, 100, QPixmap("sample.png"));
  9.     painter.drawPixmap(0, 100, 100, 100, QPixmap("sample2.png"));
  10.     painter.drawPixmap(200, 100, 100, 100, QPixmap("sample2.png"));
  11.     painter.end();

Only the second sample.png and the second sample2.png will be visible.

December 2, 2010

Andre Andre
Robot Herder
6395 posts

Sounds like a bug to me! Please file in the bug tracker.

December 2, 2010

Feoran Feoran
Lab Rat
3 posts

I have reported the bug thank you for your help. :)

December 2, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

Feoran, please post link to bug here.

December 2, 2010

Feoran Feoran
Lab Rat
3 posts

http://bugreports.qt.nokia.com/browse/QTBUG-15819

 
  ‹‹ [Solved] Linking with binary libraries compiled with other MSVC version      QMainWindow::statusBar() no object ››

You must log in to post a reply. Not a member yet? Register here!