OfdToPdf.java

package pdf_ofd;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.ofdrw.converter.export.HTMLExporter;
import org.ofdrw.converter.export.ImageExporter;
import org.ofdrw.converter.export.OFDExporter;
import org.ofdrw.converter.export.PDFExporterIText;
import org.ofdrw.converter.export.PDFExporterPDFBox;
import org.ofdrw.converter.export.SVGExporter;
import org.ofdrw.converter.export.TextExporter;

/**
 * OFD 转 PDF
 * 
<dependency>
    <groupId>org.ofdrw</groupId>
    <artifactId>ofdrw-converter</artifactId>
    <version>2.0.2</version>
</dependency>
 * 
 * 
 * @author ZengWenFeng
 * @email 117791303@QQ.com
 * @mobile 13805029595
 */
public class OfdToPdf
{

	public OfdToPdf()
	{

	}
	
	/**
	 * ofd转html
	 * 
	 * @author ZengWenFeng
	 * @email 117791303@qq.com
	 * @mobile 13805029595
	 * @param pathOfd   C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
	 * @param pathHtml  C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.html
	 * @throws IOException
	 */
	public static void convertToHtml(String pathOfd, String pathHtml) throws IOException
	{

		Path ofd = Paths.get(pathOfd);  //C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
		Path html = Paths.get(pathHtml);//C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.html
		
		
		OFDExporter exporter = null;
		try
		{
			//org.ofdrw.converter.export.HTMLExporter
			exporter = new HTMLExporter(ofd, html);
			exporter.export();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			exporter.close();
		}
	}
	
	
	/**
	 * ofd转img(png,jpg,bpm)
	 * 
	 * 好久没写了,生疏了
	 * 
	 * 留个先贤名言【智者千虑亦有一失】
	 * 
	 * 沟通是很重要的,嘴巴一口该问
	 * 该问的东西还是要自己去问清楚
	 * 很多事根本就不是你想你听到了
	 * 有些答案或许应当听听当事人
	 * 
	 * 
	 * @author ZengWenFeng
	 * @email 117791303@qq.com
	 * @mobile 13805029595
	 * @param pathOfd  C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
	 * @param pathImg  C:\\Users\\Administrator\\Desktop\\
	 * @throws IOException
	 */
	public static void convertToImg(String pathOfd, String pathImg) throws IOException
	{

		Path ofd = Paths.get(pathOfd);  //C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
		Path img = Paths.get(pathImg);//C:\\Users\\Administrator\\Desktop\\
		
		
		OFDExporter exporter = null;
		try
		{
			//org.ofdrw.converter.export.ImageExporter    png、jpg、bpm   ppm=15d   path=0.png, 1.png, 2.png
			exporter = new ImageExporter(ofd, img, "PNG", 20d);
			exporter.export();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			exporter.close();
		}
	}
	
	/**
	 * ofd转pdf
	 * 
	 * @author ZengWenFeng
	 * @email 117791303@qq.com
	 * @mobile 13805029595
	 * @param pathOfd  C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
	 * @param pathPdf  C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.pdf
	 * @throws IOException
	 */
	public static void convertToPdf(String pathOfd, String pathPdf) throws IOException
	{

		Path ofd = Paths.get(pathOfd); //C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
		Path pdf = Paths.get(pathPdf); //C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.pdf
		
		
		OFDExporter exporter = null;
		try
		{
			//org.ofdrw.converter.export.PDFExporterPDFBox
			exporter = new PDFExporterPDFBox(ofd, pdf);
			exporter.export();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			exporter.close();
		}
	}
	
	/**
	 * ofd转pdf
	 * 
	 * @author ZengWenFeng
	 * @email 117791303@qq.com
	 * @mobile 13805029595
	 * @param pathOfd  C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
	 * @param pathPdf  C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.pdf
	 * @throws IOException
	 */
	public static void convertToPdf2(String pathOfd, String pathPdf) throws IOException
	{

		Path ofd = Paths.get(pathOfd); //C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
		Path pdf = Paths.get(pathPdf); //C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.pdf
		
		
		OFDExporter exporter = null;
		try
		{
			//org.ofdrw.converter.export.PDFExporterIText
			exporter = new PDFExporterIText(ofd, pdf);
			exporter.export();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			exporter.close();
		}
	}
	
	/**
	 * ofd转svg
	 * 
	 * @author ZengWenFeng
	 * @email 117791303@qq.com
	 * @mobile 13805029595
	 * @param pathOfd  C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
	 * @param pathSvg  C:\\Users\\Administrator\\Desktop\\
	 * @throws IOException
	 */
	public static void convertToSvg(String pathOfd, String pathSvg) throws IOException
	{

		Path ofd = Paths.get(pathOfd); //C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
		Path svg = Paths.get(pathSvg); //C:\\Users\\Administrator\\Desktop\\
		
		
		OFDExporter exporter = null;
		try
		{
			//org.ofdrw.converter.export.SVGExporter ppm=15d   path=0.svg, 1.svg, 2.svg
			exporter = new SVGExporter(ofd, svg, 15d);
			exporter.export();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			exporter.close();
		}
	}
	
	
	/**
	 * ofd转txt
	 * 
	 * @author ZengWenFeng
	 * @email 117791303@qq.com
	 * @mobile 13805029595
	 * @param pathOfd  C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
	 * @param pathTxt  C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.txt
	 * @throws IOException
	 */
	public static void convertToText(String pathOfd, String pathTxt) throws IOException
	{

		Path ofd = Paths.get(pathOfd); //C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd
		Path txt = Paths.get(pathTxt); //C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.txt
		
		
		OFDExporter exporter = null;
		try
		{
			//org.ofdrw.converter.export.TextExporter
			exporter = new TextExporter(ofd, txt);
			exporter.export();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			exporter.close();
		}
	}

	
	/**
	 * 仅供测试
	 * 
	 * @author ZengWenFeng
	 * @email 117791303@qq.com
	 * @mobile 13805029595
	 * @weixin 13805029595
	 * @param args
	 */
	public static void main(String[] args)
	{
		try
		{
			String path = "C:\\Users\\Administrator\\Desktop\\";
			
			String pathOfd = "C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.ofd";
			
			String pathPdf = "C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.pdf";
			String pathHtml = "C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.html";
			String pathtxt = "C:\\Users\\Administrator\\Desktop\\3fb12626-2711-445e-80ac-093d0f2c3282.txt";
			
			
			convertToHtml(pathOfd, pathHtml);
			convertToPdf(pathOfd, pathPdf);
//			convertToPdf2(pathOfd, pathPdf);
			convertToText(pathOfd, pathtxt);
			convertToImg(pathOfd, path);
			convertToSvg(pathOfd, path);
			
			//世事浑浊目光如炬
			System.out.println("ok!");
		}
		catch (IOException e)
		{
			e.printStackTrace();
			System.out.println("err: " + e.getMessage());
		}
	}

}

关于母亲节,查了一下。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值