Java转换ofd格式到pdf
生活随笔
收集整理的這篇文章主要介紹了
Java转换ofd格式到pdf
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
最近有個業務場景,開具發票的時候,第三方返回的是ofd格式。
這里需要借助第三方庫ofdrw來實現。
引入Maven依賴
使用
使用ConvertHelper.toPdf方法就可以進行轉換,ofdrw提供多個重載方法,這里列一個最基礎的進行使用
轉換pdf
/*** 上傳附件,將ofd格式的問價轉換為pdf并上傳到文件服務器* @param fileUrl* @return*/public static String convertToPdf(String fileUrl) {InputStream inputStream = null;ByteArrayOutputStream baos = null;try {baos = new ByteArrayOutputStream();URL url = new URL(fileUrl);URLConnection urlConnection = url.openConnection();inputStream = urlConnection.getInputStream();String suffix= FileNameUtil.getSuffix(fileUrl);// ofd需轉pdf格式,在進行存儲if("ofd".equals(suffix)){ConvertHelper.toPdf(inputStream, baos);}else {return null;}baos.flush();byte[] imageByte = baos.toByteArray();String originFileName = "test.".concat("pdf");MultipartFile multipartFile = new MockMultipartFile("file", originFileName, ContentType.OCTET_STREAM.toString(), imageByte);//上傳文件到自己的服務器,并返回轉換后的pdf的url} catch (IOException e) {e.printStackTrace();} finally {IoUtil.close(inputStream);IoUtil.close(baos);}return null;}總結
以上是生活随笔為你收集整理的Java转换ofd格式到pdf的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NOD 32 企业版远程管理服务器病毒库
- 下一篇: 联想笔记本重装系统,联想电脑安装系统