-- 首先引入依赖
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-full</artifactId>
<version>1.17.0</version>
</dependency>
public static MultipartFile generateOfdFile(MultipartFile file, String url) throws IOException {
System.out.println("ofd创建前图片路径---:"+url);
String ofdFilePath = url.substring(0, url.lastIndexOf(".png")) + ".ofd";
Path OfdPath = Paths.get(ofdFilePath).toAbsolutePath();
try (OFDDoc ofdDoc = new OFDDoc(OfdPath)) {
PageLayout pageLayout = ofdDoc.getPageLayout();
VirtualPage vPage = new VirtualPage(pageLayout);
Image image = Image.getInstance(file.getBytes());
float height = image.getHeight();
float width = image.getWidth();
Path imgPath = Paths.get(url);
Img img;
if (height / width > pageLayout.getHeight() / pageLayout.getWidth()) {
img = new Img((pageLayout.getHeight() - 20) * width / height, pageLayout.getHeight(<