如何使用 MS Open XML SDK 从 .pptx 文件检索图像?
我开始尝试Open XML SDK 2.0 for Microsoft Office。
我目前可以执行某些操作,例如检索每张幻灯片中的所有文本并获取演示文稿的大小。例如,我以这种方式执行后者:
using (var doc = PresentationDocument.Open(pptx_filename, false)) {
var presentation = doc.PresentationPart.Presentation;
Debug.Print("width: " + (presentation.SlideSize.Cx / 9525.0).ToString());
Debug.Print("height: " + (presentation.SlideSize.Cy / 9525.0).ToString());
}
现在我想检索给定幻灯片中的嵌入图像。有谁知道如何做到这一点或者可以向我指出一些有关该主题的文档?
I started experimenting with Open XML SDK 2.0 for Microsoft Office.
I'm currently able to do certain things such as retrieve all texts in each slide, and get the size of the presentation. For example, I do the latter this way:
using (var doc = PresentationDocument.Open(pptx_filename, false)) {
var presentation = doc.PresentationPart.Presentation;
Debug.Print("width: " + (presentation.SlideSize.Cx / 9525.0).ToString());
Debug.Print("height: " + (presentation.SlideSize.Cy / 9525.0).ToString());
}
Now I'd like to retrieve embedded images in a given slide. Does anyone know how to do this or can point me to some docs on the subject?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要获取要从中获取图像的
SlidePart
:然后您需要搜索
Picture
对象,该对象将包含您要查找的图像关于图像的文件名:First you need to grab the
SlidePart
in which you want to get the images from:Then you need to search for the
Picture
object which will contain the image you are looking for based on the file name of the image:从 Openxml 格式获取图像的最简单方法:
使用任何 zip 存档库从 pptx 文件的媒体文件夹中提取图像。这将包含文档中的图像。同样,您可以手动将扩展名 .pptx 替换为 .zip 并解压以从媒体文件夹中获取图像。
希望这有帮助。
Simplest way of getting Images from Openxml formats:
Use any zip archive library to extract images from media folder of the pptx file. This will contain the images in the document. Similarly, you can manually replace extension .pptx into .zip and extract to get images from media folder.
Hope this helps.