2016-06-26 14 views
4

msワードテーブルからイメージを取得できますが、形状やクリップアートを取得できません。プログラム上MS Wordファイルの図形(四角形、四角形、円、矢印など)を読み取る

public static void main(String[] args) throws Exception { 
    // The path to the documents directory. 
    try { 
     String dataDir = "E://test//demo.docx"; 
     generatePicturesAsImages(dataDir); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

public static void generatePicturesAsImages(String sourcePath) { 
    try { 
     Document doc = new Document(sourcePath); 
     ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG); 
     options.setJpegQuality(100); 
     options.setResolution(100); 
     // options.setUseHighQualityRendering(true); 
     List<ShapeRenderer> pictures = getAllPictures(doc); 
     if (pictures != null) { 
      for (int i = 0; i < pictures.size(); i++) { 
       ShapeRenderer picture = pictures.get(i); 
       String imageFilePath = sourcePath + "_output_" + i + ".jpeg"; 
       picture.save(imageFilePath, options); 
      } 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

private static List<ShapeRenderer> getAllPictures(final Document document) throws Exception { 
    List<ShapeRenderer> images = null; 
    @SuppressWarnings("unchecked") 
    NodeCollection<DrawingML> nodeCollection = document.getChildNodes(NodeType.DRAWING_ML, Boolean.TRUE); 
    if (nodeCollection.getCount() > 0) { 
     images = new ArrayList<ShapeRenderer>(); 
     for (DrawingML drawingML : nodeCollection) { 
      images.add(drawingML.getShapeRenderer()); 
     } 
    } 
    return images; 
} 

はので、私はより多くを追加する必要がありますどのような形状を得るために、テーブルから画像を取得します。..任意のヘルプは感謝される私に提案して下さい!

答えて

1

古いバージョンのAspose.Wordsを使用しています。古いバージョンのAspose.Wordsを使用する場合は、getAllPicturesメソッドでDocument.getChildNodesを使用してShapeおよびDrawingMLノードのコレクションを取得してください。

NodeCollection<DrawingML> drwingmlnodes = document.getChildNodes(NodeType.DRAWING_ML, Boolean.TRUE); 

NodeCollection<Shape> shapenodes = document.getChildNodes(NodeType.SHAPE, Boolean.TRUE); 

DrawingML from our APIs in Aspose.Words 15.2.0を削除しました。 Aspose.Words v16.5.0の最新バージョンを使用する場合は、NodeType.SHAPEのみを使用してください。

私はAspose as Developerエバンジェリストを使用しています。

関連する問題