jpg批量转成一个pdf

来源:互联网 发布:电工模拟接线软件 编辑:程序博客网 时间:2024/05/20 18:53
//jpg批量转成一个pdf   //jpgPath:jpg路径数组  mOutputPdfFileName:pdf路径public static void MCombineJPG2PDF(String[] jpgPath,String mOutputPdfFileName) {String TAG = "PdfManager";com.itextpdf.text.Document doc = new com.itextpdf.text.Document(PageSize.A4, 0, 0, 0, 0);try {PdfWriter.getInstance(doc, new FileOutputStream(mOutputPdfFileName));doc.open();for (int i = 0; i < jpgPath.length; i++) {doc.newPage();Image png1 = Image.getInstance(jpgPath[i]);float heigth = png1.getHeight();float width = png1.getWidth();doc.setPageSize(new Rectangle(width, heigth));doc.newPage();doc.add(png1);}doc.close();} catch (FileNotFoundException e) {e.printStackTrace();} catch (DocumentException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}catch(Exception e){e.printStackTrace();}File mOutputPdfFile = new File(mOutputPdfFileName);if (!mOutputPdfFile.exists()) {mOutputPdfFile.deleteOnExit();}}


 
原创粉丝点击