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

Saving from Word to PDF

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 5 Posters 900 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.
  • O Offline
    O Offline
    Oda412
    wrote on last edited by SGaist
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • A Offline
      A Offline
      AlexMaly
      wrote on last edited by
      #2

      as fars as I understand the call you made is saving the same document just under different name. You need to find command / parameters which will save it to pdf. It is probably print command.

      1 Reply Last reply
      0
      • O Oda412

        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

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @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.

        O 1 Reply Last reply
        3
        • JonBJ JonB

          @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.

          O Offline
          O Offline
          Oda412
          wrote on last edited by
          #4

          @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;
          }
          
          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jose Williams
            wrote on last edited by
            #5

            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.

            jsulmJ 1 Reply Last reply
            0
            • J Jose Williams

              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.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Jose-Williams said in Saving from Word to PDF:

              Will this code work for an online converter like this

              no

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              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