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. PDF issue with Qt
Forum Update on Monday, May 27th 2025

PDF issue with Qt

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 5.2k Views
  • 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.
  • B Offline
    B Offline
    brcontainer
    wrote on last edited by
    #1

    I'm trying to add a Pdf file to a widget (using ActiveX).

    When running axwidget is added but does not show the controls AdobeReader (AcroPDF.PDF) and also does not show the pages of the Pdf file, is just a gray widget.

    My code:

    @ #include "mainwindow.h"
    #include "ui_mainwindow.h"

    #include <QAxWidget>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QAxWidget *pdfWidget = new QAxWidget;
        pdfWidget->resize(740, 580);
        pdfWidget->setControl("{ca8a9780-280d-11cf-a24d-444553540000}");
        pdfWidget->dynamicCall("LoadFile&#40; const string& &#41;", "http://localhost/order.pdf"&#41;;
    
        ui->centralWidget->layout(&#41;->addWidget(pdfWidget);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }@
    

    What have I done wrong?

    QT project: https://github.com/brcontainer/qt-helper

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      The function prototype (first argument) given to dynamicCall() is missing its closing parentheses. Whether that is the only problem...

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        The parentheses is missing but that's not the main problem. The thing is acrobat ocx can't load content from a http url. You need to download the file first (eg. via QNetworkAccessManager), store it somewhere(eg. via QTemporaryFile) and use the local url for the LoadFile.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          brcontainer
          wrote on last edited by
          #4

          ChrisW67 it was a failure of "Qt-project" at the time I posted the code. I edit the question.

          ChrisKawa I was doing this:

          @ QAxWidget *pdfWidget = new QAxWidget;
          pdfWidget->resize(740, 580);
          pdfWidget->setControl("{CA8A9780-280D-11CF-A24D-444553540000}");
          pdfWidget->setProperty("src","http://localhost/order.pdf");
          ui->centralWidget->layout()->addWidget(pdfWidget);@

          But I could not send Session/Cookies/Headers on it and not the SWF/PDF files:

          I'm trying to implement plugins in QWebView.

          The problem is that pages that use sessions/cookie/POST method to display a file (such as PDF or SWF in my case) do not receive this information.

          How do I send sessions/cookie/POST method in QWebPluginFactory::create ?

          Thanks!

          @QObject *PluginsFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const
          {
          if (mimeType == "application/pdf") {
          QAxWidget *pdfWidget = new QAxWidget;
          if(!pdfWidget->setControl("{ca8a9780-280d-11cf-a24d-444553540000}")){
          qDebug() << "Please install Adobe Acrobat Reader (R) for Pdf support!";
          pdfWidget->clear();
          } else {
          pdfWidget->setProperty("src", url.url());
          return pdfWidget;
          }
          }

          if (mimeType == "application/swf") {
          QAxWidget *flash = new QAxWidget;
          flash->resize(740, 580);
          if(!flash->setControl("{d27cdb6e-ae6d-11cf-96b8-444553540000}")){
          qDebug() << "Adobe Flash Player (R) for SWF support!";
          flash->clear();
          } else {
          flash->dynamicCall("LoadMovie(long,string)", 0, url.url());
          return flash;
          }
          }
          return 0;
          }@

          QT project: https://github.com/brcontainer/qt-helper

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Why do you implement plugins on your own? QWebView already supports plugins for flash, pdf(if any reader is available) etc.
            They are disabled by default but can be easily turned on:
            @
            webView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
            @

            1 Reply Last reply
            0
            • B Offline
              B Offline
              brcontainer
              wrote on last edited by
              #6

              Chris Kawa, there is a bug in QT5, see: https://bugreports.qt-project.org/browse/QTBUG-33053

              When I used "QWebPluginFactory::create" the BUG stopped. So we want to use "QWebPluginFactory::create".

              How can I use ActiveX with QNetWorkAccessManager?

              QT project: https://github.com/brcontainer/qt-helper

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #7

                bq. How can I use ActiveX with QNetWorkAccessManager?

                Fetch the remote file into a local temporary file with QNetworkAccessManager, QNetworkRequest and QNetworkReply. See the "Network Download Example" in the Qt docs.
                Pass LoadFile() the path to the temporary file.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  brcontainer
                  wrote on last edited by
                  #8

                  bq. Pass LoadFile() the path to the temporary file.

                  But if a SWF comes from the C:\windows\temp, the SWF will not be able to access pages "http" because it violate the Flash restrictions, Am I right?

                  QT project: https://github.com/brcontainer/qt-helper

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    The downloading was only for pdfs (the acrobat reader ocx to be exact). Other plugins I don't know. I would imagine flash component can handle http.

                    To be honest it's a lot of work to properly handle all possible plugins with all their quirks and webkit guys already did it. I would put my efforts into fixing the issue with QWebView support of plugins that you've mentioned than reinventing the wheel.

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      brcontainer
                      wrote on last edited by
                      #10

                      bq. I would put my efforts into fixing the issue with QWebView support of plugins that you’ve mentioned than reinventing the wheel.

                      I fully agree.

                      But what if I use new plugins there must be a way to maintain the link between NetWorkAccessManager and plugins.

                      I believe my code is using QAxWidget inappropriately, maybe I should use QAxClientSite (or something that has nothing to do with it), but I have some experience with this situation.

                      QT project: https://github.com/brcontainer/qt-helper

                      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