Как преобразовать файл VSD / VSDX в изображение (например, JPG PNG) с помощью Apache Poi - PullRequest
0 голосов
/ 12 ноября 2018

Я использую apache poi для чтения файлов doc / docx.

Теперь я могу извлечь абзацы и изображения из моего файла документации.

Когда в моем doc-файле есть vsd, как я могу преобразовать vsd в png-изображение?

Я пробовал это:

private byte[] emfConversionPng(DocPictureData pictureData) { 

            EMFRenderer emfRenderer = null; 
            InputStream iStream = new ByteArrayInputStream(pictureData.getContent()); 
            EMFInputStream emfInputStream = null; 
            ByteArrayOutputStream baos = null; 
            ImageOutputStream imageOutputStream = null; 

            byte[] by = null; 

            try { 
                    emfInputStream = new EMFInputStream(iStream, EMFInputStream.DEFAULT_VERSION); 
                    emfRenderer = new EMFRenderer(emfInputStream); 

                    int width = (int) emfInputStream.readHeader().getBounds().getWidth(); 
                    int height = (int) emfInputStream.readHeader().getBounds().getHeight(); 

                    BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 
                    Graphics2D graphics2d = result.createGraphics(); 

                    emfRenderer.paint(graphics2d); 


                    baos = new ByteArrayOutputStream(); 
                    imageOutputStream = ImageIO.createImageOutputStream(baos); 
                    ImageIO.write(result, "png", imageOutputStream); 

                    by = baos.toByteArray(); 
            } catch (IOException e) { 
                    // TODO Auto-generated catch block 
                    e.printStackTrace(); 
            } finally { 
                    try { 
                            if (imageOutputStream != null) { 
                                    imageOutputStream.close(); 
                            } 
                            if (baos != null) { 
                                    baos.close(); 
                            } 
                            if (emfRenderer != null) { 
                                    emfRenderer.closeFigure(); 
                            } 
                    } catch (IOException e) { 
                            // TODO Auto-generated catch block 
                            e.printStackTrace(); 
                    } 

            } 

            return by; 
    } 

Но изображение, которое я получил, не содержало текст, как это: enter image description here

Кто-нибудь знает, как я могу это сделать?

...