fei
20 小时以前 af47b774448bfa3ece4741664ce4d24128c8f629
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
package com.ruoyi.service.impl;
 
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.itextpdf.text.*;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.domain.vo.DocumentMaterialFileStyle;
import com.ruoyi.domain.vo.DocumentMaterialsVo;
import com.ruoyi.domain.vo.DocumentMaterialsVoSmall;
import com.ruoyi.service.IDocumentMaterialsService;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.List;
 
@Service
public class pdfGenerateService {
    @Autowired
    private BarcodeService barcodeService;
    @Autowired
    private IDocumentMaterialsService documentMaterialsService;
    //生产二维码
    public byte[] createQrCodeN(String content, int width, int height) throws IOException {
        QrConfig config = new QrConfig(width, height);
 
        config.setMargin(3);
        // 高纠错级别
        config.setErrorCorrection(ErrorCorrectionLevel.H);
        // 设置前景色,既二维码颜色(自行选择颜色修改)
        config.setForeColor(new Color(11, 11, 11).getRGB());
// 设置背景色(灰色)需要背景色时候打开链接
        config.setBackColor(new Color(242,242,242).getRGB());
 
 
        BufferedImage bufferedImage = QrCodeUtil.generate(//
                content, //二维码内容
                config
        );
        System.out.println(bufferedImage);
        System.out.println("---02340230949394");
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(bufferedImage, "jpg", os);
 
 
//        ImageIO.write(bufferedImage, "jpg", new File("outputImage.jpg"));
 
        return os.toByteArray();
    }
    private void handleXSSFImages(XSSFSheet sheet, Document pdfDoc) throws Exception {
        XSSFDrawing drawing = sheet.getDrawingPatriarch();
        if (drawing == null) return;
 
        for (XSSFShape shape : drawing.getShapes()) {
            if (shape instanceof XSSFPicture) {
                XSSFPicture pic = (XSSFPicture)shape;
                XSSFClientAnchor anchor = pic.getPreferredSize();
 
                // 获取图片数据
                byte[] bytes = pic.getPictureData().getData();
                Image pdfImage = Image.getInstance(bytes);
 
                // 设置图片位置和大小
                float imageWidth = pdfImage.getWidth();
                float imageHeight = pdfImage.getHeight();
                float scale = Math.min(
                        (PageSize.A4.getWidth() - 100) / imageWidth,
                        (PageSize.A4.getHeight() - 100) / imageHeight
                );
                pdfImage.scaleAbsolute(imageWidth * scale, imageHeight * scale);
 
                // 添加图片到PDF
                pdfDoc.add(pdfImage);
                pdfDoc.add(Chunk.NEWLINE);
            }
        }
    }
 
 
 
 
    private static String getCellValue(Cell cell,FormulaEvaluator evaluator) {
        //  System.out.println(cell);
        if (cell == null) return "";
        CellValue cellValue = evaluator.evaluate(cell);
        if(cellValue==null)
            return "";
        //  System.out.println(cellValue.getCellType());
        switch (cellValue.getCellType()) {
            case STRING:
                return cell.getStringCellValue();
            case NUMERIC:
                // 获取数值并转为整型
                double numericValue = cell.getNumericCellValue();
                // 判断是否为整数
                if (numericValue == (int)numericValue) {
                    if((int)numericValue==0)
                        return "";
                    else
                        return String.valueOf((int)numericValue);
                } else {
                    return String.valueOf(numericValue); // 或者根据需要返回四舍五入的整型
                }
 
            case BOOLEAN:
                return String.valueOf(cell.getBooleanCellValue());
            case FORMULA:
 
                return cell.getCellFormula()+"";
            case BLANK:
                return "";
            default:
                return "";
        }
    }
    private int getRealLastCellNum(Row row) {
        int lastCellNum = 0;
        for (int i = 0; i < row.getLastCellNum(); i++) {
            Cell cell = row.getCell(i);
            if (cell != null && cell.getCellType() != CellType.BLANK) {
                lastCellNum = i + 1;
            }
        }
        return lastCellNum;
    }
 
