Bläddra i källkod

导出含有标签头的pdf的相关代码

zcb 4 år sedan
förälder
incheckning
86e3e5022c
20 ändrade filer med 1605 tillägg och 4 borttagningar
  1. 51 0
      kmall-admin/pom.xml
  2. 60 0
      kmall-admin/src/main/java/com/kmall/admin/controller/exportPDF/ExportPDFController.java
  3. 9 0
      kmall-admin/src/main/java/com/kmall/admin/dao/GoodsDao.java
  4. 9 1
      kmall-admin/src/main/java/com/kmall/admin/service/GoodsService.java
  5. 13 1
      kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java
  6. 47 0
      kmall-admin/src/main/java/com/kmall/admin/utils/pdf/PdfUtil.java
  7. 30 0
      kmall-admin/src/main/java/com/kmall/admin/utils/pdf/ViewPDF.java
  8. 159 0
      kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite.java
  9. 224 0
      kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_12.java
  10. 216 0
      kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_2.java
  11. 233 0
      kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_36.java
  12. 218 0
      kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_4.java
  13. 222 0
      kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_9.java
  14. 26 0
      kmall-admin/src/main/resources/mybatis/mapper/GoodsDao.xml
  15. BIN
      kmall-admin/src/main/resources/static/font/ams1015.ttf
  16. 2 1
      kmall-admin/src/main/webapp/WEB-INF/page/sale/monthlyCustomers2.html
  17. 1 1
      kmall-admin/src/main/webapp/js/sale/monthlyCustomers2.js
  18. BIN
      kmall-admin/src/main/webapp/statics/font/ams1015.ttf
  19. 83 0
      kmall-api/src/main/java/com/kmall/api/entity/exportpdf/PDFGoodsDto.java
  20. 2 0
      kmall-manager/src/main/resources/conf/print.properties

+ 51 - 0
kmall-admin/pom.xml

@@ -72,6 +72,50 @@
             </exclusions>
         </dependency>
 
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>kernel</artifactId>
+            <version>7.0.3</version>
+        </dependency>
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>io</artifactId>
+            <version>7.0.3</version>
+        </dependency>
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>layout</artifactId>
+            <version>7.0.3</version>
+        </dependency>
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>font-asian</artifactId>
+            <version>7.0.3</version>
+        </dependency>
+        <dependency>
+            <groupId>com.lowagie</groupId>
+            <artifactId>itext</artifactId>
+            <version>2.1.7</version>
+        </dependency>
+
+        <!--         https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>itextpdf</artifactId>
+            <version>5.5.13</version>
+        </dependency>
+        <!-- https://mvnrepository.com/artifact/com.itextpdf/itext-asian -->
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>itext-asian</artifactId>
+            <version>5.2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <version>4.3.7.RELEASE</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 
@@ -95,6 +139,13 @@
                     <include>**/*.properties</include>
                 </includes>
             </resource>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>false</filtering>
+                <includes>
+                    <include>**/*.ttf</include>
+                </includes>
+            </resource>
         </resources>
 
         <plugins>

+ 60 - 0
kmall-admin/src/main/java/com/kmall/admin/controller/exportPDF/ExportPDFController.java

@@ -0,0 +1,60 @@
+package com.kmall.admin.controller.exportPDF;
+
+import com.kmall.admin.service.GoodsService;
+import com.kmall.admin.utils.pdf.ViewPDF;
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+/**
+ * @author zhangchuangbiao
+ * @version 1.0
+ * 2020-09-14 16:06
+ */
+@Controller
+@RequestMapping("pdf")
+public class ExportPDFController {
+
+    @Autowired
+    private GoodsService goodsService;
+
+    @Value("${font.url}")
+    private String fontUrl;
+
+    @Value("${upload.dir}")
+    private String uploadDir;
+
+
+    //打印pdf
+    @RequestMapping("/printPdf")
+    public ModelAndView printPdf(String head ,String type,String sku,String storeId) throws Exception {
+
+        PDFGoodsDto pdfGoodsDto = goodsService.queryForPDFData(sku,storeId);
+
+        if("1".equals(head)){
+            Map<String, Object> model = new HashMap<>();
+            model.put("dto", pdfGoodsDto);
+            model.put("type",type);
+            model.put("fontUrl",fontUrl);
+            model.put("uploadDir",uploadDir);
+            return new ModelAndView(new ViewPDF(), model);
+        }else if ("0".equals(head)){
+            Map<String, Object> model = new HashMap<>();
+            model.put("dto", pdfGoodsDto);
+            model.put("type",type);
+            return new ModelAndView(new ViewPDF(), model);
+        }else{
+            return null;
+        }
+
+
+    }
+}
+
+

+ 9 - 0
kmall-admin/src/main/java/com/kmall/admin/dao/GoodsDao.java

@@ -3,6 +3,7 @@ package com.kmall.admin.dao;
 import com.kmall.admin.dto.GoodsDetailsDto;
 import com.kmall.admin.dto.GoodsPanoramaDto;
 import com.kmall.admin.entity.GoodsEntity;
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
 import com.kmall.common.utils.print.ticket.item.Goods;
 import com.kmall.manager.dao.BaseDao;
 import org.apache.ibatis.annotations.Param;
@@ -39,4 +40,12 @@ public interface GoodsDao extends BaseDao<GoodsEntity> {
     GoodsPanoramaDto searchGoodsPanoramaDtoByKeyword(@Param("keyword") String keyword);
 
     List<GoodsEntity> queryExportList(Map<String, Object> params);
+
+    /**
+     * 查询pdf需要的数据
+     * @param sku sku
+     * @param storeId 门店id
+     * @return
+     */
+    PDFGoodsDto queryForPDFData(@Param("sku") String sku, @Param("storeId")String storeId);
 }

+ 9 - 1
kmall-admin/src/main/java/com/kmall/admin/service/GoodsService.java

@@ -4,7 +4,7 @@ import com.kmall.admin.dto.GoodsDetailsDto;
 import com.kmall.admin.dto.GoodsDto;
 import com.kmall.admin.dto.GoodsPanoramaDto;
 import com.kmall.admin.entity.GoodsEntity;
