Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The first image printed to PDF is invisible

The first image printed to PDF is invisible

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 7.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Feoran
    wrote on last edited by
    #1

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

    @
    QPrinter printer;
    // some code to configure the printer
    QPainter painter;
    painter.begin(&printer);
    // some code to paint the pages
    painter.end();
    @

    And the function that I use to print the images is @painter.drawPixmap();@.
    When I show the page in QPrintPreviewDialog, everything is okay. Also when I print the pages there is no problem.
    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      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":http://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!

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stukdev
          wrote on last edited by
          #4

          I have no problem with Pdf

          Simple example

          @
          QTextEdit document;
          document.append("test page");
          QPrinter printerPdf(QPrinter::HighResolution);
          printerPdf.setPageMargins(20,10,20,20,QPrinter::Millimeter);
          printerPdf.setOutputFileName("test.pdf");
          document.print(&printerPdf);
          @

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DenisKormalev
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stukdev
              wrote on last edited by
              #6

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

              @
              QPixmap pix(":/img/test.jpg");
              QPrinter printer;
              printer.setOutputFormat(QPrinter::PdfFormat);
              printer.setOutputFileName("test.pdf");
              QPainter painter;
              painter.begin(&printer);
              painter.drawPixmap(0,0,100,100,pix);
              painter.end();
              @

              1 Reply Last reply
              0
              • F Offline
                F Offline
                Feoran
                wrote on last edited by
                #7

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

                @
                QPrinter printer;
                printer.setOutputFormat(QPrinter::PdfFormat);
                printer.setOutputFileName("output.pdf");
                QPainter painter;
                painter.begin(&printer);
                painter.setBrush(Qt::transparent);
                painter.drawPixmap(0, 0, 100, 100, QPixmap("sample.png"));
                painter.drawPixmap(200, 0, 100, 100, QPixmap("sample.png"));
                painter.drawPixmap(0, 100, 100, 100, QPixmap("sample2.png"));
                painter.drawPixmap(200, 100, 100, 100, QPixmap("sample2.png"));
                painter.end();
                @
                Only the second sample.png and the second sample2.png will be visible.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    Feoran
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DenisKormalev
                      wrote on last edited by
                      #10

                      Feoran, please post link to bug here.

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        Feoran
                        wrote on last edited by
                        #11

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

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved