QT PPT转换成pdf核心代码

网友投稿 1143 2022-08-23

QT PPT转换成pdf核心代码

QT PPT转换成pdf核心代码

最近需要把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 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的问题​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Python 超详细的入门教程(python能做什么)
下一篇:[leetcode] 826. Most Profit Assigning Work
相关文章

 发表评论

暂时没有评论,来抢沙发吧~