| | |
| | | import com.google.zxing.common.BitMatrix; |
| | | import com.itextpdf.text.*; |
| | | import com.itextpdf.text.pdf.*; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | |
| | | document.close(); |
| | | return (ByteArrayOutputStream) map.get("stream"); |
| | | } |
| | | |
| | | /** |
| | | * 将多个base64pdf合并为一个 |
| | | * @param base64PdfList pdf集合 |
| | | * @return |
| | | */ |
| | | public static byte[] mergePDFs(List<String > base64PdfList) throws DocumentException, IOException { |
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | | Document document = new Document(); |
| | | PdfCopy copy = new PdfCopy(document, byteArrayOutputStream); |
| | | document.open(); |
| | | for (String base64Pdf : base64PdfList) { |
| | | byte[] pdfBytes = Base64.decodeBase64(base64Pdf); |
| | | PdfReader reader = new PdfReader(new ByteArrayInputStream(pdfBytes)); |
| | | int numberOfPages = reader.getNumberOfPages(); |
| | | for (int i = 1; i <= numberOfPages; i++) { |
| | | document.newPage(); |
| | | PdfImportedPage page = copy.getImportedPage(reader, i); |
| | | copy.addPage(page); |
| | | } |
| | | reader.close(); |
| | | } |
| | | document.close(); |
| | | return byteArrayOutputStream.toByteArray(); |
| | | } |
| | | } |