    //
    void generateSimpleExample()
    {
 
//        try {
//            // 1. 读取Excel文件
//            String excelPath = RuoYiConfig.getProfile() + "/download/"+"卷內目录.xls";
//            String pdfPath = RuoYiConfig.getProfile() + "/download/"+"1.pdf";
//
//            Workbook workbook = WorkbookFactory.create(new File(excelPath));
//            FileOutputStream fos = new FileOutputStream(pdfPath);
//            FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
//
//
//            // 获取第一个工作表
//            Sheet sheet = workbook.getSheetAt(1);
//
//            // 创建PDF文档对象
//            Document document = new Document(PageSize.A2, 50, 50, 50, 50);
//
//            // 创建PDF输出流
//            PdfWriter writer = PdfWriter.getInstance(document, fos);
//            // 4. 处理工作表中的图片
//            if (workbook instanceof XSSFWorkbook) {
//                handleXSSFImages((XSSFSheet)sheet, document);
//            }
//            // 打开PDF文档
//            document.open();
//
//            // 创建PDF表格对象
//            System.out.println(sheet.getRow(0).getLastCellNum()+"--00");
//            PdfPTable table = new PdfPTable(sheet.getRow(0).getLastCellNum());
//            table.setHeaderRows(1);
//
//            // 设置表格宽度
//            table.setWidthPercentage(100);
//
//            // 设置表格标题
//            Paragraph title = new Paragraph(sheet.getSheetName(), new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 16, Font.BOLD));
//            title.setAlignment(Element.ALIGN_CENTER);
//            document.add(title);
//            // System.out.println(sheet.)
//            // 添加表格内容
//            for (Row row : sheet) {
//                {
//                    if (row == null) continue;
//                    System.out.println(getRealLastCellNum(row)+"---987");
////                            if(row.getRowNum()==0)
////                                continue;
//                    if(row.getRowNum()==2)
//                    {
//                        PdfPCell pdfCell = ImageSet(100);
//                        pdfCell.setColspan(7);
//                        pdfCell.setRowspan(3);
//                        pdfCell.setBorderWidth(1f);
//                        pdfCell.setBorderColor(BaseColor.BLACK);
//                        pdfCell.setPadding(5f);
//                        pdfCell.setHorizontalAlignment(Element.ALIGN_CENTER);
//                        pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//                        table.addCell(pdfCell);
//                        System.out.println("{{{{{{{{{{{{{");
//                        continue;
//                    }
//                    for (int i = 0; i < 7; i++)
//                    {
//
//                        Cell cell = row.getCell(i);
//                        if(row.getRowNum()==3)
//                        {
//                            PdfPCell pdfCell = new PdfPCell(new Paragraph("卷内目录", new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12)));
//                            pdfCell.setColspan(7);
//                            pdfCell.setBorderWidth(1f);
//                            pdfCell.setBorderColor(BaseColor.BLACK);
//                            pdfCell.setPadding(5f);
//                            pdfCell.setHorizontalAlignment(Element.ALIGN_CENTER);
//                            pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//                            table.addCell(pdfCell);
//                            System.out.println("{{{{{{{{{{{{{");
//                            break;
//                        }
//                        if(cell==null) {
//
//                            table.addCell("");
//                            continue;
//                        }
//                        PdfPCell pdfCell = new PdfPCell(new Paragraph(getCellValue(cell, evaluator), new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12)));
//
//                        if(row.getRowNum()!=1) {
//                            pdfCell.setBorderWidth(1f);
//                            pdfCell.setBorderColor(BaseColor.BLACK);
//                            pdfCell.setPadding(5f);
//                            pdfCell.setHorizontalAlignment(Element.ALIGN_CENTER);
//                            pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//                        }
//                        if (cell.getRowIndex() == 5) {
//                            pdfCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
//                        }
//
//                        table.addCell(pdfCell);
//
//                    }
//                }
//            }
//
//            // 添加表格到PDF文档
//            table.setSpacingBefore(20f);
//            table.setSpacingAfter(20f);
//            table.setKeepTogether(true);
//            document.add(table);
//
//            // 关闭PDF文档
//            document.close();
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
 
    }
 
 
    //导出卷内目录的pdf
    public void generateFileDirectoryPdf(String pdfPath,List<DocumentMaterialsVo> dvss) throws DocumentException, IOException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(pdfPath));
        document.open();
 
        // 创建表格(5列)
        PdfPTable table = new PdfPTable(7);
 
        // 设置表格宽度(占页面宽度的100%)
        table.setWidthPercentage(100);
 
 
        //添加条形码
        String volumeNumber = dvss.get(0).getRecordId();
        Image img = Image.getInstance(barcodeService.generateBarcodeImage(volumeNumber));
        // 设置图片在PDF中的位置(可选)
