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

using QAxWidget to open pdf, printing is not working

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 4 Posters 4.6k 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 Offline
    P Offline
    philxxx609
    wrote on 18 Jul 2020, 11:22 last edited by
    #1

    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 1 Reply Last reply 17 Jun 2021, 07:49
    0
    • H Online
      H Online
      hskoglund
      wrote on 18 Jul 2020, 11:37 last edited by
      #2

      Hi, all looks good except

      ...
      setCentralWidget(pdf);
      ...
      

      it probably will just shanghai all of your mainwindiow, try giving Adobe Reader just a part of your mainwindow, :
      ...
      // setCentralWidget(pdf);
      pdf->setGeometry(10,10,500,500);
      ...

      P 1 Reply Last reply 18 Jul 2020, 12:14
      1
      • H hskoglund
        18 Jul 2020, 11:37

        Hi, all looks good except

        ...
        setCentralWidget(pdf);
        ...
        

        it probably will just shanghai all of your mainwindiow, try giving Adobe Reader just a part of your mainwindow, :
        ...
        // setCentralWidget(pdf);
        pdf->setGeometry(10,10,500,500);
        ...

        P Offline
        P Offline
        philxxx609
        wrote on 18 Jul 2020, 12:14 last edited by
        #3

        @hskoglund Hi, I try already but nothing changed

        1 Reply Last reply
        0
        • H Online
          H Online
          hskoglund
          wrote on 18 Jul 2020, 14:07 last edited by
          #4

          Hi. just tried your project on my Windows 10 PC. using Qt 5.15.0 MinGW32.
          I couldn't get your on_actionOpen_triggered() to work (is that a signal from your menu perhaps?) so I instead added a QPushButton to start Adobe Reader.

          So my mainwindow.cpp looks like this:

          #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);
              pdf->setGeometry(10,10,500,500);
          
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          
          
          void MainWindow::on_pushButton_clicked()
          {
              pdf->dynamicCall("LoadFile(QString)",
                  QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, "Open PDF File",  QDir::currentPath(), "PDF Documents (*.pdf)")));
          

          I downloaded and installed Adobe Reader, when I start the program, I click on the button, select a PDF and the screen looks like this:
          ScreenShot.png

          On Adobe Readers' black ribbon I click on the 2nd left print Icon, and then I can print:
          Screenshot 2020-07-18 at 16.04.31.png

          P 1 Reply Last reply 18 Jul 2020, 16:10
          2
          • H hskoglund
            18 Jul 2020, 14:07

            Hi. just tried your project on my Windows 10 PC. using Qt 5.15.0 MinGW32.
            I couldn't get your on_actionOpen_triggered() to work (is that a signal from your menu perhaps?) so I instead added a QPushButton to start Adobe Reader.

            So my mainwindow.cpp looks like this:

            #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);
                pdf->setGeometry(10,10,500,500);
            
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            
            
            void MainWindow::on_pushButton_clicked()
            {
                pdf->dynamicCall("LoadFile(QString)",
                    QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, "Open PDF File",  QDir::currentPath(), "PDF Documents (*.pdf)")));
            

            I downloaded and installed Adobe Reader, when I start the program, I click on the button, select a PDF and the screen looks like this:
            ScreenShot.png

            On Adobe Readers' black ribbon I click on the 2nd left print Icon, and then I can print:
            Screenshot 2020-07-18 at 16.04.31.png

            P Offline
            P Offline
            philxxx609
            wrote on 18 Jul 2020, 16:10 last edited by
            #5

            @hskoglund could you send me the link of the acrobat you had installed? trying with the qt 5.15 mingw32 same problem no printing even changing

                setCentralWidget(pdf);
               //pdf->setGeometry(10,10,500,500);
            

            to

                //setCentralWidget(pdf);
               pdf->setGeometry(10,10,500,500);
            
            1 Reply Last reply
            0
            • H Online
              H Online
              hskoglund
              wrote on 18 Jul 2020, 16:23 last edited by
              #6

              It is the standard DC reader:
              https://get.adobe.com/reader/

              P 1 Reply Last reply 18 Jul 2020, 16:25
              1
              • H hskoglund
                18 Jul 2020, 16:23

                It is the standard DC reader:
                https://get.adobe.com/reader/

                P Offline
                P Offline
                philxxx609
                wrote on 18 Jul 2020, 16:25 last edited by
                #7

                @hskoglund may be could you send me the full code you use then, I don't understand what is wrong on my side...

                I change pdf->setGeometry(0,20,800,800); to be able to see the file upload button

                1 Reply Last reply
                0
                • H Online
                  H Online
                  hskoglund
                  wrote on 18 Jul 2020, 16:48 last edited by
                  #8

                  You mean you don’t get the black ribbon to appear?

                  Anyway, my project Iis almost the same as your project, I only added a QPushButton and a slot for it.
                  I’ll upload it when I get back to my PC, taking a walk right now...

                  1 Reply Last reply
                  1
                  • H Online
                    H Online
                    hskoglund
                    wrote on 18 Jul 2020, 18:39 last edited by
                    #9

                    Hi, my project is here

                    But don't worry, there's more than one way to skin a cat, got an idea during my walk: since we've loaded Adobe DC Reader via COM/QAxObject, you can instruct it to print through COM instead of the black ribbon.

                    So I created another QPushButton (it's in the uploaded project):

                    Screenshot 2020-07-18 at 20.31.02.png

                    The 2nd QPushButton has this line:

                    void MainWindow::on_pushButton_2_clicked()
                    {
                        pdf->dynamicCall("Print()");
                    }
                    

                    Pressing that button, voila, the print dialog appears :-)

                    P 1 Reply Last reply 19 Jul 2020, 14:24
                    1
                    • H hskoglund
                      18 Jul 2020, 18:39

                      Hi, my project is here

                      But don't worry, there's more than one way to skin a cat, got an idea during my walk: since we've loaded Adobe DC Reader via COM/QAxObject, you can instruct it to print through COM instead of the black ribbon.

                      So I created another QPushButton (it's in the uploaded project):

                      Screenshot 2020-07-18 at 20.31.02.png

                      The 2nd QPushButton has this line:

                      void MainWindow::on_pushButton_2_clicked()
                      {
                          pdf->dynamicCall("Print()");
                      }
                      

                      Pressing that button, voila, the print dialog appears :-)

                      P Offline
                      P Offline
                      philxxx609
                      wrote on 19 Jul 2020, 14:24 last edited by
                      #10

                      @hskoglund Hello, thanks a lot but same issue with your test project, nothing happen when click on print button...

                      P 1 Reply Last reply 19 Jul 2020, 15:13
                      0
                      • P philxxx609
                        19 Jul 2020, 14:24

                        @hskoglund Hello, thanks a lot but same issue with your test project, nothing happen when click on print button...

                        P Offline
                        P Offline
                        philxxx609
                        wrote on 19 Jul 2020, 15:13 last edited by
                        #11

                        @philxxx609 I will try to reinstall QT in case...
                        Other question, may it possible to pass argument with QAxWidget?

                        I would like open my pdf to specific page, the argument following acrobat is "page= page number" ea. "page=15"

                        Thank you for your help

                        1 Reply Last reply
                        0
                        • H Online
                          H Online
                          hskoglund
                          wrote on 20 Jul 2020, 15:30 last edited by
                          #12

                          Hi, to open on a specific page, easiest is to say to Adobe Reader to go to that page after the open() call, say like this:

                          void MainWindow::on_pushButton_clicked()
                          {
                              pdf->dynamicCall("LoadFile(QString)",
                                  QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, "Open PDF File", QDir::currentPath(), "PDF Documents (*.pdf)")));
                          
                              pdf->dynamicCall("SetCurrentPage(int)",15);
                          }
                          

                          But why doesn't it work for you, perhaps Adobe Reader wasn't installed properly or you have a copy (there a too many of them in the Microsoft Store :-(

                          To check that have you the real Adobe Reader installed, you get print out it's UUID, see what pdf->control() returns for you::

                              pdf = new QAxWidget(this);
                          
                              if(!pdf->setControl("Adobe PDF Reader"))
                                  QMessageBox::critical(this, "Error", "Make sure you have Adobe Reader (and its ActiveX) installed!");
                          
                              qDebug() << pdf->control();    // show the UUID of the widget
                          
                              pdf->setGeometry(10,10,500,500);
                          }
                          

                          qDebug() should show a string starting with ( and some hexadecimal numbers and then ending with a }...

                          P 1 Reply Last reply 22 Jul 2020, 08:13
                          2
                          • H hskoglund
                            20 Jul 2020, 15:30

                            Hi, to open on a specific page, easiest is to say to Adobe Reader to go to that page after the open() call, say like this:

                            void MainWindow::on_pushButton_clicked()
                            {
                                pdf->dynamicCall("LoadFile(QString)",
                                    QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, "Open PDF File", QDir::currentPath(), "PDF Documents (*.pdf)")));
                            
                                pdf->dynamicCall("SetCurrentPage(int)",15);
                            }
                            

                            But why doesn't it work for you, perhaps Adobe Reader wasn't installed properly or you have a copy (there a too many of them in the Microsoft Store :-(

                            To check that have you the real Adobe Reader installed, you get print out it's UUID, see what pdf->control() returns for you::

                                pdf = new QAxWidget(this);
                            
                                if(!pdf->setControl("Adobe PDF Reader"))
                                    QMessageBox::critical(this, "Error", "Make sure you have Adobe Reader (and its ActiveX) installed!");
                            
                                qDebug() << pdf->control();    // show the UUID of the widget
                            
                                pdf->setGeometry(10,10,500,500);
                            }
                            

                            qDebug() should show a string starting with ( and some hexadecimal numbers and then ending with a }...

                            P Offline
                            P Offline
                            philxxx609
                            wrote on 22 Jul 2020, 08:13 last edited by philxxx609
                            #13

                            @hskoglund said in using QAxWidget to open pdf, printing is not working:
                            thanks a lot, where did you find the property associated with acrobat to found :

                            pdf->dynamicCall("SetCurrentPage(int)",15); ?

                            Because I want also to set toolbar to 0 but I don't know how to do that.

                            After did qdebug as you say, I received clid: CA8A9780-280D-11CF-A24D-444553540000 then I think it's the good one but after completly re-install windows from zero and then Qt, the problem for printing stay the same, I don't know what happen...

                            for info, with:
                            qDebug()<<pdf->dynamicCall("Print()");

                            I received:
                            QVariant(Invalid)

                            1 Reply Last reply
                            0
                            • H Online
                              H Online
                              hskoglund
                              wrote on 22 Jul 2020, 09:08 last edited by
                              #14

                              Also, have you checked that you can print manually, I mean: if you open a PDF in Adobe Reader by hand, can you print it if you click Print?

                              P 1 Reply Last reply 22 Jul 2020, 09:24
                              0
                              • H hskoglund
                                22 Jul 2020, 09:08

                                Also, have you checked that you can print manually, I mean: if you open a PDF in Adobe Reader by hand, can you print it if you click Print?

                                P Offline
                                P Offline
                                philxxx609
                                wrote on 22 Jul 2020, 09:24 last edited by
                                #15

                                @hskoglund Yes But now I can not explain why but I can print... my problem is solved but I don't know how...

                                to found acrobat property I found :
                                https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_api_reference.pdf

                                All what I need is in there so perfect but one command is strange for me:

                                SetViewMode(long nType)

                                width nType possible value:
                                PDDontCare: Leave the view mode as it is.
                                PDUseNone : Display the document, but neither bookmarks nor
                                thumbnail images.
                                PDUseThumbs: Display the document and thumbnail images.
                                PDUseBookmarks: Display the document and bookmarks.
                                PDFullScreen: Display the document in full-screen mode.

                                do you know how I have to use it?

                                thank you very much for your precious help!!

                                P 1 Reply Last reply 22 Jul 2020, 10:36
                                0
                                • P philxxx609
                                  22 Jul 2020, 09:24

                                  @hskoglund Yes But now I can not explain why but I can print... my problem is solved but I don't know how...

                                  to found acrobat property I found :
                                  https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_api_reference.pdf

                                  All what I need is in there so perfect but one command is strange for me:

                                  SetViewMode(long nType)

                                  width nType possible value:
                                  PDDontCare: Leave the view mode as it is.
                                  PDUseNone : Display the document, but neither bookmarks nor
                                  thumbnail images.
                                  PDUseThumbs: Display the document and thumbnail images.
                                  PDUseBookmarks: Display the document and bookmarks.
                                  PDFullScreen: Display the document in full-screen mode.

                                  do you know how I have to use it?

                                  thank you very much for your precious help!!

                                  P Offline
                                  P Offline
                                  philxxx609
                                  wrote on 22 Jul 2020, 10:36 last edited by philxxx609
                                  #16

                                  @philxxx609 I find other link with answers of my question, acrobat change every thing for each version :-(
                                  https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_api_reference.pdf#G4.1514939

                                  pdf->dynamicCall("SetShowToolbar(bool)",false);
                                  pdf->dynamicCall("SetPageMode(BSTR)","thumbs");

                                  I still have to find how to hide the left tool panel at startup because it's heavy to close it each time...

                                  bu at the moment, I don't found any command for it...

                                  1 Reply Last reply
                                  0
                                  • H Online
                                    H Online
                                    hskoglund
                                    wrote on 22 Jul 2020, 10:52 last edited by
                                    #17

                                    Very nice googling! And congratulations on getting printing to work :-)

                                    Adobe Reader is at least 20 years old program, so it's no wonder the documentation is changing. So what I do, I have a "COM-dump" program (I wrote it a maybe 2 years ago for someone on this forum who wanted to know every function/property of Excel). So I run on it "Adobe PDF Reader", here's an excerpt of the output:

                                    IDispatch callable type: "IAcroAXDocShim"
                                    "Property" "src" ()
                                    "Function" "LoadFile" ("fileName")
                                    "Function" "setShowToolbar" ("On")
                                    "Function" "gotoFirstPage" ()
                                    "Function" "gotoLastPage" ()
                                    "Function" "gotoNextPage" ()
                                    "Function" "gotoPreviousPage" ()
                                    "Function" "setCurrentPage" ("n")
                                    "Function" "goForwardStack" ()
                                    "Function" "goBackwardStack" ()
                                    "Function" "setPageMode" ("pageMode")
                                    "Function" "setLayoutMode" ("layoutMode")
                                    "Function" "setNamedDest" ("namedDest")
                                    "Function" "Print" ()
                                    "Function" "printWithDialog" ()
                                    "Function" "setZoom" ("percent")
                                    "Function" "setZoomScroll" ("percent", "left", "top")
                                    "Function" "setView" ("viewMode")
                                    "Function" "setViewScroll" ("viewMode", "offset")
                                    "Function" "setViewRect" ("left", "top", "width", "height")
                                    "Function" "printPages" ("from", "to")
                                    "Function" "printPagesFit" ("from", "to", "shrinkToFit")
                                    "Function" "printAll" ()
                                    "Function" "printAllFit" ("shrinkToFit")
                                    "Function" "setShowScrollbars" ("On")
                                    "Function" "GetVersions" ()
                                    "Function" "setCurrentHightlight" ("a", "b", "c", "d")
                                    "Function" "setCurrentHighlight" ("a", "b", "c", "d")
                                    "Function" "postMessage" ("strArray")
                                    "Property" "messageHandler" ()
                                    "Function" "execCommand" ("strArray")
                                    

                                    Maybe "setLayoutMode" is what you're looking for...

                                    P 1 Reply Last reply 22 Jul 2020, 16:36
                                    2
                                    • H hskoglund
                                      22 Jul 2020, 10:52

                                      Very nice googling! And congratulations on getting printing to work :-)

                                      Adobe Reader is at least 20 years old program, so it's no wonder the documentation is changing. So what I do, I have a "COM-dump" program (I wrote it a maybe 2 years ago for someone on this forum who wanted to know every function/property of Excel). So I run on it "Adobe PDF Reader", here's an excerpt of the output:

                                      IDispatch callable type: "IAcroAXDocShim"
                                      "Property" "src" ()
                                      "Function" "LoadFile" ("fileName")
                                      "Function" "setShowToolbar" ("On")
                                      "Function" "gotoFirstPage" ()
                                      "Function" "gotoLastPage" ()
                                      "Function" "gotoNextPage" ()
                                      "Function" "gotoPreviousPage" ()
                                      "Function" "setCurrentPage" ("n")
                                      "Function" "goForwardStack" ()
                                      "Function" "goBackwardStack" ()
                                      "Function" "setPageMode" ("pageMode")
                                      "Function" "setLayoutMode" ("layoutMode")
                                      "Function" "setNamedDest" ("namedDest")
                                      "Function" "Print" ()
                                      "Function" "printWithDialog" ()
                                      "Function" "setZoom" ("percent")
                                      "Function" "setZoomScroll" ("percent", "left", "top")
                                      "Function" "setView" ("viewMode")
                                      "Function" "setViewScroll" ("viewMode", "offset")
                                      "Function" "setViewRect" ("left", "top", "width", "height")
                                      "Function" "printPages" ("from", "to")
                                      "Function" "printPagesFit" ("from", "to", "shrinkToFit")
                                      "Function" "printAll" ()
                                      "Function" "printAllFit" ("shrinkToFit")
                                      "Function" "setShowScrollbars" ("On")
                                      "Function" "GetVersions" ()
                                      "Function" "setCurrentHightlight" ("a", "b", "c", "d")
                                      "Function" "setCurrentHighlight" ("a", "b", "c", "d")
                                      "Function" "postMessage" ("strArray")
                                      "Property" "messageHandler" ()
                                      "Function" "execCommand" ("strArray")
                                      

                                      Maybe "setLayoutMode" is what you're looking for...

                                      P Offline
                                      P Offline
                                      philxxx609
                                      wrote on 22 Jul 2020, 16:36 last edited by philxxx609
                                      #18

                                      @hskoglund I try layout but that is not this command.

                                      Any way my better problem has been solve then that is fine, thank you very much for all you do for me!!!

                                      kind regards

                                      Philippe

                                      here my last command is case any one need it:

                                          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!");
                                          currentPage=0;
                                          pdf->dynamicCall("LoadFile(QString)",QDir::toNativeSeparators("./saft.pdf"));
                                          pdf->dynamicCall("SetCurrentPage(int)",currentPage);
                                          pdf->dynamicCall("SetShowToolbar(bool)",false);
                                          pdf->dynamicCall("SetPageMode(BSTR)","bookmarks");//"none"//"thumbs";
                                      

                                      my mainwindow.cpp to mix qml and QWidget:

                                      MainWindow::MainWindow(QWidget *parent) :
                                          QWidget(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!");
                                          currentPage=0;
                                          pdf->dynamicCall("LoadFile(QString)",QDir::toNativeSeparators("./saft.pdf"));
                                          pdf->dynamicCall("SetCurrentPage(int)",currentPage);
                                          pdf->dynamicCall("SetShowToolbar(bool)",false);
                                          pdf->dynamicCall("SetPageMode(BSTR)","bookmarks");//"none"//"thumbs";
                                         // pdf->dynamicCall("SetView(BSTR)","FitB");
                                      
                                      
                                          QQuickView *view = new QQuickView();
                                          QWidget *container = QWidget::createWindowContainer(view, this);
                                          container->setFocusPolicy(Qt::TabFocus);
                                          view->setSource(QUrl("qrc:/qml/Main.qml"));
                                          ui->horizontalLayout->addWidget(container);
                                          ui->horizontalLayout->addWidget(pdf);
                                      
                                      }
                                      
                                      1 Reply Last reply
                                      0
                                      • P philxxx609
                                        18 Jul 2020, 11:22

                                        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 17 Jun 2021, 07:49 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 17 Jun 2021, 08:00 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 17 Jun 2021, 08:26
                                          0

                                          • Login

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