-import com.kmall.common.utils.print.ticket.item.Goods;
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
 
 import java.util.List;
 import java.util.Map;
@@ -142,4 +142,12 @@ public interface GoodsService {
      * @return
      */
     List<GoodsEntity> queryExportList(Map<String, Object> params);
+
+    /**
+     * 查出pdf需要的需要
+     * @param sku 商品sku
+     * @param storeId
+     * @return
+     */
+    PDFGoodsDto queryForPDFData(String sku, String storeId);
 }

+ 13 - 1
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java

@@ -9,10 +9,10 @@ import com.kmall.admin.dto.GoodsPanoramaDto;
 import com.kmall.admin.entity.*;
 import com.kmall.admin.service.GoodsService;
 import com.kmall.admin.utils.ShiroUtils;
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
 import com.kmall.common.constant.Dict;
 import com.kmall.admin.fromcomm.entity.SysUserEntity;
 import com.kmall.common.utils.*;
-import com.kmall.common.utils.print.ticket.item.Goods;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -1041,6 +1041,18 @@ public class GoodsServiceImpl implements GoodsService {
 
         return goodsDao.queryExportList(params);
     }
+
+    /**
+     * 查出pdf需要的需要
+     *
+     * @param sku 商品sku
+     * @param storeId
+     * @return
+     */
+    @Override
+    public PDFGoodsDto queryForPDFData(String sku, String storeId) {
+        return goodsDao.queryForPDFData(sku,storeId);
+    }
 /*  @Override
     @Transactional
     public int uploadExcel(MultipartFile file) {

+ 47 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/PdfUtil.java

@@ -0,0 +1,47 @@
+package com.kmall.admin.utils.pdf;
+
+import com.itextpdf.text.DocumentException;
+import com.kmall.admin.utils.pdf.type.*;
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import com.lowagie.text.Document;
+import com.lowagie.text.pdf.PdfWriter;
+
+import java.io.IOException;
+
+public class PdfUtil {
+
+  public void createPDF(Document document, PdfWriter writer, PDFGoodsDto pdfGoodsDto,
+                        String type, String fontUrl, String uploadDir) throws IOException, com.lowagie.text.DocumentException {
+
+      switch (type){
+          case "1":
+              PDFWrite pdfWrite = new PDFWrite();
+              pdfWrite.write(document,writer,pdfGoodsDto,fontUrl,uploadDir);
+              break;
+          case "2":
+              PDFWrite_2 pdfWrite2 = new PDFWrite_2();
+              pdfWrite2.write(document,writer,pdfGoodsDto,fontUrl,uploadDir);
+              break;
+          case "4":
+              PDFWrite_4 pdfWrite4 = new PDFWrite_4();
+              pdfWrite4.write(document,writer,pdfGoodsDto,fontUrl,uploadDir);
+              break;
+          case "9":
+              PDFWrite_9 pdfWrite9 = new PDFWrite_9();
+              pdfWrite9.write(document,writer,pdfGoodsDto,fontUrl,uploadDir);
+              break;
+          case "12":
+              PDFWrite_12 pdfWrite12 = new PDFWrite_12();
+              pdfWrite12.write(document,writer,pdfGoodsDto,fontUrl,uploadDir);
+              break;
+          case "36":
+              PDFWrite_36 pdfWrite36 = new PDFWrite_36();
+              pdfWrite36.write(document,writer,pdfGoodsDto,fontUrl,uploadDir);
+              break;
+          default:
+              break;
+      }
+
+
+  }
+}

+ 30 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/ViewPDF.java

@@ -0,0 +1,30 @@
+package com.kmall.admin.utils.pdf;
+
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import com.lowagie.text.Document;
+import com.lowagie.text.pdf.PdfWriter;
+import org.springframework.web.servlet.view.document.AbstractPdfView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Date;
+import java.util.Map;
+
+public class ViewPDF extends AbstractPdfView {
+
+  @Override
+  protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
+                                  HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+      String fileName = new Date().getTime()+"_quotation.pdf"; // 设置response方式,使执行此controller时候自动出现下载页面,而非直接使用excel打开
+      response.setCharacterEncoding("UTF-8");
+      response.setContentType("application/pdf");
+      response.setHeader("Content-Disposition","filename=" + new String(fileName.getBytes(), "iso8859-1"));
+      PdfUtil pdfUtil = new PdfUtil();
+      String type = (String) model.get("type");
+      PDFGoodsDto pdfGoodsDto = (PDFGoodsDto) model.get("dto");
+      String fontUrl = (String) model.get("fontUrl");
+      String uploadDir = (String) model.get("uploadDir");
+      pdfUtil.createPDF(document,writer,pdfGoodsDto,type,fontUrl,uploadDir);
+  }
+}

+ 159 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite.java

@@ -0,0 +1,159 @@
+package com.kmall.admin.utils.pdf.type;
+
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import com.lowagie.text.*;
+import com.lowagie.text.pdf.BaseFont;
+import com.lowagie.text.pdf.PdfPCell;
+import com.lowagie.text.pdf.PdfPTable;
+import com.lowagie.text.pdf.PdfWriter;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+/**
+ * @author zhangchuangbiao
+ * @version 1.0
+ * 2020-09-11 09:51
+ */
+public class PDFWrite {
+
+
+    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();// 打开文档
+        // -----------------------标签头----------------------
+        PdfPTable table1 = new PdfPTable(1);
+
+        Image img = Image.getInstance("H:\\Demo\\cheaper.jpg");
+        img.setAlignment(Image.MIDDLE);  //设置图片居中
+        img.setBorder(Image.BOX);
+        img.setBorderWidth(10);
+//        img.setBorderColor(BaseColor.WHITE);
+
+        img.scaleToFit(595, 842);// 设置图片大小
+
+        doc.add(img); //添加img
+
+        // --------------产品名称-------------------------------
+        PdfPTable pdfPTable2 = new PdfPTable(1);
+        Font font = new Font(bfHei, 60);
+        Paragraph tParagraph = new Paragraph(pdfGoodsDto.getProductName(), font);
+        PdfPCell nameCell = new PdfPCell(tParagraph);
+        nameCell.setBorder(0);
+        nameCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 水平居中
+        nameCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中
+        pdfPTable2.addCell(nameCell);
+        doc.add(pdfPTable2);
+
+        Paragraph blankRow31 = new Paragraph(18f, " ", FontChinese11);
+        doc.add(blankRow31);
+
+        // --------------产品英文名称-------------------------------
+        PdfPTable pdfPTable3 = new PdfPTable(1);
+        font = new Font(bfHei, 30);
+        Paragraph englistPararaph = new Paragraph(pdfGoodsDto.getEnglishName(), font);
+        PdfPCell englishNameCell = new PdfPCell(englistPararaph);
+        englishNameCell.setBorder(0);
+        englishNameCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 水平居中
+        englishNameCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中
+        pdfPTable3.addCell(englishNameCell);
+        doc.add(pdfPTable3);
+
+
+        // --------------大价格-------------------------------
+        PdfPTable pdfPTable4 = new PdfPTable(2);
+
+        pdfPTable4.setWidths(new int[]{20,10});
+
+        font = new Font(bfHei, 120);
+        Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
+
+        PdfPCell priceCell = new PdfPCell(bigPrice);
+        priceCell.setBorder(0);
+        priceCell.setHorizontalAlignment(Element.ALIGN_RIGHT); // 水平居中
+        priceCell.setVerticalAlignment(Element.ALIGN_CENTER); // 垂直居中
+        pdfPTable4.addCell(priceCell);
+        // --------------小价格-------------------------------
+        font = new Font(bfHei, 90);
+        Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font);
+
+        PdfPCell smallPriceCell = new PdfPCell(smallPrice);
+        smallPriceCell.setBorder(0);
+        smallPriceCell.setHorizontalAlignment(Element.ALIGN_LEFT); // 水平居中
+        smallPriceCell.setVerticalAlignment(Element.ALIGN_CENTER); // 垂直居中
+        pdfPTable4.addCell(smallPriceCell);
+
+        doc.add(pdfPTable4);
+
+        // --------------空格--------------
+        blankRow31 = new Paragraph(18f, " ", FontChinese11);
+        doc.add(blankRow31);
+
+        // --------------底部1-------------------------------
+        PdfPTable pdfPTable5 = new PdfPTable(1);
+        font = new Font(bfHei, 40);
+        Paragraph advice = new Paragraph("比建议零售价省¥"+pdfGoodsDto.getSavings(), font);
+        PdfPCell adviceCell = new PdfPCell(advice);
+        adviceCell.setBorder(0);
+        adviceCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 水平居中
+        adviceCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中
+        pdfPTable5.addCell(adviceCell);
+        doc.add(pdfPTable5);
+
+        // --------------空格--------------
+        blankRow31 = new Paragraph(18f, " ", FontChinese11);
+        doc.add(blankRow31);
+
+        // --------------底部2-------------------------------
+        PdfPTable pdfPTable6 = new PdfPTable(1);
+        font = new Font(bfHei, 26);
+        Paragraph tax = new Paragraph("税率:"+pdfGoodsDto.getStartFax(), font);
+        PdfPCell taxCell = new PdfPCell(tax);
+        taxCell.setBorder(0);
+        taxCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 水平居中
+        taxCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中
+        pdfPTable6.addCell(taxCell);
+        doc.add(pdfPTable6);
+
+        // --------------空格--------------
+        blankRow31 = new Paragraph(18f, " ", FontChinese11);
+        doc.add(blankRow31);
+
+        // --------------底部左边PLU-------------------------------
+        PdfPTable pdfPTable7 = new PdfPTable(2);
+        font = new Font(bfHei, 20);
+        Paragraph PLU = new Paragraph(pdfGoodsDto.getPlu(), font);
+        PdfPCell pluCell = new PdfPCell(PLU);
+        pluCell.setBorder(0);
+        pluCell.setHorizontalAlignment(Element.ALIGN_LEFT); // 水平居中
+        pluCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中
+        // --------------底部右边条形码-------------------------------
+        Paragraph barCode = new Paragraph(pdfGoodsDto.getBarCode(), font);
+        PdfPCell barCodeCell = new PdfPCell(barCode);
+        barCodeCell.setBorder(0);
+        barCodeCell.setHorizontalAlignment(Element.ALIGN_RIGHT); // 水平居中
+        barCodeCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中
+        pdfPTable7.addCell(pluCell);
+        pdfPTable7.addCell(barCodeCell);
+        doc.add(pdfPTable7);
+
+
+        doc.setMargins(10, 20, 30, 40);// 页边空白
+
+
+        doc.close();  //记得关闭document
+
+    }
+
+
+
+}