//        img.setAbsolutePosition(100, 100);
        // 将图片添加到PDF文档中
        PdfPCell pdfPCell = new PdfPCell(img);
        pdfPCell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框
 
        pdfPCell.setMinimumHeight(40);
        pdfPCell.setUseAscender(true); // 设置可以居中
        pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
        pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
        pdfPCell.setColspan(2);
        pdfPCell.setPaddingBottom(30);
// 创建表格并设置列宽比例
        float[] columnWidths = {35f, 65f}; // 第一列30%,第二列70%
        PdfPTable table1 = new PdfPTable(columnWidths);
//        PdfPTable table = new PdfPTable(2);
        table1.setWidthPercentage(80); // 增大表格宽度百分比
        table1.setHorizontalAlignment(Element.ALIGN_LEFT); // 设置表格整体居中
        table1.setSpacingBefore(30f); // 设置表格前间距
 
        table1.addCell(pdfPCell);
 
        document.add(table1);
 
 
        // 添加表头
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font chineseFont = new Font(bfChinese, 12);
        Font chineseFont1 = new Font(bfChinese, 16, Font.BOLD);
        // 添加标题
        Paragraph title = new Paragraph("卷    内    目    录", chineseFont1);
        title.setAlignment(Element.ALIGN_CENTER);
        document.add(title);
        Paragraph withNewLine = new Paragraph("\n");
        document.add(withNewLine);
        document.add(withNewLine);
 
 
        //添加卷号
        Paragraph recordInfo = new Paragraph("卷号:" + volumeNumber, chineseFont);
        recordInfo.setAlignment(Element.ALIGN_RIGHT);
        document.add(recordInfo);
 
        document.add(withNewLine);
        document.add(withNewLine);
        String[] headers = {"序号", "文件编号", "责任者", "文件题名", "日期", "页号", "备注"};
        for (String header : headers) {
            PdfPCell cell = new PdfPCell(new Paragraph(header,
                    chineseFont1));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(200, 200, 200));
            table.addCell(cell);
        }
 
        // 添加表格数据
