QT PPT转换成pdf核心代码

6 篇文章 0 订阅

最近需要把PPT文件转换成PDF文件,我发现网上好像关于这方面的教程很少,我这里来弥补一下,首先我的环境是windows 10 64bit,qt 5.9.7,安装了office 2010.

然后转换的核心代码为:

void MainWindow::openPPT(){
    QFileDialog _dialog;

    _dialog.setFileMode(QFileDialog::ExistingFile);

    _dialog.setViewMode(QFileDialog::Detail);

    _dialog.setOption(QFileDialog::ReadOnly, true);

    _dialog.setDirectory(QString("./"));
     _dialog.setNameFilter(QString("ppt(*.pptx *.ppt)"));
     if (_dialog.exec()){
         QStringList files = _dialog.selectedFiles();
         for (auto fileName : files){
             if (fileName.endsWith(".pptx")||fileName.endsWith(".ppt"))

             {
                 // Open parameter

                 QAxObject *_powerPointAxObj = new QAxObject("Powerpoint.Application", 0);
                 if (!_powerPointAxObj){
                     continue;
                 }
                 _powerPointAxObj->dynamicCall("SetVisible(bool)", false);
                 QAxObject *presentations = _powerPointAxObj->querySubObject("Presentations");
                 QList<QVariant> paramList;
                 paramList.push_back(QVariant(fileName));
                 paramList.push_back(0);
                 paramList.push_back(0);
                 paramList.push_back(0);
                 //FileName   Required String. The name of the file to open
                         //ReadOnly   Optional Long. True to open the file with read-only status. If this argument is omitted, the file is opened with read/write status.
                         //Untitled   Optional Long. True to open the file without a title. This is equivalent to creating a copy of the file. If this argument isn't specified, the file name automatically becomes the title of the opened presentation.
                         //WithWindow Optional Long. True to open the file in a visible window. False to hide the opened presentation. The default value is True.
                 QAxObject *presentation = presentations->querySubObject("Open(const QString&,int,int,int)",paramList);
                 if (presentation != nullptr){
                     paramList.clear();
                     QString application_path = QApplication::applicationDirPath();
                     application_path.replace("/", "\\");
                     application_path += "\\ShowFile.pdf";
                     paramList.push_back(application_path);
                     paramList.push_back(32);
                     paramList.push_back(0);
                     presentation->dynamicCall("SaveAs(const QString&,int,int)", paramList);
                     presentations->dynamicCall("Close()");  //到这里就已经转换成功了,转换的文件名为ShowFile.pdf,保存在你的debug或者release目录里,可以自行查看
                     delete presentations;
      //               this->OpenPdf(application_path);

             }

         }

     }

}

参考文献

[1].关于使用QAxObject自动播放ppt的问题.https://bbs.csdn.net/topics/392037375

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

农民小飞侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值