Saving from Word to PDF
-
Hello! I'm trying to save .docx file into .pdf:
#include "widget.h" #include <QAxObject> #include <QAxWidget> #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); QAxWidget word("Word.Application"); word.setProperty("Visible", true); QAxObject * documents = word.querySubObject("Documents"); QAxObject * document=documents->querySubObject("Open(QString)","C:/Users/Olga/Desktop/test.docx"); document->dynamicCall("SaveAs (const QString&)", QString("C:/Users/Olga/Desktop/test2.pdf")); document->dynamicCall("Close (boolean)", false); word.dynamicCall("Quit (void)"); return 0; }
The new file "test2.pdf" is appearing. But I cannot open it.
Help me, please, how could I save the .docx file into the PDF format properly?
Best regards,
Olga -
Hello! I'm trying to save .docx file into .pdf:
#include "widget.h" #include <QAxObject> #include <QAxWidget> #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); QAxWidget word("Word.Application"); word.setProperty("Visible", true); QAxObject * documents = word.querySubObject("Documents"); QAxObject * document=documents->querySubObject("Open(QString)","C:/Users/Olga/Desktop/test.docx"); document->dynamicCall("SaveAs (const QString&)", QString("C:/Users/Olga/Desktop/test2.pdf")); document->dynamicCall("Close (boolean)", false); word.dynamicCall("Quit (void)"); return 0; }
The new file "test2.pdf" is appearing. But I cannot open it.
Help me, please, how could I save the .docx file into the PDF format properly?
Best regards,
Olga -
@Oda412
https://stackoverflow.com/questions/42909112/saving-word-document-as-pdf from 2018 shows a couple of Automation ways of saving as PDF.ActiveDocument.ExportAsFixedFormat
seems to be the key.@JonB Thank you a lot! Now it works!
#include "widget.h" #include <QAxObject> #include <QAxWidget> #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); QAxWidget word("Word.Application"); word.setProperty("Visible", true); QAxObject * documents = word.querySubObject("Documents"); QAxObject * document=documents->querySubObject("Open(QString)","C:/Users/Olga/Desktop/test.docx"); // vars for ExportAsFixedFormat QVariant OutputFileName("C:/Users/Olga/Desktop/test.pdf"); QVariant ExportFormat(17); QVariant OpenAfterExport(false); // converting to PDF document->querySubObject("ExportAsFixedFormat(const QVariant&,const QVariant&,const QVariant&)", OutputFileName, ExportFormat, OpenAfterExport); //closing document document->dynamicCall("Close(boolean)",false); word.dynamicCall("Quit (void)"); return 0; }
-
Hi,
Will this code work for an online converter like this:
https://oneconvert.com/pdf-converter/word-to-pdf
Or where can I get an example?
Thanks. -
Hi,
Will this code work for an online converter like this:
https://oneconvert.com/pdf-converter/word-to-pdf
Or where can I get an example?
Thanks.@Jose-Williams said in Saving from Word to PDF:
Will this code work for an online converter like this
no