| 
					
				 | 
			
			
				@@ -0,0 +1,182 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.kmall.admin.utils.pdf.type; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.kmall.api.entity.exportpdf.PDFGoodsDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.lowagie.text.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.lowagie.text.Font; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.lowagie.text.Image; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.lowagie.text.pdf.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.awt.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.FileOutputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @author zhangchuangbiao 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @version 1.0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * 2020-09-11 09:51 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class PDFWrite_nohead_36 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void write(Document doc, PdfWriter writer, PDFGoodsDto pdfGoodsDto 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            , String fontUrl, String uploadDir) throws IOException, DocumentException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 设置字体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BaseFont bfHei = BaseFont.createFont(fontUrl,BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Font FontChinese11 = new Font(bfHei, 11); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String path = uploadDir; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FileOutputStream out = new FileOutputStream(path); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        doc.setMargins(0,0,0,0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        writer.setPdfVersion(PdfWriter.PDF_VERSION_1_2);//版本(默认1.4) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        doc.open();// 打开文档 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // -----------------------标签头---------------------- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 9; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        doc.close();  //记得关闭document 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static void getPdfPTable(Font fontChinese11, BaseFont bfHei, Document doc, PDFGoodsDto pdfGoodsDto) throws IOException, DocumentException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        PdfPTable table = new PdfPTable(4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // --------------产品名称------------------------------- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        table = new PdfPTable(4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 4; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            setTable(bfHei, table, 13, pdfGoodsDto.getProductName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        doc.add(table); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // --------------产品英文名称------------------------------- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        table = new PdfPTable(4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 4; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            setTable(bfHei, table, 7, pdfGoodsDto.getEnglishName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        doc.add(table); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        table = new PdfPTable(4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 4; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+           PdfPTable pdfPTable4 = new PdfPTable(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Font font = new Font(bfHei, 20); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            bigPrice.setAlignment(Element.ALIGN_BOTTOM); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // --------------小价格------------------------------- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            font = new Font(bfHei, 10); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            smallPrice.setAlignment(Element.ALIGN_BOTTOM); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            smallPrice.setIndentationLeft(50); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            bigPrice.add(smallPrice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PdfPCell priceCell = new PdfPCell(bigPrice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            priceCell.setBorder(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            priceCell.setHorizontalAlignment(Element.ALIGN_LEFT); // 水平居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            priceCell.setVerticalAlignment(Element.ALIGN_BOTTOM); // 垂直居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pdfPTable4.addCell(priceCell); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // ----------------test----------------------- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PdfPTable pdfPTable8 = new PdfPTable(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pdfPTable8.setWidths(new int[]{10,8}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            font = new Font(bfHei, 6); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // --------------左上的字------------------------------- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Paragraph leftParagraph1 = new Paragraph("\n建议零售价省¥"+pdfGoodsDto.getSavings()+"\n\n", font); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            font = new Font(bfHei, 4.5f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Paragraph leftParagraph2 = new Paragraph("税率:"+pdfGoodsDto.getStartFax()+"\n", font); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            leftParagraph1.add(leftParagraph2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PdfPCell leftCell1 = new PdfPCell(leftParagraph1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            leftCell1.setBorder(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            leftCell1.setHorizontalAlignment(Element.ALIGN_LEFT); // 水平居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            leftCell1.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pdfPTable8.addCell(leftCell1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pdfPTable8.addCell(priceCell); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PdfPCell p = new PdfPCell(pdfPTable8); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            p.setBorder(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            table.setWidthPercentage(110f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            table.addCell(p); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        doc.add(table); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        table = new PdfPTable(4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 4; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // --------------底部黑色和条形码区域------------------------------- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PdfPTable pdfPTable7 = new PdfPTable(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Font font = new Font(bfHei, 5.5f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            font.setColor(Color.WHITE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Paragraph PLU = new Paragraph(pdfGoodsDto.getPlu(), font); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Paragraph blankParagraph = new Paragraph("                        ", font); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Paragraph barCode = new Paragraph(pdfGoodsDto.getBarCode().substring(pdfGoodsDto.getBarCode().length()-4), font); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            blankParagraph.add(barCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PLU.add(blankParagraph); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PLU.setAlignment(Element.ALIGN_CENTER); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PdfPCell pluCell = new PdfPCell(PLU); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pluCell.setBackgroundColor(Color.BLACK); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pluCell.setBorder(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pluCell.setFixedHeight(10.5f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pluCell.setHorizontalAlignment(Element.ALIGN_LEFT); // 水平居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pluCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // -------------条形码图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Image img = Image.getInstance("E:\\demo\\barCode.jpg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            img.setAlignment(Image.ALIGN_CENTER);  //设置图片居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            img.setBorder(Image.NO_BORDER); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            img.setBorderColor(Color.WHITE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            img.scaleAbsolute(72,10.5f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PdfPCell imgCell = new PdfPCell(img,false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            imgCell.setBorder(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pdfPTable7.addCell(pluCell); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pdfPTable7.addCell(imgCell); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PdfPCell p = new PdfPCell(pdfPTable7); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            p.setBorder(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            table.setWidthPercentage(110f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            table.addCell(p); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        doc.add(table); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        table = new PdfPTable(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Paragraph blankRow = new Paragraph("\n"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        PdfPCell nextLine = new PdfPCell(blankRow); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        nextLine.setBorder(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        nextLine.setFixedHeight(8.5f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        table.addCell(nextLine); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        doc.add(table); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 去除边框,设置水平垂直居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static void setBasisStyle(PdfPCell pluCell, int alignLeft, int alignMiddle) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        pluCell.setBorder(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        pluCell.setHorizontalAlignment(alignLeft); // 水平居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        pluCell.setVerticalAlignment(alignMiddle); // 垂直居中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static void setTable(BaseFont bfHei, PdfPTable table, int i2, String s) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Font font = new Font(bfHei, i2); // 设置字体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Paragraph paragraph = new Paragraph(s, font); // 段落 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        PdfPCell nameCell = new PdfPCell(paragraph); // 单元Cell 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        setBasisStyle(nameCell, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        table.setWidthPercentage(110f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        table.addCell(nameCell); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |