您好,登錄后才能下訂單哦!
本篇內容主要講解“Android怎么實現excel/pdf/word/odt/圖片相互轉換”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Android怎么實現excel/pdf/word/odt/圖片相互轉換”吧!
public static long pdfToExcel(String inFile, String outFile) throws Exception { if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) { return 0; } try { long old = System.currentTimeMillis(); Document doc = new Document(inFile); ExcelSaveOptions options = new ExcelSaveOptions(); options.setFormat(ExcelSaveOptions.ExcelFormat.XLSX); doc.save(outFile, options); Out.print(inFile, outFile, System.currentTimeMillis(), old); return new File(outFile).length(); }catch (Exception e) { e.printStackTrace(); throw new Exception(e.getMessage()); } }
public static long excelToPdf(String inFile, String outFile) throws Exception { if (!com.yrnet.transfer.business.transfer.file.License.getExcelLicense()) { return 0; } try { long old = System.currentTimeMillis(); File pdfFile = new File(outFile); Workbook wb = new Workbook(inFile); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.setOnePagePerSheet(true); FileOutputStream fileOS = new FileOutputStream(pdfFile); wb.save(fileOS, SaveFormat.PDF); fileOS.close(); long now = System.currentTimeMillis(); Out.print(inFile, outFile, now, old); return pdfFile.length(); }catch (Exception e) { e.printStackTrace(); throw new Exception(e.getMessage()); } }
public static long pptToPdf(String inFile, String outFile) throws Exception { if (!com.yrnet.transfer.business.transfer.file.License.getPptLicense()) { return 0; } try { long old = System.currentTimeMillis(); File pdfFile = new File(outFile); FileOutputStream os = new FileOutputStream(pdfFile); Presentation pres = new Presentation(inFile); pres.save(os, com.aspose.slides.SaveFormat.Pdf); os.close(); long now = System.currentTimeMillis(); Out.print(inFile, outFile, now, old); return pdfFile.length(); } catch (Exception e) { e.printStackTrace(); throw new Exception(e.getMessage()); } }
public static long pdfToPpt(String inFile, String outFile) { if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) { return 0; } long old = System.currentTimeMillis(); Document pdfDocument = new Document(inFile); PptxSaveOptions pptxOptions = new PptxSaveOptions(); pptxOptions.setExtractOcrSublayerOnly(true); pdfDocument.save(outFile, pptxOptions); long now = System.currentTimeMillis(); Out.print(inFile, outFile, now, old); return new File(outFile).length(); }
public static long pdfToDoc(String inFile, String outFile) { if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) { return 0; } log.info("開始轉換..."); long old = System.currentTimeMillis(); Document pdfDocument = new Document(inFile); DocSaveOptions saveOptions = new DocSaveOptions(); /** 或者DocSaveOptions.DocFormat.DocX*/ saveOptions.setFormat(DocSaveOptions.DocFormat.Doc); pdfDocument.save(outFile, saveOptions); long now = System.currentTimeMillis(); Out.print(inFile, outFile, now, old); log.info("轉換結束..."); return new File(outFile).length(); }
public static long wordToPdf(String inFile, String outFile) throws Exception { if (!com.yrnet.transfer.business.transfer.file.License.getWordLicense()) { return 0; } try { long old = System.currentTimeMillis(); File file = new File(outFile); FileOutputStream os = new FileOutputStream(file); Document doc = new Document(inFile); Document tmp = new Document(); tmp.removeAllChildren(); tmp.appendDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES); System.out.println("開始解析word文檔" + inFile); doc.save(os, SaveFormat.PDF); long now = System.currentTimeMillis(); log.info("target file size:{}",file.length()); os.close(); Out.print(inFile, outFile, now, old); return file.length(); } catch (Exception e) { log.error(inFile + "轉換失敗,請重試",e); throw new Exception(e.getMessage()); } }
public static long excelToPic(String inFile, String outFile) throws Exception { if (!com.yrnet.transfer.business.transfer.file.License.getExcelLicense()) { return 0; } try { long old = System.currentTimeMillis(); Workbook wb = new Workbook(inFile); Worksheet sheet = wb.getWorksheets().get(0); ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); imgOptions.setImageFormat(ImageFormat.getPng()); imgOptions.setCellAutoFit(true); imgOptions.setOnePagePerSheet(true); SheetRender render = new SheetRender(sheet, imgOptions); render.toImage(0, outFile); long now = System.currentTimeMillis(); Out.print(inFile, outFile, now, old); return new File(outFile).length(); }catch (Exception e) { e.printStackTrace(); throw new Exception(e.getMessage()); } }
public static long pdfToPng(String inFile, List<String> outFile) throws Exception { long size = 0; if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) { return size; } try { long old = System.currentTimeMillis(); Document pdfDocument = new Document(inFile); Resolution resolution = new Resolution(960); JpegDevice jpegDevice = new JpegDevice(resolution); for (int index=1;index<=pdfDocument.getPages().size();index++) { String path = inFile.substring(0,inFile.lastIndexOf(".")) + "_"+index+".png"; File file = new File(path); size += file.length(); FileOutputStream fileOs = new FileOutputStream(file); jpegDevice.process(pdfDocument.getPages().get_Item(index), fileOs); outFile.add(path); fileOs.close(); long now = System.currentTimeMillis(); Out.print(inFile, path, now, old); } return size; }catch (Exception e){ log.error(e.getMessage(),e); throw new Exception(e.getMessage()); } }
public static long pdfToPng(String inFile, List<String> outFile) throws Exception { long size = 0; if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) { return size; } try { long old = System.currentTimeMillis(); Document pdfDocument = new Document(inFile); Resolution resolution = new Resolution(960); JpegDevice jpegDevice = new JpegDevice(resolution); for (int index=1;index<=pdfDocument.getPages().size();index++) { String path = inFile.substring(0,inFile.lastIndexOf(".")) + "_"+index+".png"; File file = new File(path); size += file.length(); FileOutputStream fileOs = new FileOutputStream(file); jpegDevice.process(pdfDocument.getPages().get_Item(index), fileOs); outFile.add(path); fileOs.close(); long now = System.currentTimeMillis(); Out.print(inFile, path, now, old); } return size; }catch (Exception e){ log.error(e.getMessage(),e); throw new Exception(e.getMessage()); } }
到此,相信大家對“Android怎么實現excel/pdf/word/odt/圖片相互轉換”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。