控件中国网现已改版,您看到的是老版本网站的镜像,系统正在为您跳转到新网站首页,请稍候.......
中国最专业的商业控件资讯网产品咨询电话:023-67870900 023-67871946
产品咨询EMAIL:SALES@COMPONENTCN.COM

Aspose.Word从word文档里提取图片

作者:ComponentCN 出处:ComponentCN 2014年08月21日 阅读:

Aspose.Word从word文档里提取图片

Aspose.Word是一款功能强大的word控件,可以对word文件进行创建、编辑、读取、修改、转换,合并,插入等操作,并且不需要安装任何第三方插件,下面我们简单介绍,Aspose.Word如果从word文件中提取图片并保存。

具体查看下面的代码:
C#

public void ExtractImagesToFiles()
{
    Document doc = new Document(MyDir + "Image.SampleImages.doc");

    NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
    int imageIndex = 0;           
    foreach (Shape shape in shapes)
    {
        if (shape.HasImage)
        {
            string imageFileName = string.Format(
                "Image.ExportImages.{0} Out{1}", imageIndex, FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType));
            shape.ImageData.Save(MyDir + imageFileName);
            imageIndex++;
        }
    }

    // Newer Microsoft Word documents (such as DOCX) may contain a different type of image container called DrawingML.
    // Repeat the process to extract these if they are present in the loaded document.
    NodeCollection dmlShapes = doc.GetChildNodes(NodeType.DrawingML, true);
    foreach (DrawingML dml in dmlShapes)
    {
        if (dml.HasImage)
        {
            string imageFileName = string.Format(
                "Image.ExportImages.{0} Out{1}", imageIndex, FileFormatUtil.ImageTypeToExtension(dml.ImageData.ImageType));
            dml.ImageData.Save(MyDir + imageFileName);
            imageIndex++;
        }
    }
}
 

Visual Basic


Public Sub ExtractImagesToFiles()
    Dim doc As New Document(MyDir & "Image.SampleImages.doc")

    Dim shapes As NodeCollection = doc.GetChildNodes(NodeType.Shape, True)
    Dim imageIndex As Integer = 0
    For Each shape As Shape In shapes
        If shape.HasImage Then
            Dim imageFileName As String = String.Format("Image.ExportImages.{0} Out{1}", imageIndex, FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType))
            shape.ImageData.Save(MyDir & imageFileName)
            imageIndex += 1
        End If
    Next shape

    ' Newer Microsoft Word documents (such as DOCX) may contain a different type of image container called DrawingML.
    ' Repeat the process to extract these if they are present in the loaded document.
    Dim dmlShapes As NodeCollection = doc.GetChildNodes(NodeType.DrawingML, True)
    For Each dml As DrawingML In dmlShapes
        If dml.HasImage Then
            Dim imageFileName As String = String.Format("Image.ExportImages.{0} Out{1}", imageIndex, FileFormatUtil.ImageTypeToExtension(dml.ImageData.ImageType))
            dml.ImageData.Save(MyDir & imageFileName)
            imageIndex += 1
        End If
    Next dml
End Sub
 

热推产品

  • ActiveReport... 强大的.NET报表设计、浏览、打印、转换控件,可以同时用于WindowsForms谀坔攀戀Forms平台下......
  • AnyChart AnyChart使你可以创建出绚丽的交互式的Flash和HTML5的图表和仪表控件。可以用于仪表盘的创......
首页 | 新闻中心 | 产品中心 | 技术文档 | 友情连接 | 关于磐岩 | 技术支持中心 | 联系我们 | 帮助中心 Copyright-2006 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 电话:023 - 67870900 传真:023 - 67870270 产品咨询:sales@componentcn.com 渝ICP备12000264号 法律顾问:元炳律师事务所 重庆市江北区塔坪36号维丰创意绿苑A座28-5 邮编:400020
在线客服
在线客服系统
在线客服
在线客服系统