java ofd文件 转 pdf,png,jpg格式
所需要maven 版本
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-converter</artifactId>
<version>1.8.6</version>
</dependency>
代码格式
import org.ofdrw.converter.ImageMaker;
import org.ofdrw.reader.OFDReader;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.ofdrw.converter.ConvertHelper.ofd2pdf;
public class OfdToPdf {
public static void main(String[] args) throws IOException {
toPng("F:\\xiaoxiong\\开发文件\\文件\\2.ofd", "F:\\xiaoxiong\\开发文件\\文件","22");
}
public static void toPng(String filename, String dirPath, String jpgName) throws IOException {
Files.createDirectories(Paths.get(dirPath));
Path src = Paths.get(filename);
ImageMaker imageMaker = new ImageMaker(new OFDReader(src), 15);
imageMaker.config.setDrawBoundary(false);
for (int i = 0; i < imageMaker.pageSize(); i++) {
BufferedImage image = imageMaker.makePage(i);
Path dist = Paths.get(dirPath, jpgName + ".png");
ImageIO.write(image, "PNG", dist.toFile());
}
}
public static void toPdf(Path input, Path output) {
ofd2pdf(input, output);
}
}