I have a real use for changing the color of the paper, as my application does copy-and-paste from multiple PDF files and it would indicate the source. But setPaperColor() does not do anything. Attached is a simple program that demonstrates this (change filename to point to a valid .pdf file on your system).

Is there any way to fix this?

FYI This is Mac OS X El Capitan, with Qt 5.9.1 installed via HomeBrew, and poppler-0.57.0.

Tom Roberts
#include <iostream>
#include <QString>
#include <QApplication>
#include <QImage>
#include <QPixmap>
#include <QLabel>
#include <QColor>

#include "poppler-qt5.h"

int main(int argc, char *argv[])
{
        QApplication app(argc,argv);

        QString filename = "../Test.pdf";
        Poppler::Document* document = Poppler::Document::load(filename);
        if (!document || document->isLocked()) {
                std::cerr << "Error in load()\n";
                delete document;
                return -1;
        }

        document->setPaperColor(QColor(255,0,0));

        // Access page of the PDF file
        int pageNumber = 0;
        Poppler::Page* pdfPage = document->page(pageNumber);
        if (pdfPage == 0) {
                std::cerr << "Error in page()\n";
                delete document;
                return -1;
        }

        // Generate a QImage of the rendered page
        int xres=72, yres=72;
        QImage image = pdfPage->renderToImage(xres, yres);
        if (image.isNull()) {
                std::cerr << "Error in renderToImage()\n";
                delete pdfPage;
                delete document;
                return -1;
        }

        QLabel *label = new QLabel();
        QPixmap p = QPixmap::fromImage(image);
        label->setPixmap(p);
        label->show();

        delete pdfPage;
        delete document;
        return app.exec();
}

_______________________________________________
poppler mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to