using QAxWidget to open pdf, printing is not working
-
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...
-
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...
@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); }
-
Hello guys,
using the code bellow:
PDF_Reader.proQT += 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
@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.
thank for your help. -
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
@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 toLoadFile
, 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 needSetCurrentPage(1)
. Or what aboutSetShowToolbar(true)
or theSetPageMode("bookmarks")
just to see whether either of these appear? -
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
-
@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 toLoadFile
, 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 needSetCurrentPage(1)
. Or what aboutSetShowToolbar(true)
or theSetPageMode("bookmarks")
just to see whether either of these appear? -
@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 toLoadFile
, 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 needSetCurrentPage(1)
. Or what aboutSetShowToolbar(true)
or theSetPageMode("bookmarks")
just to see whether either of these appear?@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
andacropdflib.h
file.
But when I use these file in my project, it can't complie.unknown type name '_IAcroAXDocShimEvents'.
-
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
@hskoglund Hi thank you for your advice. I try another pdf file, but not work.
-
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
-
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
@hskoglund Thanks for your reply. I will try it tomorrow. Very appreciate.
-
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
@hskoglund Yes, it works. Build with MSVC2019 32-bit works. Thanks for your help.