| | |
| | | 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; |
| | |
| | | map.put(EncodeHintType.CHARACTER_SET,"utf-8"); |
| | | BitMatrix encode = null; |
| | | try { |
| | | encode = new MultiFormatWriter().encode(tjNumber, BarcodeFormat.CODE_128, 300, 100, map); |
| | | encode = new MultiFormatWriter().encode(tjNumber, BarcodeFormat.CODE_128, 500, 100, map); |
| | | } catch (WriterException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | * @throws DocumentException |
| | | * @throws IOException |
| | | */ |
| | | public static void makeTjInfo(Document document,List<Map<String ,String>> data) throws DocumentException, IOException { |
| | | public static void makeTjInfo(Document document,List<Map<String ,Object>> data) throws DocumentException, IOException { |
| | | PdfPTable table1 = new PdfPTable(7); |
| | | table1.setWidthPercentage(100); |
| | | float[] columnWidths = {1.5f, 3, 3, 6, 1.5f, 3, 3}; |
| | |
| | | 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(); |
| | | } |
| | | } |