java: itext 7.2.1 using jdk 17.0.1


/**
* iText 7.2.1
* bouncycastle 1.7.0
* slf4j-api-1.6.1
* slf4j-log4j12-1.6.1
* log4j-1.2.16
*
* */

 
	/**
	 * 
	 * 
	 * 
	 * */
   public static PdfFont getDefaultFont() {
       try {
//         return PdfFontFactory.createFont("C://windows//fonts//simsun.ttc,1", PdfEncodings.IDENTITY_H, false);// 引用系统字体
           return PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H");// 使用itext字体
       } catch (IOException e) {
           // 记录日志
           e.printStackTrace();
       }
       return null;
   }
    
	/**
	 * 
	 * 
	 * 
	 * */
   public static PdfFont getImportFont(String fontName) {
       // 获取resource下文件夹路径
       String path = "src/resource/";
       String fontPath = path + fontName;
       try {
           // 处理中文乱码(支持Linux系统)
           //FontProgram fontProgram = FontProgramFactory.createFont(fontPath, false);
           PdfFont font = PdfFontFactory.createFont(path, PdfEncodings.IDENTITY_H);
           return font;
       } catch (IOException e) {
           // 记录日志
           e.printStackTrace();
       }
       return null;
   }

    
   PdfFont hfFont;
   {
       try {
           hfFont =PdfFontFactory.createFont(path);// new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 8, Font.NORMAL);
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
 
   /**
    * 图片水印
    *
    * */
   public static void addImageToPDFDU(String PDFPath){      
	   
       try{     
            

           // PdfWriter writer = new PdfWriter(new File(PDFPath));            //new FileOutputStream();
            // writer = new PdfWriter(new File(PDFPath));
           // PdfDocument pdfDoc = new PdfDocument(writer);
 
 
 
           // PdfWriter pdfwriter = PdfWriter(new File(PDFPath);
            PdfDocument pdf = new PdfDocument(new PdfWriter(PDFPath));
            PageSize pageSize = new PageSize(PageSize.A4).rotate();

            //设置文档属性
            pdf.getDocumentInfo().setAuthor("涂聚文 Geovin Du");
            pdf.getDocumentInfo().setTitle("iText7 java测试PDF");
            pdf.getDocumentInfo().setSubject("涂聚文公司");
            pdf.getDocumentInfo().setMoreInfo("Geovin Du","1201");
            pdf.getDocumentInfo().setCreator("geovindu 涂聚文");
            pdf.getDocumentInfo().setKeywords("iText,涂聚文 塗聚文 Geovin Du");
            
            
            Document document = new Document(pdf,PageSize.A4,true);

            TextFooterEventHandler eventHandler = new TextFooterEventHandler(document);
            pdf.addEventHandler(PdfDocumentEvent.END_PAGE, eventHandler);
            for (int i = 0; i < 12; i++) {
            	document.add(new Paragraph("Test " + i + " 涂聚文 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.").setFont(getDefaultFont()));
            }

            // the currently last page is also the last page of the document, so inform the event listener 
            eventHandler.lastPage = pdf.getLastPage();
            
            
            PdfPage page1 = pdf.addNewPage();
            PdfCanvas canvas = new PdfCanvas(page1);
 
 
            // creating image data instance by passing the path to image
            ImageData img = ImageDataFactory.create("src/resource/gogo.png");
            canvas.saveState();
            // graphic state
            PdfExtGState state = new PdfExtGState();
            state.setFillOpacity(0.2f);
            canvas.setExtGState(state);
            canvas.addImageAt(img, 20, pageSize.getWidth()/2, false); //650,
            canvas.restoreState();
            document.add(new Paragraph("Adding image to PDF Example,涂聚文").setFont(getDefaultFont()));
            
            pdf.addNewPage();
           
            PdfFont headerFont = PdfFontFactory.createFont(path);
            PdfFont cellFont = PdfFontFactory.createFont(path);
 
     
           Table table = new Table(new float[]{4, 4, 4});
           table.setWidth(UnitValue.createPercentValue(100));
           // adding header
           table.addHeaderCell(new Cell().add(new Paragraph(
                   "姓").setFont(headerFont)));
           table.addHeaderCell(new Cell().add(new Paragraph(
                   "名").setFont(headerFont)));
           table.addHeaderCell(new Cell().add(new Paragraph(
                   "区域名称").setFont(headerFont)));          
            
            
    
           table.addCell(new Paragraph("1.0 geovindu").setFont(cellFont));
           table.addCell(new Paragraph("1.1 涂聚文").setFont(cellFont));
           table.addCell(new Paragraph("1.2 上海市").setFont(cellFont));
           
           table.addCell(new Paragraph("2.1 北京市").setFont(cellFont));
           table.addCell(new Paragraph("2.2 重庆市").setFont(cellFont));
           table.addCell(new Paragraph("2.3 宜春市").setFont(cellFont));
            
           document.add(table);
            
            
            
           document.close();
            
       } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
     }