Appending multiple images with QPainter and poppler results in black pages

  • Hello there

    I wrote a very basic PDF reader, based on poppler. The idea is to read every page, convert it to an QImage and in the end append it. The problem is, that afer page 24 I just see black pages. Is this a limitation in QPainter/QImage or did I make a mistake ? Is there a better way to append images or can anybody recommend a good Qt PDF library (GPL3) ?

    @#include "FastLatexPDFWidget.h"

    FastLatexPDFWidget::FastLatexPDFWidget(const QString &filepath, QWidget *parent) : QLabel(parent)
    Poppler::Document *document = Poppler::Document::load(filepath);
    if(document && !document->isLocked())
    // Document attributes
    int maxwidth = 0;
    int maxheight = 0;

    // Contains each page as QImage (1 QImage = 1 Page)
    QList<QImage> listImages;

    // Iterate over the document
    for(int i = 0; i < document->numPages(); i++)
    // Load the page as QImage and append it to the list
    Poppler::Page *page = document->page(i);
    QImage image = page->renderToImage(physicalDpiX(), physicalDpiY());

    // Release the page
    delete page;

    int width = image.width();
    int height = image.height();

    // Vertical or horizontal orientation - take care of that and increase the width
    if(width > maxwidth)
    maxwidth = width;

    // Add height
    maxheight += height;

    // Now create the output image
    QImage output(maxwidth, maxheight, QImage::Format_RGB32);

    // Create a painter object and set it to the output image
    QPainter painter;

    // Attribute for the passed height during drawing
    int passedheight = 0;

    // Now draw the images from the list
    for(int i = 0; i < listImages.count(); i++)
    QImage image =;
    painter.drawImage(0, passedheight, image);
    passedheight += image.height();

    // Now stop the painter

    // Add the image to the label

    // Release the document
    delete document;

    // @TESTING
    Q_ASSERT(maxheight == passedheight);

    Thanks in advice

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.