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

can't compile QtPdfium



  • Hello,
    I want to extract text from PDF so I tried QPdfium From here
    I tried to compile the library using QT 5.12.0 with Mingw32 compiler I followed this steps

    1 - I open the qtpdfium.pro in release mode and I downloaded the PDFIUM third-party library and add it's content to the folder

    2 - I compiled and I got this error

    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fsdk_actionhandler.cpp:425: error: 'class CPDF_Dest' has no member named 'GetObjectW'; did you mean 'GetObject'?
       const CPDF_Array* pMyArray = ToArray(MyDest.GetObject());
                                                   ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:447: error: 'g_pdfium_print_postscript_level' was not declared in this scope
       g_pdfium_print_postscript_level = postscript_level;
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fsdk_actionhandler.cpp:425: error: 'class CPDF_Dest' has no member named 'GetObjectW'; did you mean 'GetObject'?
       const CPDF_Array* pMyArray = ToArray(MyDest.GetObject());
                                                   ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:681: error: no matching function for call to 'MakeUnique<<expression error> >(HDC__*&)'
         pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
                                                                       ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:681: error: template argument 1 is invalid
         pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
                                                                       ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:681: error: template argument 1 is invalid
         pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
                                                                       ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:681: error: template argument 1 is invalid
         pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
                                                                       ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:688: error: 'CFX_WindowsDevice' was not declared in this scope
         CFX_WindowsDevice WinDC(dc);
         ^~~~~~~~~~~~~~~~~
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:689: error: 'WinDC' was not declared in this scope
         if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) {
             ^~~~~
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:447: error: 'g_pdfium_print_postscript_level' was not declared in this scope
       g_pdfium_print_postscript_level = postscript_level;
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:681: error: 'CFX_WindowsDevice' was not declared in this scope
         pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
                                                  ^~~~~~~~~~~~~~~~~
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:681: error: no matching function for call to 'MakeUnique<<expression error> >(HDC__*&)'
         pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
                                                                       ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:681: error: template argument 1 is invalid
         pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
                                                                       ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:681: error: template argument 1 is invalid
         pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
                                                                       ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:681: error: template argument 1 is invalid
         pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
                                                                       ^
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:688: error: 'CFX_WindowsDevice' was not declared in this scope
         CFX_WindowsDevice WinDC(dc);
         ^~~~~~~~~~~~~~~~~
    D:\build\qtpdfium-master\src\3rdparty\pdfium\fpdfsdk\fpdfview.cpp:689: error: 'WinDC' was not declared in this scope
         if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) {
             ^~~~~
    

    so what the problem I did to not compile so I can fix it, or if someone compiled it before and have the binaries please upload it.
    Thanks in advance.


  • Lifetime Qt Champion

    Hi,

    What you are showing doesn't contain the original error. Search for that one.



  • I Updated the question


  • Lifetime Qt Champion

    Hi
    From
    https://pdfium.googlesource.com/pdfium/+/master/README.md
    The lib QPdfium uses.

    it says
    Windows development
    PDFium uses the same build tool as Chromium:

    so that makes we wonder if its even possible to build with mingw ?



  • @mrjjI don't know but even if I built using MSVC I got more errors, all I want is a good library to read data from PDF file I can use with my Qt application I tested QPoppler but same problem I can't compile it, gives me a lot of errors and it needs a lot of dependencies, when I used it, it was old precompiled library I download it, so I can't update to the last Poppler release with the new futures because there are no precompiled libraries to download I must compile it.


  • Lifetime Qt Champion

    @AmrCoder
    Hi
    When i read what QtPdfium does, it sounds like it can display pdf files but im not sure you can extract text with it.
    If the goal is only to extract text from pdf, you could cheat and just use QProcess to call a tool to do it for you.
    https://en.wikipedia.org/wiki/Pdftotext



  • This example on the GitHub

    And for extracting text:
    
    #include <QtPdfium/QPdfium>
    
    QPdfium pdf("mypdf.pdf");
    QPdfiumPage page =  pdf.page(0);
    QString pageText = page.text();
    

    yes i see but i want to do it throw a code in my application if possible.


  • Lifetime Qt Champion

    @AmrCoder
    Ah good. I miss that part.
    Well should work fine then.
    Ok, i understand you want it in-app.
    It was just case it was option to use external tool :)



  • Any progress on this?

    I have the same error. The code that bugs requires CFX_WindowsDevice to be defined.
    This piece of code is conditionally compiled when _WIN_32 define is set.
    This is not the case by default, the "platform" is set to QT whatever it means.

    Someone didn't make a proper job with those defines.
    @AmrCoder If you somehow managed to solve this, please share the solution. The code works on linux.



  • @Pietrko, to be honest, I gave up after I got no answer but iam still actually interesting to make it works, so what should I add to make it work on windows please if you can post it step by step, I understand it should be cross-platform but for now I want to make it work on windows
    Thank you.



  • I tried to download the Pdfium from Google using this command

    git clone https://pdfium.googlesource.com/pdfium
    

    it downloads about 129 MB file not as the Pdfium that comes with the QPdfium which is 29 MB, then i replace it and compile I got this error

    :-1: error: No rule to make target 'D:/cook/qtpdfium-master/src/3rdparty/pdfium/fpdfsdk/cba_annotiterator.cpp', needed by '.obj/debug/cba_annotiterator.o'.  Stop.
    

    I found many version of Pdfium each one has some files missing and give me this error each time with different file when I search on this file on google I got a GitHub Link which contains a pdfium source code which contains this file, when I download this one it missing other files, so is there anyway to make it work on windows I don't need cross-compiling Now.



  • I managed to get it work.
    You have to either patch like four files from pdfium or use "espen/compile-on-mingw" branch of this fork of qpdfium:

    Remember to use "espen/compile-on-mingw" branch on qtpdifum and this branch "https://github.com/snowpong/pdfium/tree/g_38c2705c
    on snowpong pdfium repo.

    BTW: even this guy made a mistake and put "qt" branch in .gitmodules insgtead of g_38c2705c
    Fix that.

    I hope you know how to update submodules of git repo.
    GL, it works


Log in to reply