java ofd转pdf和jpg

最近刚遇到ofd转jpg百度好友也找不到 好不容易在git上找到的又不全所以自己整理了一下给大家探探路

首先要导入jar包依赖

<dependency>
    <groupId>org.ofdrw</groupId>
    <artifactId>ofdrw-full</artifactId>
    <version>1.8.6</version>

</dependency>

如果jar下载不下来的话就可以自行导入

 


mvn install:install-file -Dfile=ofdrw-full-1.8.6.jar -DgroupId=org.ujmp -DartifactId=ofdrw-full -Dversion=1.8.6 -Dpackaging=jar

我把jar放到百度云盘链接:https://pan.baidu.com/s/17DCEN0li3Izhgfh5T6KtFg   提取码:1234

把它导入maven依赖后就大功告成你只需要调用里面的方法即可

package com.sh.untils;

import org.ofdrw.converter.GeneralConvertException;
import org.ofdrw.converter.ImageMaker;
import org.ofdrw.reader.DLOFDReader;
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;

/**
 * @program: electroniclicense_xinxiang
 * @description: ofd转jpg和pdf
 * @author: Mr.JZQ
 * @create: 2021-04-17 15:53
 **/

public class OfdConver {
    public static void main(String[] args) throws IOException {
        toPng("D:/downloadFile/ceshi.ofd", "D:/downloadFile","aa");
    }


    /**
     * @Description: ofd转jpg
     * @Param: * @param null:
     * @return: * @return: null
     * @Author: Mr.JZQ
     * @Date: 2021年04月17日 0017
     */
    public static void toPng(String filename, String dirPath, String jpgName) throws IOException {
        Files.createDirectories(Paths.get(dirPath));
        //filename文件路径到文件名
        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 + ".jpg");
            ImageIO.write(image, "PNG", dist.toFile());
        }
    }

    /**
     * 转PDF
     *
     * @param input  OFD输入文件
     * @param output PDF输出文件路径
     * @throws IllegalArgumentException 参数错误
     * @throws GeneralConvertException  文档转换过程中异常
     */
    public static void toPdf(Path input, Path output) {
        ofd2pdf(input, output);
    }
}

这样就大功告成 开箱即用

  • 7
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值