|
@@ -1,6 +1,8 @@
|
|
|
package com.kmall.admin.utils.pdf.type;
|
|
|
|
|
|
+import com.kmall.admin.utils.pdf.BarcodeUtil;
|
|
|
import com.kmall.api.entity.exportpdf.PDFGoodsDto;
|
|
|
+import com.kmall.common.fileserver.util.FileManager;
|
|
|
import com.lowagie.text.*;
|
|
|
import com.lowagie.text.Font;
|
|
|
import com.lowagie.text.Image;
|
|
@@ -9,6 +11,7 @@ import com.lowagie.text.pdf.*;
|
|
|
import java.awt.*;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* @author zhangchuangbiao
|
|
@@ -28,10 +31,10 @@ public class PDFWrite_nohead_36 {
|
|
|
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();// 打开文档
|
|
|
+ doc.setMargins(0,0,0,0);
|
|
|
|
|
|
// -----------------------标签头----------------------
|
|
|
for (int i = 0; i < 9; i++) {
|
|
@@ -49,7 +52,7 @@ public class PDFWrite_nohead_36 {
|
|
|
table = new PdfPTable(4);
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
- setTable(bfHei, table, 13, pdfGoodsDto.getProductName());
|
|
|
+ setTable(bfHei, table, 10, pdfGoodsDto.getProductName());
|
|
|
}
|
|
|
|
|
|
doc.add(table);
|
|
@@ -113,8 +116,10 @@ public class PDFWrite_nohead_36 {
|
|
|
|
|
|
|
|
|
doc.add(table);
|
|
|
-
|
|
|
+ String dtoBarCode = pdfGoodsDto.getBarCode();
|
|
|
table = new PdfPTable(4);
|
|
|
+ byte[] bytes = BarcodeUtil.generateBarCode128(dtoBarCode, 9.0d, 1.28d, false, true);
|
|
|
+ String uploadUrl = FileManager.upload(dtoBarCode + UUID.randomUUID().toString(), bytes, String.valueOf(bytes.length));
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
// --------------底部黑色和条形码区域-------------------------------
|
|
|
PdfPTable pdfPTable7 = new PdfPTable(2);
|
|
@@ -122,7 +127,7 @@ public class PDFWrite_nohead_36 {
|
|
|
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);
|
|
|
+ Paragraph barCode = new Paragraph(dtoBarCode.substring(dtoBarCode.length()-4), font);
|
|
|
blankParagraph.add(barCode);
|
|
|
PLU.add(blankParagraph);
|
|
|
PLU.setAlignment(Element.ALIGN_CENTER);
|
|
@@ -134,7 +139,8 @@ public class PDFWrite_nohead_36 {
|
|
|
pluCell.setHorizontalAlignment(Element.ALIGN_LEFT); // 水平居中
|
|
|
pluCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中
|
|
|
// -------------条形码图片
|
|
|
- Image img = Image.getInstance("E:\\demo\\barCode.jpg");
|
|
|
+
|
|
|
+ Image img = Image.getInstance(uploadUrl);
|
|
|
img.setAlignment(Image.ALIGN_CENTER); //设置图片居中
|
|
|
img.setBorder(Image.NO_BORDER);
|
|
|
img.setBorderColor(Color.WHITE);
|