/** * 把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(); } }