Nominate our 2022 Qt Champions!

Qt - Poppler - Render to Image

  • Hello guys,

    I'm trying to display a PDF inside an image by doing this :

    //Load the PDF
                Poppler::Document * document = Poppler::Document::loadFromData(r);
                //Check if PDF was loaded and isn't locked.
                if(document != NULL) {
                    if(!document || document->isLocked()) {
                        delete document;
                        document = 0;
                    //Set different options of render to increase the quality of SVG.
                    //Creation of the image which will be displayed
                    image = new QImage(document->page(0)->pageSize().width(),document->page(0)->pageSize().height(), QImage::Format_ARGB32);
                    //Set the zone to extract, here, it's the entire first page
                    rect = new QRect(0, 0,document->page(0)->pageSize().width(),document->page(0)->pageSize().height());
                    QTextStream(stdout) << "Value of rect : x,y,w,h" << _x << "," << _y << "," <<_sizeWidth << ","<< _sizeHeight;
                    painterImage = new QPainter(image);
                    //Check if painter isn't null + paint into SVG
                    if(painterImage != NULL) {

    The render is good even if the quality isn't but anyway.

    Now, I'm trying to specific a zone of my PDF to extract. I mean that I want an image of 0,0 to 250,250 of the original PDF. I was trying to do that with QRect but it doesn't work because QPainter makes his paint inside a QRect of (0,0,250,250) and it's not what I want.

    What I want is to get an image of the zone QRect(0,0,250,250) of my pdf's page but it doesn't seem to be possible with this, am I wrong ?


  • Please keep in mind that a PDF Document has another coordinate System that QPainter.

    The PDF Coordinate System starts at the bottom left corner !

    Im nut 100% sure but i think you have to scale your painter by (1,-1).

    After that ther must be a scaling factor because PDF is alwas in mm not in pixel ( Pixel * 25,4 / DPI = MM)

Log in to reply