Results 1 to 5 of 5

Thread: [SOLVED] Using QPainter to Import JPG for PDF Report

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default [SOLVED] Using QPainter to Import JPG for PDF Report

    Qt Version: 5.3.1
    OS: CentOS 6.5

    I'm attempting to create a PDF report using QPainter.
    This seems to work better than using QTextDocument.
    However, I am faced with an issue involving certain graphics files when I attempt to load them.

    I have a JPEG file that contains a company logo (attached). When loaded in the GNOME image viewer, the tool indicates the image is 170 pixels x 80 pixels.

    I have attempted to use QPixmap and QImage as the mechanism for loading and putting the image into the QPainter object that then dump to PDF.

    Here is the issue:
    The QPixmap method produces an image that is extremely small in the PDF file. If I attempt to scale it up, the image quality becomes very poor.
    The QImage method produces no image in the PDF file.

    Here is the code:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPdfWriter>
    3. #include <QPainter>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. QPdfWriter pdfWriter("my.pdf");
    10. QPainter painter(&pdfWriter);
    11. quint32 iYPos = 10;
    12.  
    13. QPixmap pxPic;
    14. pxPic.load("/usr/local/SMART/public_html/images/logo.jpg", "JPG");
    15. painter.drawPixmap(0, iYPos, pxPic.width(), pxPic.height(), pxPic);
    16. iYPos += pxPic.height() + 250;
    17.  
    18. QImage imgPic;
    19. imgPic.load("/usr/local/SMART/public_html/images/logo.jpg", "JPG");
    20. painter.drawImage(0, iYPos, imgPic, imgPic.width(), imgPic.height());
    21.  
    22. return 0;
    23. }
    To copy to clipboard, switch view to plain text mode 

    I would appreciate any input as to how to make this work.

    Karl
    Attached Images Attached Images
    Last edited by KaptainKarl; 20th October 2014 at 21:01. Reason: Problem is solved. Wanted to reflect that in the title.

Similar Threads

  1. Report library for QT
    By blackliteon in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2014, 08:23
  2. Replies: 0
    Last Post: 17th November 2009, 20:59
  3. QT report
    By triperzz in forum Qt Programming
    Replies: 3
    Last Post: 25th February 2008, 17:58
  4. Crash report
    By Lele in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2007, 09:50
  5. error report
    By Rekha in forum Newbie
    Replies: 1
    Last Post: 14th August 2006, 12:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.