Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to handle images in a proper way by rendering from QPdfDocument



  • Dear all,

    I want to extract an image from a PDF document. The PDF document page is the following:

    42bf7953-49d5-4106-ba75-035b932b32dc-grafik.png

    using the QPdfDocument class I rendered an image using

    QPdfDocument pdf;
    pdf.load("test.pdf");
    const int n = 0;
    QImage qimg = pdf.render(n,pdf.pageSize(n).toSize());
    qimg = qimg.convertToFormat(QImage::Format_RGB888);

    The rendered image looks like:

    0a59206b-ffa4-497d-b98c-adce729acf08-grafik.png

    Extracting the image's alpha channel by using

    QImage alpha = qimg.convertToFormat(QImage::Format_Alpha8);
    alpha.invertPixels(QImage::InvertRgba);

    I get:

    392b1a2d-d93a-4396-a32c-25f67c69d46c-grafik.png

    As mentioned in an earlier post I just want to render an image of the PDF page that looks the same as the pdf page itsself, no fancy stuff. I guess I somehow have to combine or convert the upper both images. I'd be grateful if someone has an idea of how to get things done.

    Cheers


Log in to reply