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. Qt - Poppler - Render to Image
Forum Updated to NodeBB v4.3 + New Features

Qt - Poppler - Render to Image

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 2.5k 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.
  • L Offline
    L Offline
    Lordful
    wrote on 14 Mar 2016, 10:12 last edited by
    #1

    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.
                    document->setRenderHint(Poppler::Document::TextAntialiasing);
                    document->setRenderHint(Poppler::Document::Antialiasing);
                    document->setRenderHint(Poppler::Document::TextHinting);
                    document->setRenderHint(Poppler::Document::TextSlightHinting);
                    document->setRenderHint(Poppler::Document::ThinLineSolid);
    
                    document->setRenderBackend(Poppler::Document::ArthurBackend);
    
                    document->setPaperColor(Qt::transparent);
                    //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) {
                        painterImage->setViewport(*rect);
                        document->page(0)->renderToPainter(painterImage);
                        painterImage->end();
                    }
    

    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 ?

    Thanks

    1 Reply Last reply
    0
    • E Offline
      E Offline
      euchkatzl
      wrote on 14 Mar 2016, 15:52 last edited by
      #2

      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)

      1 Reply Last reply
      1

      1/2

      14 Mar 2016, 10:12

      • Login

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