//        Object[][] data = {
//              //  {1, "商品A", 2, 100.00, 200.00},
//             //   {2, "商品B", 1, 250.50, 250.50},
//             //   {3, "商品C", 3, 80.00, 240.00}
//        };
//        data.
      //  for (Object[] row : data) {
            for (DocumentMaterialsVo cellData : dvss) {
                //序号
                PdfPCell cell = new PdfPCell(new Paragraph(cellData.getNum().toString(),
                        chineseFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(cell);
 
 
                //序号
                PdfPCell cell1 = new PdfPCell(new Paragraph(cellData.getDocumentNumber()==null?"":cellData.getDocumentNumber().toString(),
                        chineseFont));
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
 
                table.addCell(cell1);
 
 
                //序号
                PdfPCell cell2 = new PdfPCell(new Paragraph(cellData.getCreator()==null?"":cellData.getCreator().toString(),
                        chineseFont));
                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
 
                table.addCell(cell2);
 
 
                //序号
                PdfPCell cell3 = new PdfPCell(new Paragraph(cellData.getTitle()==null?"":cellData.getTitle().toString(),
                        chineseFont));
                cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
 
                cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell3);
 
                //序号
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
               // String dateString = sdf.format(date);
                PdfPCell cell4 = new PdfPCell(new Paragraph(cellData.getDate()==null?"":sdf.format(cellData.getDate()),
                        chineseFont));
                cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
 
                cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell4);
 
 
                //序号
                PdfPCell cell5 = new PdfPCell(new Paragraph(cellData.getPageNumber()==null?"": cellData.getPageNumber().toString(),
                        chineseFont));
                cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);
 
                table.addCell(cell5);
 
                //序号
                PdfPCell cell6 = new PdfPCell(new Paragraph(cellData.getRemarks()==null?"":cellData.getRemarks().toString(),
                        chineseFont));
                cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);
 
                cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell6);
            }
      //  }
 
        document.add(table);
        document.close();
    }
    //设置备考表
   public void generateFileStyleInfo(String pdfPath, String volumeNumber, Long id) throws IOException, DocumentException {
       Document document = new Document();
       PdfWriter.getInstance(document, new FileOutputStream(pdfPath));
       document.open();
 
// 创建PDF文档
       List<DocumentMaterialFileStyle> dmfs = documentMaterialsService.findFileStyleInfo(Math.toIntExact(id));
       PdfWriter.getInstance(document, new FileOutputStream("09-备考表"+".pdf"));
       document.open();
       // 设置中文字体
 
       BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
       Font chineseFont = new Font(bfChinese, 16, Font.BOLD);
       // 添加标题
       Paragraph title = new Paragraph("卷内备考表", chineseFont);
       title.setAlignment(Element.ALIGN_CENTER);
       document.add(title);
 
       // 添加内容
     //  String volumeNumber = "D3.4.1-05-2024-0002";
       Paragraph recordInfo = new Paragraph("卷号:" + volumeNumber, chineseFont);
       recordInfo.setAlignment(Element.ALIGN_RIGHT);
       document.add(recordInfo);
       int allCnt = dmfs.get(0).getCnt() + dmfs.get(1).getCnt() + dmfs.get(2).getCnt();
       document.add(new Paragraph("          本 案 卷 共 有 文 件 材 料 " + allCnt + " 页"+",其中:文字材料 " +
               dmfs.get(1).getCnt() + " 页"+",图样材料 " + dmfs.get(2).getCnt() + " 页"+",照片 " + dmfs.get(0).getCnt() + " 张", chineseFont));
 
 
       document.add(new Paragraph("说明: ", chineseFont));
       // 方法2:使用带换行符的Paragraph
       for(int i = 0; i < 10; i++) {
           Paragraph withNewLine = new Paragraph("\n");
           document.add(withNewLine);
       }
 
 
       String tis1 = "立卷人:仇翀(广州盈家档案管理有限公司)";
       Paragraph par1 = new Paragraph(tis1, chineseFont);
       par1.setAlignment(Element.ALIGN_RIGHT);
       document.add(par1);
       //拿到当前时间
       // 获取当前日期
       LocalDate currentDate = LocalDate.now();
 
       // 打印年、月、日
//       System.out.println("Year: " + currentDate.getYear());
//       System.out.println("Month: " + currentDate.getMonthValue()); // 月份是从1开始的
//       System.out.println("Day of Month: " + currentDate.getDayOfMonth());
       Paragraph withNewLine = new Paragraph("\n");
       document.add(withNewLine);
       String cdt = currentDate.getYear()+"年"+currentDate.getMonthValue()+"月"+currentDate.getDayOfMonth()+"日";
 
 
       Paragraph par3 = new Paragraph(cdt, chineseFont);
       par3.setAlignment(Element.ALIGN_RIGHT);
       document.add(par3);
       String tis2 = "审核人:曾瑞莹(广州盈家档案管理有限公司)";
       document.add(withNewLine);
 
       Paragraph par2 = new Paragraph(tis2, chineseFont);
       par2.setAlignment(Element.ALIGN_RIGHT);
       document.add(par2);
       document.add(withNewLine);
       document.add(par3);
 
       document.close();
 
   }
 
    public void generatePdf(String pdfPath) throws IOException, DocumentException {
 
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(pdfPath));
        document.open();
 
        String [] tits = {"档        号:","档案馆(室)号:","缩  微  号: ","发  文  号:",
                "案  卷  题  名:","编  制  日  期:","编  制  单  位:","保  管  期  限:","密     级:"};
        String [] cons = {"D3.4.1-05-2024-0002","","","穗规划资源建证〔2024〕2033号","广州市自来水有限公司白云区江高镇江高镇政府西侧、江府路北侧白云区江高镇江高镇政府西侧、江府路北侧新装供水管工程","2024-04-23","广州市规划和自然资源局白云区分局","永久",""};
 
        //把图片加入到pdf当中
        Image img = Image.getInstance(createQrCodeN(cons[0], 80, 80));
        // 设置图片在PDF中的位置(可选)
