PDF issue with Qt
-
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( const string& )", "http://localhost/order.pdf"); ui->centralWidget->layout()->addWidget(pdfWidget); } MainWindow::~MainWindow() { delete ui; }@
What have I done wrong?
-
The function prototype (first argument) given to dynamicCall() is missing its closing parentheses. Whether that is the only problem...
-
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.
-
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;
}@ -
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);
@ -
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?
-
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. -
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?
-
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.
-
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.