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. using QAxWidget to open pdf, printing is not working
Qt 6.11 is out! See what's new in the release blog

using QAxWidget to open pdf, printing is not working

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 4 Posters 5.8k Views 1 Watching
  • 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.
  • P philxxx609

    Hello guys,

    using the code bellow:
    PDF_Reader.pro

    QT       += core gui axcontainer printsupport
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = PDF_Reader
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    
    

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        pdf = new QAxWidget(this);
    
        if(!pdf->setControl("Adobe PDF Reader"))//("Microsoft Web Browser")
            QMessageBox::critical(this, "Error", "Make sure you have Adobe Reader (and its ActiveX) installed!");
    
        setCentralWidget(pdf);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_actionOpen_triggered()
    {
        /*pdf.dynamicCall("Navigate(const QString&)", QDir::toNativeSeparators(QFileDialog::getOpenFileName(this,
        "Open PDF File",
        QDir::currentPath(),
        "PDF Documents (*.pdf)")));*/
        pdf->dynamicCall("LoadFile(QString)",
                         QDir::toNativeSeparators(QFileDialog::getOpenFileName(this,
                                                                               "Open PDF File",
                                                                               QDir::currentPath(),
                                                                               "PDF Documents (*.pdf)")));
    }
    

    mainwindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <ActiveQt>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private slots:
        void on_actionOpen_triggered();
    
    private:
        Ui::MainWindow *ui;
    
        QAxWidget *pdf;
    
    };
    
    #endif // MAINWINDOW_H
    

    all is working fine except print button, nothing happen, no error, no printing dialog , why?

    thanks for your help

    Philippe

    H Offline
    H Offline
    hank17_0
    wrote on last edited by hank17_0
    #19

    @philxxx609 hi, I am using Adobe PDF Reader ActiveX Control in Qt.
    I run your code, but it didn't display the pdf file. I don't know what is wrong.
    It just display a gray background.
    WechatIMG152.jpeg
    WechatIMG153.jpeg
    thank for your help.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hank17_0
      wrote on last edited by hank17_0
      #20

      My Qt version is 5.15.2

      qDebug() << pdf->control(); // return the right UUID .
      qDebug() << pdf->dynamicCall("LoadFile(QString)", "E:/signed.pdf").toBool(); // return true
      
      JonBJ 1 Reply Last reply
      0
      • H hank17_0

        My Qt version is 5.15.2

        qDebug() << pdf->control(); // return the right UUID .
        qDebug() << pdf->dynamicCall("LoadFile(QString)", "E:/signed.pdf").toBool(); // return true
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #21

        @hank17_0
        I think you may have tried this, and I admit that you say the call returns true so it may not be a problem, but I wouldn't have passed a path with forward slashes to LoadFile, I would have passed a Windows path with backslashes.

        P.S.
        Otherwise, just maybe it has read the document but isn't showing a page? For all I know maybe you need SetCurrentPage(1). Or what about SetShowToolbar(true) or the SetPageMode("bookmarks") just to see whether either of these appear?

        H 2 Replies Last reply
        0
        • hskoglundH Online
          hskoglundH Online
          hskoglund
          wrote on last edited by
          #22

          Hi, totally agreeing with @JonB, forward slashes can spell trouble.

          Also, maybe that particular pdf has a problem (just guessing) why not try another PDF (from Wikipedia):

          qDebug() << pdf->dynamicCall("LoadFile(QString)", "http://tripleboot.org/Pictures/GettysburgAddress.pdf").toBool(); // return true
          
          H 1 Reply Last reply
          0
          • JonBJ JonB

            @hank17_0
            I think you may have tried this, and I admit that you say the call returns true so it may not be a problem, but I wouldn't have passed a path with forward slashes to LoadFile, I would have passed a Windows path with backslashes.

            P.S.
            Otherwise, just maybe it has read the document but isn't showing a page? For all I know maybe you need SetCurrentPage(1). Or what about SetShowToolbar(true) or the SetPageMode("bookmarks") just to see whether either of these appear?

            H Offline
            H Offline
            hank17_0
            wrote on last edited by
            #23

            @JonB Thanks for your reply. I will try it.

            1 Reply Last reply
            0
            • JonBJ JonB

              @hank17_0
              I think you may have tried this, and I admit that you say the call returns true so it may not be a problem, but I wouldn't have passed a path with forward slashes to LoadFile, I would have passed a Windows path with backslashes.

              P.S.
              Otherwise, just maybe it has read the document but isn't showing a page? For all I know maybe you need SetCurrentPage(1). Or what about SetShowToolbar(true) or the SetPageMode("bookmarks") just to see whether either of these appear?

              H Offline
              H Offline
              hank17_0
              wrote on last edited by
              #24

              @JonB still the same gray background. I used

              pdf->dynamicCall("SetCurrentPage(1)");
              pdf->dynamicCall("SetPageMode(\"bookmarks\")");
              

              nothing happened.

              I also use

              dumpcpp "{CA8A9780-280D-11CF-A24D-444553540000}"
              

              to generate acropdflib.cpp and acropdflib.h file.
              But when I use these file in my project, it can't complie.

              unknown type name '_IAcroAXDocShimEvents'.
              
              1 Reply Last reply
              0
              • hskoglundH hskoglund

                Hi, totally agreeing with @JonB, forward slashes can spell trouble.

                Also, maybe that particular pdf has a problem (just guessing) why not try another PDF (from Wikipedia):

                qDebug() << pdf->dynamicCall("LoadFile(QString)", "http://tripleboot.org/Pictures/GettysburgAddress.pdf").toBool(); // return true
                
                H Offline
                H Offline
                hank17_0
                wrote on last edited by
                #25

                @hskoglund Hi thank you for your advice. I try another pdf file, but not work.

                1 Reply Last reply
                0
                • hskoglundH Online
                  hskoglundH Online
                  hskoglund
                  wrote on last edited by hskoglund
                  #26

                  Hmm, COM technology is old, maybe you're compiling/building for 64-bits?
                  Try 32-bit, it should work better.

                  1 Reply Last reply
                  0
                  • hskoglundH Online
                    hskoglundH Online
                    hskoglund
                    wrote on last edited by
                    #27

                    Yes, just to confirm, I built the app both in MSVC2019 32-bit and 64-bit versions. Both version gave the same qDebug() output and no errors.
                    But the 64-bit version returns only a grey page (same as you got).
                    The 32-bit version works.

                    P.S: More users have had this problem, eg. https://forum.qt.io/topic/119455/qaxwidget-adobe-pdf-reader-working-with-kit-qt-5-14-1-msvc2017-32-but-not-with-kit-with-qt-5-14-1-msvc2017-64

                    H 2 Replies Last reply
                    2
                    • hskoglundH hskoglund

                      Yes, just to confirm, I built the app both in MSVC2019 32-bit and 64-bit versions. Both version gave the same qDebug() output and no errors.
                      But the 64-bit version returns only a grey page (same as you got).
                      The 32-bit version works.

                      P.S: More users have had this problem, eg. https://forum.qt.io/topic/119455/qaxwidget-adobe-pdf-reader-working-with-kit-qt-5-14-1-msvc2017-32-but-not-with-kit-with-qt-5-14-1-msvc2017-64

                      H Offline
                      H Offline
                      hank17_0
                      wrote on last edited by
                      #28

                      @hskoglund Thanks for your reply. I will try it tomorrow. Very appreciate.

                      1 Reply Last reply
                      0
                      • hskoglundH hskoglund

                        Yes, just to confirm, I built the app both in MSVC2019 32-bit and 64-bit versions. Both version gave the same qDebug() output and no errors.
                        But the 64-bit version returns only a grey page (same as you got).
                        The 32-bit version works.

                        P.S: More users have had this problem, eg. https://forum.qt.io/topic/119455/qaxwidget-adobe-pdf-reader-working-with-kit-qt-5-14-1-msvc2017-32-but-not-with-kit-with-qt-5-14-1-msvc2017-64

                        H Offline
                        H Offline
                        hank17_0
                        wrote on last edited by
                        #29

                        @hskoglund Yes, it works. Build with MSVC2019 32-bit works. Thanks for your help.

                        1 Reply Last reply
                        0

                        • Login

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