+ 224 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_12.java

@@ -0,0 +1,224 @@
+package com.kmall.admin.utils.pdf.type;
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import com.lowagie.text.*;
+import com.lowagie.text.pdf.*;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * @author zhangchuangbiao
+ * @version 1.0
+ * 2020-09-11 09:51
+ */
+public class PDFWrite_12 {
+
+
+    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();// 打开文档
+
+        // -----------------------标签头----------------------
+//        PdfPTable table = getPdfPTable(FontChinese11, bfHei, doc);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        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(3);
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            Image img = Image.getInstance("H:\\Demo\\cheaper.jpg");
+            img.setAlignment(Image.ALIGN_CENTER);  //设置图片居中
+
+            PdfPCell p = new PdfPCell(img,true);
+            p.setPaddingLeft(2);
+            p.setPaddingRight(2);
+            p.setPaddingTop(2);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+                canvas.moveTo(position.getLeft(), position.getTop());
+                canvas.lineTo(position.getRight(), position.getTop());
+            });
+
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+        // --------------产品名称-------------------------------
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            setTable(bfHei, table, 22, pdfGoodsDto.getProductName());
+        }
+
+        doc.add(table);
+
+        Paragraph blankRow31 = new Paragraph(18f, " ", fontChinese11);
+        PdfPCell nextLine = new PdfPCell(blankRow31);
+        nextLine.setBorder(0);
+        nextLine.setCellEvent((cell,position,canvases)->{
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        doc.add(nextLine);
+
+
+
+        // --------------产品英文名称-------------------------------
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            setTable(bfHei, table, 14, pdfGoodsDto.getEnglishName());
+        }
+        doc.add(table);
+
+
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            PdfPTable pdfPTable4 = new PdfPTable(2);
+            pdfPTable4.setWidths(new int[]{10,6});
+
+
+
+            // --------------大价格-------------------------------
+            Font font = new Font(bfHei, 54);
+            Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell priceCell = new PdfPCell(bigPrice);
+            setBasisStyle(priceCell, Element.ALIGN_RIGHT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(priceCell);
+
+            // --------------小价格-------------------------------
+            font = new Font(bfHei, 40);
+            Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell smallPriceCell = new PdfPCell(smallPrice);
+            setBasisStyle(smallPriceCell, Element.ALIGN_LEFT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(smallPriceCell);
+
+            PdfPCell p = new PdfPCell(pdfPTable4);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+
+
+        doc.add(table);
+
+        // --------------空格--------------
+        doc.add(nextLine);
+
+        // --------------底部1-------------------------------
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            setTable(bfHei, table, 16, "比建议零售价省¥"+pdfGoodsDto.getSavings());
+        }
+
+        doc.add(table);
+
+
+        // --------------底部2-------------------------------
+        table = new PdfPTable(3);
+        for (int i = 0; i < 3; i++) {
+            setTable(bfHei, table, 10, "税率:"+pdfGoodsDto.getStartFax());
+        }
+        doc.add(table);
+
+        table = new PdfPTable(3);
+        for (int i = 0; i < 3; i++) {
+            // --------------底部左边PLU-------------------------------
+            PdfPTable pdfPTable7 = new PdfPTable(2);
+            Font font = new Font(bfHei, 9);
+            Paragraph PLU = new Paragraph(pdfGoodsDto.getPlu(), font);
+            PdfPCell pluCell = new PdfPCell(PLU);
+            setBasisStyle(pluCell, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE);
+            pluCell.setPaddingLeft(20);
+            // --------------底部右边条形码-------------------------------
+            Paragraph barCode = new Paragraph(pdfGoodsDto.getBarCode(), font);
+            PdfPCell barCodeCell = new PdfPCell(barCode);
+            setBasisStyle(barCodeCell, Element.ALIGN_RIGHT, Element.ALIGN_MIDDLE);
+            barCodeCell.setPaddingRight(20);
+            pdfPTable7.addCell(pluCell);
+            pdfPTable7.addCell(barCodeCell);
+            PdfPCell p = new PdfPCell(pdfPTable7);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+        doc.add(nextLine);
+        doc.add(nextLine);
+        doc.add(nextLine);
+
+    }
+
+    // 绘制右边边框虚线
+    private static void cellRight(Rectangle position, PdfContentByte canvas) {
+        canvas.saveState();
+        canvas.setLineWidth(0.5f);
+        canvas.setLineDash(new float[]{5.0f, 5.0f}, 0);
+        canvas.moveTo(position.getRight(), position.getTop());
+        canvas.lineTo(position.getRight(), position.getBottom());
+        canvas.stroke();
+    }
+
+    // 去除边框,设置水平垂直居中
+    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); // 设置字体
+        PdfPTable pdfPTable3 = new PdfPTable(1);
+        Paragraph pararaph = new Paragraph(s, font); // 段落
+        PdfPCell nameCell = new PdfPCell(pararaph); // 单元Cell
+        setBasisStyle(nameCell, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
+        pdfPTable3.addCell(nameCell);
+
+        // 创建PCell来存储PTable,用来去除边框
+        PdfPCell p = new PdfPCell(pdfPTable3);
+        p.setBorder(0);
+        // 设置虚线边框
+        p.setCellEvent((cell, position, canvases) -> {
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        // 填充满
+        table.setWidthPercentage(100f);
+        table.addCell(p);
+    }
+
+
+}

+ 216 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_2.java

@@ -0,0 +1,216 @@
+package com.kmall.admin.utils.pdf.type;
+
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import com.lowagie.text.*;
+import com.lowagie.text.pdf.*;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+/**
+ * @author zhangchuangbiao
+ * @version 1.0
+ * 2020-09-11 09:51
+ */
+public class PDFWrite_2 {
+
+
+    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();// 打开文档
+        // -----------------------标签头----------------------
+        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(2);
+
+        for (int i = 0; i < 2; i++) {
+            Image img = Image.getInstance("H:\\Demo\\cheaper.jpg");
+            img.setAlignment(Image.ALIGN_CENTER);  //设置图片居中
+
+            PdfPCell p = new PdfPCell(img,true);
+            p.setPaddingLeft(2);
+            p.setPaddingRight(2);
+            p.setPaddingTop(2);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+                canvas.moveTo(position.getLeft(), position.getTop());
+                canvas.lineTo(position.getRight(), position.getTop());
+            });
+
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+        // --------------产品名称-------------------------------
+        table = new PdfPTable(2);
+
+        for (int i = 0; i < 2; i++) {
+            setTable(bfHei, table, 40, pdfGoodsDto.getProductName());
+        }
+
+        doc.add(table);
+
+        Paragraph blankRow31 = new Paragraph(18f, " ", fontChinese11);
+        PdfPCell nextLine = new PdfPCell(blankRow31);
+        nextLine.setBorder(0);
+        nextLine.setCellEvent((cell,position,canvases)->{
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        doc.add(nextLine);
+
+
+
+        // --------------产品英文名称-------------------------------
+        table = new PdfPTable(2);
+
+        for (int i = 0; i < 2; i++) {
+            setTable(bfHei, table, 20, pdfGoodsDto.getEnglishName());
+        }
+        doc.add(table);
+
+
+        table = new PdfPTable(2);
+
+        for (int i = 0; i < 2; i++) {
+            PdfPTable pdfPTable4 = new PdfPTable(2);
+            pdfPTable4.setWidths(new int[]{10,6});
+
+
+
+            // --------------大价格-------------------------------
+            Font font = new Font(bfHei, 66);
+            Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell priceCell = new PdfPCell(bigPrice);
+            setBasisStyle(priceCell, Element.ALIGN_RIGHT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(priceCell);
+
+            // --------------小价格-------------------------------
+            font = new Font(bfHei, 44);
+            Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell smallPriceCell = new PdfPCell(smallPrice);
+            setBasisStyle(smallPriceCell, Element.ALIGN_LEFT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(smallPriceCell);
+
+            PdfPCell p = new PdfPCell(pdfPTable4);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+
+
+        doc.add(table);
+
+        // --------------空格--------------
+
+        doc.add(nextLine);
+
+        // --------------底部1-------------------------------
+        table = new PdfPTable(2);
+
+        for (int i = 0; i < 2; i++) {
+            setTable(bfHei, table, 20, "比建议零售价省¥"+pdfGoodsDto.getSavings());
+        }
+
+        doc.add(table);
+
+
+        // --------------底部2-------------------------------
+        table = new PdfPTable(2);
+        for (int i = 0; i < 2; i++) {
+            setTable(bfHei, table, 16, "税率:"+pdfGoodsDto.getStartFax());
+        }
+        doc.add(table);
+
+        table = new PdfPTable(2);
+        for (int i = 0; i < 2; i++) {
+            // --------------底部左边PLU-------------------------------
+            PdfPTable pdfPTable7 = new PdfPTable(2);
+            Font font = new Font(bfHei, 12);
+            Paragraph PLU = new Paragraph(pdfGoodsDto.getPlu(), font);
+            PdfPCell pluCell = new PdfPCell(PLU);
+            setBasisStyle(pluCell, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE);
+            pluCell.setPaddingLeft(20);
+            // --------------底部右边条形码-------------------------------
+            Paragraph barCode = new Paragraph(pdfGoodsDto.getBarCode(), font);
+            PdfPCell barCodeCell = new PdfPCell(barCode);
+            setBasisStyle(barCodeCell, Element.ALIGN_RIGHT, Element.ALIGN_MIDDLE);
+            barCodeCell.setPaddingRight(20);
+            pdfPTable7.addCell(pluCell);
+            pdfPTable7.addCell(barCodeCell);
+            PdfPCell p = new PdfPCell(pdfPTable7);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+        doc.add(nextLine);
+
+    }
+
+    // 绘制右边边框虚线
+    private static void cellRight(Rectangle position, PdfContentByte canvas) {
+        canvas.saveState();
+        canvas.setLineWidth(0.5f);
+        canvas.setLineDash(new float[]{5.0f, 5.0f}, 0);
+        canvas.moveTo(position.getRight(), position.getTop());
+        canvas.lineTo(position.getRight(), position.getBottom());
+        canvas.stroke();
+    }
+
+    // 去除边框,设置水平垂直居中
+    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); // 设置字体
+        PdfPTable pdfPTable3 = new PdfPTable(1);
+        Paragraph pararaph = new Paragraph(s, font); // 段落
+        PdfPCell nameCell = new PdfPCell(pararaph); // 单元Cell
+        setBasisStyle(nameCell, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
+        pdfPTable3.addCell(nameCell);
+
+        // 创建PCell来存储PTable,用来去除边框
+        PdfPCell p = new PdfPCell(pdfPTable3);
+        p.setBorder(0);
+        // 设置虚线边框
+        p.setCellEvent((cell, position, canvases) -> {
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        // 填充满
+        table.setWidthPercentage(100f);
+        table.addCell(p);
+    }
+
+
+}

+ 233 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_36.java

@@ -0,0 +1,233 @@
+package com.kmall.admin.utils.pdf.type;
+
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import com.lowagie.text.*;
+import com.lowagie.text.pdf.*;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * @author zhangchuangbiao
+ * @version 1.0
+ * 2020-09-11 09:51
+ */
+public class PDFWrite_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();// 打开文档
+
+        // -----------------------标签头----------------------
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        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(3);
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            Image img = Image.getInstance("H:\\Demo\\cheaper.jpg");
+            img.setAlignment(Image.ALIGN_CENTER);  //设置图片居中
+
+            PdfPCell p = new PdfPCell(img,true);
+            p.setPaddingLeft(2);
+            p.setPaddingRight(2);
+            p.setPaddingTop(2);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+                canvas.moveTo(position.getLeft(), position.getTop());
+                canvas.lineTo(position.getRight(), position.getTop());
+            });
+
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+
+        // --------------产品名称-------------------------------
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            setTable(bfHei, table, 11, pdfGoodsDto.getProductName());
+        }
+
+        doc.add(table);
+
+
+        Paragraph blankRow31 = new Paragraph(18f, " ", fontChinese11);
+        PdfPCell nextLine = new PdfPCell(blankRow31);
+        nextLine.setBorder(0);
+        nextLine.setCellEvent((cell,position,canvases)->{
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+//        doc.add(nextLine);
+
+
+
+        // --------------产品英文名称-------------------------------
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            setTable(bfHei, table, 7, pdfGoodsDto.getEnglishName());
+        }
+        doc.add(table);
+
+
+
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            PdfPTable pdfPTable4 = new PdfPTable(2);
+            pdfPTable4.setWidths(new int[]{10,6});
+
+
+
+            // --------------大价格-------------------------------
+            Font font = new Font(bfHei, 22);
+            Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell priceCell = new PdfPCell(bigPrice);
+            setBasisStyle(priceCell, Element.ALIGN_RIGHT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(priceCell);
+
+            // --------------小价格-------------------------------
+            font = new Font(bfHei, 14);
+            Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell smallPriceCell = new PdfPCell(smallPrice);
+            setBasisStyle(smallPriceCell, Element.ALIGN_LEFT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(smallPriceCell);
+
+            PdfPCell p = new PdfPCell(pdfPTable4);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+
+
+        doc.add(table);
+
+
+        // --------------空格--------------
+
+//        doc.add(nextLine);
+
+        // --------------底部1-------------------------------
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            setTable(bfHei, table, 8, "比建议零售价省¥"+pdfGoodsDto.getSavings());
+        }
+
+        doc.add(table);
+
+
+
+        // --------------底部2-------------------------------
+        table = new PdfPTable(6);
+        for (int i = 0; i < 6; i++) {
+            setTable(bfHei, table, 6, "税率:"+pdfGoodsDto.getStartFax());
+        }
+        doc.add(table);
+
+
+        table = new PdfPTable(6);
+        for (int i = 0; i < 6; i++) {
+            // --------------底部左边PLU-------------------------------
+            PdfPTable pdfPTable7 = new PdfPTable(2);
+            Font font = new Font(bfHei, 5);
+            Paragraph PLU = new Paragraph(pdfGoodsDto.getPlu(), font);
+            PdfPCell pluCell = new PdfPCell(PLU);
+            setBasisStyle(pluCell, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE);
+            pluCell.setPaddingLeft(10);
+            // --------------底部右边条形码-------------------------------
+            Paragraph barCode = new Paragraph(pdfGoodsDto.getBarCode(), font);
+            PdfPCell barCodeCell = new PdfPCell(barCode);
+            setBasisStyle(barCodeCell, Element.ALIGN_RIGHT, Element.ALIGN_MIDDLE);
+            barCodeCell.setPaddingRight(10);
+            pdfPTable7.addCell(pluCell);
+            pdfPTable7.addCell(barCodeCell);
+            PdfPCell p = new PdfPCell(pdfPTable7);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+
+//        doc.add(nextLine);
+
+    }
+
+    // 绘制右边边框虚线
+    private static void cellRight(Rectangle position, PdfContentByte canvas) {
+        canvas.saveState();
+        canvas.setLineWidth(0.5f);
+        canvas.setLineDash(new float[]{5.0f, 5.0f}, 0);
+        canvas.moveTo(position.getRight(), position.getTop());
+        canvas.lineTo(position.getRight(), position.getBottom());
+        canvas.stroke();
+    }
+
+    // 去除边框,设置水平垂直居中
+    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); // 设置字体
+        PdfPTable pdfPTable3 = new PdfPTable(1);
+        Paragraph pararaph = new Paragraph(s, font); // 段落
+        PdfPCell nameCell = new PdfPCell(pararaph); // 单元Cell
+        setBasisStyle(nameCell, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
+        pdfPTable3.addCell(nameCell);
+
+        // 创建PCell来存储PTable,用来去除边框
+        PdfPCell p = new PdfPCell(pdfPTable3);
+        p.setBorder(0);
+        // 设置虚线边框
+        p.setCellEvent((cell, position, canvases) -> {
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        // 填充满
+        table.setWidthPercentage(100f);
+        table.addCell(p);
+    }
+
+
+}

+ 218 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_4.java

@@ -0,0 +1,218 @@
+package com.kmall.admin.utils.pdf.type;
+
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import com.lowagie.text.*;
+import com.lowagie.text.pdf.*;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+/**
+ * @author zhangchuangbiao
+ * @version 1.0
+ * 2020-09-11 09:51
+ */
+public class PDFWrite_4 {
+
+
+    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();// 打开文档
+        // -----------------------标签头----------------------
+//        PdfPTable table = getPdfPTable(FontChinese11, bfHei, doc);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        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(2);
+
+        for (int i = 0; i < 2; i++) {
+            Image img = Image.getInstance("H:\\Demo\\cheaper.jpg");
+            img.setAlignment(Image.ALIGN_CENTER);  //设置图片居中
+
+            PdfPCell p = new PdfPCell(img,true);
+            p.setPaddingLeft(2);
+            p.setPaddingRight(2);
+            p.setPaddingTop(2);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+                canvas.moveTo(position.getLeft(), position.getTop());
+                canvas.lineTo(position.getRight(), position.getTop());
+            });
+
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+        // --------------产品名称-------------------------------
+        table = new PdfPTable(2);
+
+        for (int i = 0; i < 2; i++) {
+            setTable(bfHei, table, 40, pdfGoodsDto.getProductName());
+        }
+
+        doc.add(table);
+
+        Paragraph blankRow31 = new Paragraph(18f, " ", fontChinese11);
+        PdfPCell nextLine = new PdfPCell(blankRow31);
+        nextLine.setBorder(0);
+        nextLine.setCellEvent((cell,position,canvases)->{
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        doc.add(nextLine);
+
+
+
+        // --------------产品英文名称-------------------------------
+        table = new PdfPTable(2);
+
+        for (int i = 0; i < 2; i++) {
+            setTable(bfHei, table, 20, pdfGoodsDto.getEnglishName());
+        }
+        doc.add(table);
+
+
+        table = new PdfPTable(2);
+
+        for (int i = 0; i < 2; i++) {
+            PdfPTable pdfPTable4 = new PdfPTable(2);
+            pdfPTable4.setWidths(new int[]{10,6});
+
+
+
+            // --------------大价格-------------------------------
+            Font font = new Font(bfHei, 66);
+            Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell priceCell = new PdfPCell(bigPrice);
+            setBasisStyle(priceCell, Element.ALIGN_RIGHT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(priceCell);
+
+            // --------------小价格-------------------------------
+            font = new Font(bfHei, 44);
+            Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell smallPriceCell = new PdfPCell(smallPrice);
+            setBasisStyle(smallPriceCell, Element.ALIGN_LEFT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(smallPriceCell);
+
+            PdfPCell p = new PdfPCell(pdfPTable4);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+
+
+        doc.add(table);
+
+        // --------------空格--------------
+
+        doc.add(nextLine);
+
+        // --------------底部1-------------------------------
+        table = new PdfPTable(2);
+
+        for (int i = 0; i < 2; i++) {
+            setTable(bfHei, table, 20, "比建议零售价省¥"+pdfGoodsDto.getSavings());
+        }
+
+        doc.add(table);
+
+
+        // --------------底部2-------------------------------
+        table = new PdfPTable(2);
+        for (int i = 0; i < 2; i++) {
+            setTable(bfHei, table, 16, "税率:"+pdfGoodsDto.getStartFax());
+        }
+        doc.add(table);
+
+        table = new PdfPTable(2);
+        for (int i = 0; i < 2; i++) {
+            // --------------底部左边PLU-------------------------------
+            PdfPTable pdfPTable7 = new PdfPTable(2);
+            Font font = new Font(bfHei, 12);
+            Paragraph PLU = new Paragraph(pdfGoodsDto.getPlu(), font);
+            PdfPCell pluCell = new PdfPCell(PLU);
+            setBasisStyle(pluCell, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE);
+            pluCell.setPaddingLeft(20);
+            // --------------底部右边条形码-------------------------------
+            Paragraph barCode = new Paragraph(pdfGoodsDto.getBarCode(), font);
+            PdfPCell barCodeCell = new PdfPCell(barCode);
+            setBasisStyle(barCodeCell, Element.ALIGN_RIGHT, Element.ALIGN_MIDDLE);
+            barCodeCell.setPaddingRight(20);
+            pdfPTable7.addCell(pluCell);
+            pdfPTable7.addCell(barCodeCell);
+            PdfPCell p = new PdfPCell(pdfPTable7);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+        doc.add(nextLine);
+
+    }
+
+    // 绘制右边边框虚线
+    private static void cellRight(Rectangle position, PdfContentByte canvas) {
+        canvas.saveState();
+        canvas.setLineWidth(0.5f);
+        canvas.setLineDash(new float[]{5.0f, 5.0f}, 0);
+        canvas.moveTo(position.getRight(), position.getTop());
+        canvas.lineTo(position.getRight(), position.getBottom());
+        canvas.stroke();
+    }
+
+    // 去除边框,设置水平垂直居中
+    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); // 设置字体
+        PdfPTable pdfPTable3 = new PdfPTable(1);
+        Paragraph pararaph = new Paragraph(s, font); // 段落
+        PdfPCell nameCell = new PdfPCell(pararaph); // 单元Cell
+        setBasisStyle(nameCell, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
+        pdfPTable3.addCell(nameCell);
+
+        // 创建PCell来存储PTable,用来去除边框
+        PdfPCell p = new PdfPCell(pdfPTable3);
+        p.setBorder(0);
+        // 设置虚线边框
+        p.setCellEvent((cell, position, canvases) -> {
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        // 填充满
+        table.setWidthPercentage(100f);
+        table.addCell(p);
+    }
+
+
+}

+ 222 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_9.java

@@ -0,0 +1,222 @@
+package com.kmall.admin.utils.pdf.type;
+
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import com.lowagie.text.*;
+import com.lowagie.text.pdf.*;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * @author zhangchuangbiao
+ * @version 1.0
+ * 2020-09-11 09:51
+ */
+public class PDFWrite_9 {
+
+
+    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();// 打开文档
+        // -----------------------标签头----------------------
+//        PdfPTable table = getPdfPTable(FontChinese11, bfHei, doc);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+        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(3);
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            Image img = Image.getInstance("H:\\Demo\\cheaper.jpg");
+            img.setAlignment(Image.ALIGN_CENTER);  //设置图片居中
+
+            PdfPCell p = new PdfPCell(img,true);
+            p.setPaddingLeft(2);
+            p.setPaddingRight(2);
+            p.setPaddingTop(2);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+                canvas.moveTo(position.getLeft(), position.getTop());
+                canvas.lineTo(position.getRight(), position.getTop());
+            });
+
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+        // --------------产品名称-------------------------------
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            setTable(bfHei, table, 22, pdfGoodsDto.getProductName());
+        }
+
+        doc.add(table);
+
+        Paragraph blankRow31 = new Paragraph(18f, " ", fontChinese11);
+        PdfPCell nextLine = new PdfPCell(blankRow31);
+        nextLine.setBorder(0);
+        nextLine.setCellEvent((cell,position,canvases)->{
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        doc.add(nextLine);
+
+
+
+        // --------------产品英文名称-------------------------------
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            setTable(bfHei, table, 14, pdfGoodsDto.getEnglishName());
+        }
+        doc.add(table);
+
+
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            PdfPTable pdfPTable4 = new PdfPTable(2);
+            pdfPTable4.setWidths(new int[]{10,6});
+
+
+
+            // --------------大价格-------------------------------
+            Font font = new Font(bfHei, 54);
+            Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell priceCell = new PdfPCell(bigPrice);
+            setBasisStyle(priceCell, Element.ALIGN_RIGHT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(priceCell);
+
+            // --------------小价格-------------------------------
+            font = new Font(bfHei, 40);
+            Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell smallPriceCell = new PdfPCell(smallPrice);
+            setBasisStyle(smallPriceCell, Element.ALIGN_LEFT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(smallPriceCell);
+
+            PdfPCell p = new PdfPCell(pdfPTable4);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+
+
+        doc.add(table);
+
+        // --------------空格--------------
+        doc.add(nextLine);
+
+        // --------------底部1-------------------------------
+        table = new PdfPTable(3);
+
+        for (int i = 0; i < 3; i++) {
+            setTable(bfHei, table, 16, "比建议零售价省¥"+pdfGoodsDto.getSavings());
+        }
+
+        doc.add(table);
+
+
+        // --------------底部2-------------------------------
+        table = new PdfPTable(3);
+        for (int i = 0; i < 3; i++) {
+            setTable(bfHei, table, 10, "税率:"+pdfGoodsDto.getStartFax());
+        }
+        doc.add(table);
+
+        table = new PdfPTable(3);
+        for (int i = 0; i < 3; i++) {
+            // --------------底部左边PLU-------------------------------
+            PdfPTable pdfPTable7 = new PdfPTable(2);
+            Font font = new Font(bfHei, 9);
+            Paragraph PLU = new Paragraph(pdfGoodsDto.getPlu(), font);
+            PdfPCell pluCell = new PdfPCell(PLU);
+            setBasisStyle(pluCell, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE);
+            pluCell.setPaddingLeft(20);
+            // --------------底部右边条形码-------------------------------
+            Paragraph barCode = new Paragraph(pdfGoodsDto.getBarCode(), font);
+            PdfPCell barCodeCell = new PdfPCell(barCode);
+            setBasisStyle(barCodeCell, Element.ALIGN_RIGHT, Element.ALIGN_MIDDLE);
+            barCodeCell.setPaddingRight(20);
+            pdfPTable7.addCell(pluCell);
+            pdfPTable7.addCell(barCodeCell);
+            PdfPCell p = new PdfPCell(pdfPTable7);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+        doc.add(nextLine);
+        doc.add(nextLine);
+        doc.add(nextLine);
+
+    }
+
+    // 绘制右边边框虚线
+    private static void cellRight(Rectangle position, PdfContentByte canvas) {
+        canvas.saveState();
+        canvas.setLineWidth(0.5f);
+        canvas.setLineDash(new float[]{5.0f, 5.0f}, 0);
+        canvas.moveTo(position.getRight(), position.getTop());
+        canvas.lineTo(position.getRight(), position.getBottom());
+        canvas.stroke();
+    }
+
+    // 去除边框,设置水平垂直居中
+    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); // 设置字体
+        PdfPTable pdfPTable3 = new PdfPTable(1);
+        Paragraph pararaph = new Paragraph(s, font); // 段落
+        PdfPCell nameCell = new PdfPCell(pararaph); // 单元Cell
+        setBasisStyle(nameCell, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
+        pdfPTable3.addCell(nameCell);
+
+        // 创建PCell来存储PTable,用来去除边框
+        PdfPCell p = new PdfPCell(pdfPTable3);
+        p.setBorder(0);
+        // 设置虚线边框
+        p.setCellEvent((cell, position, canvases) -> {
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        // 填充满
+        table.setWidthPercentage(100f);
+        table.addCell(p);
+    }
+
+
+}

+ 26 - 0
kmall-admin/src/main/resources/mybatis/mapper/GoodsDao.xml

@@ -686,4 +686,30 @@
         </if>
 
     </select>
+
+    <select id="queryForPDFData" resultType="com.kmall.api.entity.exportpdf.PDFGoodsDto">
+        select
+            g.name as productName,
+            g.english_name as englishName,
+            rela.retail_price as price,
+            (rela.market_price - rela.retail_price ) as savings,
+            g.goods_rate as startFax,
+            g.goods_rate as endFax,
+            g.plu as plu,
+            g.prod_barcode as barCode
+        from
+            mall_goods g
+        left join mall_product_store_rela rela on g.id = rela.goods_id
+        <where>
+            <if test="sku != null and storeId != ''">
+               and g.sku = #{sku}
+            </if>
+            <if test="storeId != null and storeId != ''">
+               and rela.store_id = #{storeId}
+            </if>
+        </where>
+
+
+    </select>
+
 </mapper>

BIN
kmall-admin/src/main/resources/static/font/ams1015.ttf


+ 2 - 1
kmall-admin/src/main/webapp/WEB-INF/page/sale/monthlyCustomers2.html

@@ -40,8 +40,9 @@
             <span>日期:</span>
             <input type="month" name="startMonth" id="startMonth"/>&nbsp;
             <input type="month" name="endMonth" id="endMonth" />&nbsp;
+            <span>预定月份数</span>
+                <input type="number" name="monthNumber" id="monthNumber">;
             <input type="button" name="queryButton" value="导出选中的数据" onclick="exportSelectedMonthData()" />
-            <input type="number" name="monthNumber" id="monthNumber">;
             </div>
         </div>
     </header>

+ 1 - 1
kmall-admin/src/main/webapp/js/sale/monthlyCustomers2.js

@@ -220,7 +220,7 @@ function exportSelectedMonthData(){
         endMonth:endMonth,
         monthNumber:monthNumber
     };
-    console.log(param+321313112);
+    console.log(param);
     exportFile('#rrapp', '../monthly/exportSelectedMonthData', param);
     // $.ajax({
     //     url: "../monthly/exportSelectedMonthData",

BIN
kmall-admin/src/main/webapp/statics/font/ams1015.ttf


+ 83 - 0
kmall-api/src/main/java/com/kmall/api/entity/exportpdf/PDFGoodsDto.java

@@ -0,0 +1,83 @@
+package com.kmall.api.entity.exportpdf;
+
+/**
+ * @author zhangchuangbiao
+ * @version 1.0
+ * 2020-09-14 16:35
+ */
+public class PDFGoodsDto {
+
+    private String productName; // 产品名称
+    private String englishName; // 产品英文名称
+    private String price; // 价格
+    private String savings; // 节约价格
+    private String startFax; // 开始税率
+    private String endFax; // 结束税率
+    private String plu;
+    private String barCode;
+
+
+    public String getProductName() {
+        return productName;
+    }
+
+    public void setProductName(String productName) {
+        this.productName = productName;
+    }
+
+    public String getEnglishName() {
+        return englishName;
+    }
+
+    public void setEnglishName(String englishName) {
+        this.englishName = englishName;
+    }
+
+    public String getPrice() {
+        return price;
+    }
+
+    public void setPrice(String price) {
+        this.price = price;
+    }
+
+    public String getSavings() {
+        return savings;
+    }
+
+    public void setSavings(String savings) {
+        this.savings = savings;
+    }
+
+    public String getStartFax() {
+        return startFax;
+    }
+
+    public void setStartFax(String startFax) {
+        this.startFax = startFax;
+    }
+
+    public String getEndFax() {
+        return endFax;
+    }
+
+    public void setEndFax(String endFax) {
+        this.endFax = endFax;
+    }
+
+    public String getPlu() {
+        return plu;
+    }
+
+    public void setPlu(String plu) {
+        this.plu = plu;
+    }
+
+    public String getBarCode() {
+        return barCode;
+    }
+
+    public void setBarCode(String barCode) {
+        this.barCode = barCode;
+    }
+}

+ 2 - 0
kmall-manager/src/main/resources/conf/print.properties

@@ -0,0 +1,2 @@
+font.url=/static/font/ams1015.ttf
+upload.dir=H:/Demo/code_1.pdf