//        img.setAbsolutePosition(100, 100);
        // 将图片添加到PDF文档中
        PdfPCell pdfPCell = new PdfPCell(img);
        pdfPCell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框
 
        pdfPCell.setMinimumHeight(80);
        pdfPCell.setUseAscender(true); // 设置可以居中
        pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
        pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
        pdfPCell.setColspan(2);
        pdfPCell.setPaddingBottom(30);
 
// 创建表格并设置列宽比例
        float[] columnWidths = {35f, 65f}; // 第一列30%,第二列70%
        PdfPTable table = new PdfPTable(columnWidths);
//        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(80); // 增大表格宽度百分比
        table.setHorizontalAlignment(Element.ALIGN_LEFT); // 设置表格整体居中
        table.setSpacingBefore(30f); // 设置表格前间距
        table.setSpacingAfter(90f); // 设置表格后间距
 
 
//        PdfPTable table1 = new PdfPTable(1);
//        table1.setWidthPercentage(90); // 增大表格宽度百分比
//        table1.setHorizontalAlignment(Element.ALIGN_LEFT); // 设置表格整体居中
//        table1.setSpacingBefore(10f); // 设置表格前间距
//        table1.setSpacingAfter(10f); // 设置表格后间距
        table.addCell(pdfPCell);
//        document.add(table1);
        // 设置中文字体
 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font chineseFont = new Font(bfChinese, 16, Font.BOLD);
        Font chineseFont1 = new Font(bfChinese, 10, Font.BOLD);
 
        // 添加档号
        // 添加带下划线的档号
 
 
 
        for(int i = 0; i < tits.length; i++) {
            // 使用PdfPTable实现精确对齐
 
            // 第一行:档号
            PdfPCell labelCell1 = new PdfPCell(new Phrase(tits[i], chineseFont));
            labelCell1.setHorizontalAlignment(Element.ALIGN_RIGHT); // 设置右对齐
 
            labelCell1.setBorder(Rectangle.NO_BORDER);
//            PdfPCell valueCell1 = new PdfPCell(new Phrase(cons[i], chineseFont));
//            valueCell1.setBorder(Rectangle.NO_BORDER);
            labelCell1.setMinimumHeight(30);
            labelCell1.setPaddingTop(10f);    // 上内边距10单位
            labelCell1.setPaddingBottom(10f); // 下内边距10单位
            labelCell1.setPaddingLeft(15f);   // 左内边距15单位
            labelCell1.setPaddingRight(15f);  // 右内边距15单位
 
 
            PdfPCell valueCell1 = new PdfPCell(new Phrase(cons[i], chineseFont));
            valueCell1.setBorder(Rectangle.NO_BORDER);
            valueCell1.setUseBorderPadding(true);
            valueCell1.setBorderWidthBottom(0.5f); // 设置底部边框作为下划线
            valueCell1.setMinimumHeight(30);
            valueCell1.setPaddingTop(10f);    // 上内边距10单位
            valueCell1.setPaddingBottom(10f); // 下内边距10单位
            valueCell1.setPaddingLeft(15f);   // 左内边距15单位
            valueCell1.setPaddingRight(15f);  // 右内边距15单位
            table.addCell(labelCell1);
            table.addCell(valueCell1);
 
            if(i==3)
            {
                //增加那个条形码
                byte []  bas = barcodeService.generateBarcodeImage(cons[0]);
 
                Image img1= Image.getInstance(bas);
 
                PdfPCell pdfPCell1 = new PdfPCell(img1);
                pdfPCell1.setBorder(Rectangle.NO_BORDER); // 移除单元格边框
 
                pdfPCell1.setMinimumHeight(40);
                pdfPCell1.setUseAscender(true); // 设置可以居中
                pdfPCell1.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
                pdfPCell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                pdfPCell1.setColspan(2);
                pdfPCell1.setPaddingBottom(20);
                pdfPCell1.setPaddingTop(20);
                table.addCell(pdfPCell1);
            }
 
 
        }
        document.add(table); // 空行
 
        // 关闭文档
        document.close();
    }
}