我希望将pptx转换为md时,将pptx的所有图片上传到远端服务器,但是我不希望图片直接落盘,因此我才用了如下的方式:
1、遍历所有的shape,找到所有的图片,下载并上传到我的服务器
2、删除图片shape,并在原位置插入图片的url(markdown格式)
但是这样转换,会导致我插入的文本被转义,导致md无法正确识别图片,有什么解决办法么?
或者有没有现场的更好的实践方案?
var pres = new Presentation(String.valueOf(Paths.get(prePath, "test_complex.pptx")));
Map<IShape, String> shapeUrlMap = new HashMap<>();
for (var slide : pres.getSlides()) {
for (var shape : slide.getShapes()) {
if (shape instanceof IPictureFrame) {
// 取图片二进制、上传到服务器
IPictureFrame picShape = (IPictureFrame) shape;
byte[] imageBytes = picShape.getPictureFormat().getPicture().getImage().getBinaryData();
// String imageUrl = uploadImageToRemote(imageBytes); // 自定义上传
String imageUrl = "1111.png";
shapeUrlMap.put(shape, imageUrl);
}
}
}
for (Map.Entry<IShape, String> entry : shapeUrlMap.entrySet()) {
IShape shape = entry.getKey();
IBaseSlide slide = shape.getSlide();
String imageUrl = entry.getValue();
// 删除原图片 shape
slide.getShapes().remove(shape);
// 插入新的 shape(文本框)——内容为 Markdown 图片语法
IAutoShape newTextShape = slide.getShapes().addAutoShape(ShapeType.Rectangle,
shape.getX(), shape.getY(), shape.getWidth(), shape.getHeight());
newTextShape.getTextFrame().setText("");
}
<groupId>com.aspose</groupId>
<artifactId>aspose-slides</artifactId>
<version>24.8</version>