主頁 > 後端開發 > java: create pdf using itextpdf 2.1.7 or 7.1.10 Library

java: create pdf using itextpdf 2.1.7 or 7.1.10 Library

2022-01-20 06:05:51 後端開發

 

/**
 * 著作權所有 2022 涂聚文有限公司
 * 許可資訊查看:
 * 描述:
 * IDE:IntelliJ IDEA 2021.2.3
 * 資料庫:MSSQL Server 2019
 * OS:windows 10 x64
 * 歷史版本: JDK 14.02
 * 2022-1-12 創建者 geovindu
 * 2022-1-15 添加 Lambda
 * 2022-1-15 修改:date
 * 介面類 mssql-jdbc-9.4.1.jre16.jar.
 *
 * 2022-1-15 修改者:Geovin Du
 * 生成API幫助檔案的指令:
 *javadoc - -encoding Utf-8 -d apidoc iTextHelper.java
 https://mvnrepository.com/artifact/com.itextpdf
 https://mvnrepository.com/artifact/com.lowagie/itext/2.1.7
 https://mvnrepository.com/artifact/com.lowagie/itext/4.2.1

 https://sourceforge.net/projects/itext/
 https://github.com/itext

 java write stringbuilder to file
 http://guava-libraries.googlecode.com/
 https://github.com/google/guava
 Files.write(stringBuilder, file, Charsets.UTF_8)

 http://commons.apache.org/io/
 You could use the Apache Commons IO library, which gives you FileUtils:

 FileUtils.writeStringToFile(file, stringBuilder.toString(), Charset.forName("UTF-8"))


 https://github.com/weiyeh/iText-4.2.0
 https://github.com/ymasory/iText-4.2.0
 https://mvnrepository.com/artifact/com.itextpdf/html2pdf
 http://www.java2s.com/Code/Jar/i/Downloaditextpdf541jar.htm
 http://www.java2s.com/Code/Jar/i/Downloaditextrtf215jar.htm
 https://mvnrepository.com/artifact/com.lowagie/itext-rtf/2.1.7
 http://www.java2s.com/Code/Jar/i/Downloaditextasian217jar.htm

 https://mvnrepository.com/artifact/com.itextpdf/itext-asian/5.2.0
 https://mvnrepository.com/artifact/com.itextpdf
 https://mvnrepository.com/artifact/com.itextpdf.tool
 http://www.java2s.com/Code/Jar/i/itext.htm
 
 * */


package Geovin.Common;

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/*
5.4.1
import com.itextpdf.io.*;
import com.itextpdf.pdfa.*;
import com.itextpdf.test.*;
import com.itextpdf.commons.*;
import com.itextpdf.pdfa.PdfADocument;
import com.itextpdf.barcodes.*;
import com.itextpdf.svg.*;
import com.itextpdf.forms.*;
import com.itextpdf.kernel.*;
import com.itextpdf.layout.*;
import com.itextpdf.layout.font.*;
import com.itextpdf.styledxmlparser.*;
import com.itextpdf.signatures.*;
import com.itextpdf.text.*;

import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.Image;

import com.itextpdf.text.Phrase;
import com.itextpdf.text.Header;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.TextField;
import com.itextpdf.text.*;
*/


import Geovin.Model.Person;
import com.lowagie.text.BadElementException;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.tools.*;
import com.lowagie.text.pdf.fonts.*;

/**
 *itext-rtf 2.1.7
 * itextasian 2.1.7
 *itextpdf 2.1.7
 * @author geovindu
 * @version 1.0
 * */

public class iTextHelper {



    /**
     *
     *
     *
     * */
    public  void Create() throws DocumentException, IOException
    {
        // 創建Document物件(頁面的大小為A4,左、右、上、下的頁邊距為10)
        Document document = new Document(PageSize.A4, 10, 10, 10, 10);
        // 建立書寫器
        PdfWriter.getInstance(document, new FileOutputStream("src/geovindu.PDF"));
        // 設定相關的引數
        setParameters(document, "開發者測驗", "涂聚文測驗", "測驗 開發者 除錯", "geovindu", "geovindu");
        // 打開檔案
        document.open();
        // 使用iTextAsian.jar中的字體
        BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font font = new Font(baseFont);

        List<Person> personList = new ArrayList<Person>();
        // 回圈添加物件
        for (int i = 0; i < 5; i++) {
            Person user = new Person();
            user.setLastName("geovindu:"+i);
            user.setFirstName("開發者測驗"+i);
            user.setSex("測驗"+i);
            personList.add(user);
        }

        Table table = setTable(personList);
        document.add(new Paragraph("用戶資訊如下:",setFont()));
        document.add(table);

        // 關閉檔案
        document.close();
    }


     /**
      *
      *
      * */
     public Table setTable(List<Person> personList) throws BadElementException{
        //創建一個有3列的表格
        Table table = new Table(3);
        table.setBorderWidth(1);
        table.setBorderColor(new Color(0, 0, 255));
        table.setPadding(5);
        table.setSpacing(5);
        // 創建表頭
        Cell cell1 = setTableHeader("姓");
        Cell cell2 = setTableHeader("名");
        Cell cell3 = setTableHeader("性別");
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        // 添加此代碼后每頁都會顯示表頭
        table.endHeaders();


        for (int i = 0; i < personList.size(); i++) {
            Cell celli1 = setTableHeader(personList.get(i).getLastName());
            Cell celli2 = setTableHeader(personList.get(i).getFirstName());
            Cell celli3 = setTableHeader(personList.get(i).getSex());
            table.addCell(celli1);
            table.addCell(celli2);
            table.addCell(celli3);
        }

        return table;

    }

    /**
     * itextasian 2.1.7
     *
     * */
    public  Font setFont(){
        BaseFont baseFont = null;
        try {
            baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Font font = new Font(baseFont, 8, Font.NORMAL,Color.BLUE);
        return font;
    }
    /**
     * 設定cell
     * @param name
     * @return
     * @throws BadElementException
     */
    public  Cell setTableHeader(String name) throws BadElementException {

        Cell cell = new Cell(new Phrase(name, setFont()));
        //單元格水平對齊方式
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //單元格垂直對齊方式
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
       //        cell.setHeader(true);
        //cell.setBackgroundColor(Color.RED);
        return cell;

    }
    /**
     * 設定相關引數
     * @param document
     * @return
     */
    public  Document setParameters(Document document,String title,String subject,String keywords,String author,
                                         String creator){
        // 設定標題
        document.addTitle(title);
        // 設定主題
        document.addSubject(subject);
        // 設定作者
        document.addKeywords(keywords);
        // 設定作者
        document.addAuthor(author);
        // 設定創建者
        document.addCreator(creator);
        // 設定生產者
        document.addProducer();
        // 設定創建日期
        document.addCreationDate();

        return document;
    }




}

  

5.2.0

/**
 * 著作權所有 2022 涂聚文有限公司
 * 許可資訊查看:
 * 描述:
 * IDE:IntelliJ IDEA 2021.2.3
 * 資料庫:MSSQL Server 2019
 * OS:windows 10 x64
 * 歷史版本: JDK 14.02
 * 2022-1-12 創建者 geovindu
 * 2022-1-15 添加 Lambda
 * 2022-1-15 修改:date
 * 介面類 mssql-jdbc-9.4.1.jre16.jar.
 *
 * 2022-1-15 修改者:Geovin Du
 * 生成API幫助檔案的指令:
 *javadoc - -encoding Utf-8 -d apidoc DuiTextPdfHelper.java
 *
 *
 https://mvnrepository.com/artifact/com.itextpdf
 https://mvnrepository.com/artifact/com.lowagie/itext/2.1.7
 https://mvnrepository.com/artifact/com.lowagie/itext/4.2.1

 https://sourceforge.net/projects/itext/
 https://github.com/itext

 java write stringbuilder to file
 http://guava-libraries.googlecode.com/
 https://github.com/google/guava
 Files.write(stringBuilder, file, Charsets.UTF_8)

 http://commons.apache.org/io/
 You could use the Apache Commons IO library, which gives you FileUtils:

 FileUtils.writeStringToFile(file, stringBuilder.toString(), Charset.forName("UTF-8"))


 https://github.com/weiyeh/iText-4.2.0
 https://github.com/ymasory/iText-4.2.0
 https://mvnrepository.com/artifact/com.itextpdf/html2pdf
 http://www.java2s.com/Code/Jar/i/Downloaditextpdf541jar.htm
 http://www.java2s.com/Code/Jar/i/Downloaditextrtf215jar.htm
 https://mvnrepository.com/artifact/com.lowagie/itext-rtf/2.1.7
 http://www.java2s.com/Code/Jar/i/Downloaditextasian217jar.htm
 https://mvnrepository.com/artifact/com.lowagie/itext
 https://mvnrepository.com/artifact/com.itextpdf/itext-asian/5.2.0
 https://mvnrepository.com/artifact/com.itextpdf
 https://mvnrepository.com/artifact/com.itextpdf.tool
 http://www.java2s.com/Code/Jar/i/itext.htm
 https://www.vogella.com/tutorials/JavaPDF/article.html
 * */


package Geovin.Common;

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;

import com.itextpdf.io.*;
import com.itextpdf.pdfa.*;
import com.itextpdf.test.*;
import com.itextpdf.pdfa.PdfADocument;
import com.itextpdf.barcodes.*;
import com.itextpdf.svg.*;
import com.itextpdf.forms.*;
import com.itextpdf.kernel.*;
import com.itextpdf.layout.*;
import com.itextpdf.layout.font.*;
import com.itextpdf.styledxmlparser.*;
import com.itextpdf.signatures.*;
import com.itextpdf.text.*;

import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.Image;

import com.itextpdf.text.Phrase;
import com.itextpdf.text.Header;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.TextField;


import com.itextpdf.text.Anchor;
import com.itextpdf.text.BadElementException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chapter;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Section;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;


/**
 * iText 5.2.0
 * @author geovindu
 * @version 1.0
 *
 *
 *
 * */
public class DuiTextPdfHelper {

    private static String FILE = "src/geovinduPdf.pdf";
    private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18,
            Font.BOLD);
    private static Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12,
            Font.NORMAL, BaseColor.RED);
    private static Font subFont = new Font(Font.FontFamily.TIMES_ROMAN, 16,
            Font.BOLD);
    private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12,
            Font.BOLD);

    public static void CreatePdf()
    {
        try {
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream(FILE));
            document.open();
            addMetaData(document);
            addTitlePage(document);
            addContent(document);
            document.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // iText allows to add metadata to the PDF which can be viewed in your Adobe
    // Reader
    // under File -> Properties
    private static void addMetaData(Document document) {
        document.addTitle("My first PDF");
        document.addSubject("Using iText");
        document.addKeywords("Java, PDF, iText");
        document.addAuthor("geovindu");
        document.addCreator("geovindu");
    }

    private static void addTitlePage(Document document)
            throws DocumentException {
        Paragraph preface = new Paragraph();
        // We add one empty line
        addEmptyLine(preface, 1);
        // Lets write a big header
        preface.add(new Paragraph("Title of the document", catFont));

        addEmptyLine(preface, 1);
        // Will create: Report generated by: _name, _date
        preface.add(new Paragraph(
                "Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                smallBold));
        addEmptyLine(preface, 3);
        preface.add(new Paragraph(
                "This document describes something which is very important ",
                smallBold));

        addEmptyLine(preface, 8);

        preface.add(new Paragraph(
                "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
                redFont));

        document.add(preface);
        // Start a new page
        document.newPage();
    }

    private static void addContent(Document document) throws DocumentException {
        Anchor anchor = new Anchor("First Chapter", catFont);
        anchor.setName("First Chapter");

        // Second parameter is the number of the chapter
        Chapter catPart = new Chapter(new Paragraph(anchor), 1);

        Paragraph subPara = new Paragraph("Subcategory 1", subFont);
        Section subCatPart = catPart.addSection(subPara);
        subCatPart.add(new Paragraph("Hello"));

        subPara = new Paragraph("Subcategory 2", subFont);
        subCatPart = catPart.addSection(subPara);
        subCatPart.add(new Paragraph("Paragraph 1"));
        subCatPart.add(new Paragraph("Paragraph 2"));
        subCatPart.add(new Paragraph("Paragraph 3"));

        // add a list
        createList(subCatPart);
        Paragraph paragraph = new Paragraph();
        addEmptyLine(paragraph, 5);
        subCatPart.add(paragraph);

        // add a table
        createTable(subCatPart);

        // now add all this to the document
        document.add(catPart);

        // Next section
        anchor = new Anchor("Second Chapter", catFont);
        anchor.setName("Second Chapter");

        // Second parameter is the number of the chapter
        catPart = new Chapter(new Paragraph(anchor), 1);

        subPara = new Paragraph("Subcategory", subFont);
        subCatPart = catPart.addSection(subPara);
        subCatPart.add(new Paragraph("This is a very important message"));

        // now add all this to the document
        document.add(catPart);

    }

    private static void createTable(Section subCatPart)
            throws BadElementException {
        PdfPTable table = new PdfPTable(3);

        // t.setBorderColor(BaseColor.GRAY);
        // t.setPadding(4);
        // t.setSpacing(4);
        // t.setBorderWidth(1);

        PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Table Header 2"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Table Header 3"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        table.setHeaderRows(1);

        table.addCell("1.0");
        table.addCell("1.1");
        table.addCell("1.2");
        table.addCell("2.1");
        table.addCell("2.2");
        table.addCell("2.3");

        subCatPart.add(table);

    }

    private static void createList(Section subCatPart) {
        List list = new List(true, false, 10);
        list.add(new ListItem("First point"));
        list.add(new ListItem("Second point"));
        list.add(new ListItem("Third point"));
        subCatPart.add(list);
    }

    private static void addEmptyLine(Paragraph paragraph, int number) {
        for (int i = 0; i < number; i++) {
            paragraph.add(new Paragraph(" "));
        }
    }


}

  

https://riptutorial.com/Download/itext.pdf

https://www.netjstech.com/2018/10/creating-pdf-in-java-using-itext.html

https://github.com/itext/i7js-examples/blob/develop/src/main/java/com/itextpdf/samples/sandbox/layout/ParagraphTextWithStyle.java

https://kb.itextsupport.com/home/it7kb/ebooks/itext-7-jump-start-tutorial-for-java/chapter-7-creating-pdf-ua-and-pdf-a-documents

https://www.tutorialspoint.com/itext/itext_adding_table.htm

 7.2.7

/**
 * 著作權所有 2021 涂聚文有限公司
 * 許可資訊查看:
 * 描述:
 * 
 * 資料庫:Ms SQL server 2019
 * IDE: Eclipse IDE for Enterprise Java and Web Developers - 2021-09
 * OS: Windows 10 x64
 * IDE: Eclipse IDE for Enterprise Java and Web Developers - 2021-09
 * 歷史版本: JDK 14.0.2
 * 2021-12-12 創建者 geovindu
 * 2021-12-15 添加 Lambda
 * 2021-12-15 修改:date
 * 介面類 mssql-jdbc-9.4.1.jre16.jar.
 * 資料庫:MSSQL Server 2019
 * 2021-12-15 修改者:Geovin Du
 * 生成API幫助檔案的指令:
 *javadoc - -encoding Utf-8 -d apidoc DuiTextPdfHelper.java
 *https://www.microsoft.com/en-us/software-download/windows10
 *https://github.com/PaddlePaddle/PaddleOCR
 *https://docs.microsoft.com/es-es/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15
 *https://github.com/microsoft/mssql-jdbc/blob/main/README.md
 *oracle.jdbc.driver.OracleDriver
 *
 *1、打開idea安裝目錄的bin目錄下的idea.exe.vmoption和idea64.exe.vmoption,在最后加上 -Dfile.encoding=utf-8
2、設定idea file編碼,在選單欄找到”File->settings->搜索File Encodeing,然后在IDE Encoding ,Project Encoding和Default encoding for properties files都設定為utf-8
3、設定idea server編碼,在選單欄找到”run->editconfigration” 找到”server”選項卡 設定 vm option為 -Dfile.encoding=utf-8
4、HELP->Edit Custom VM OPtions中加 -Dfile.encoding=utf-8 重啟idea


 * */

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.util.ArrayList;
//import java.util.List;
import com.itextpdf.*;
import com.itextpdf.io.font.*;
import com.itextpdf.pdfa.*;
import com.itextpdf.kernel.*;
import com.itextpdf.kernel.pdf.*;
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Text;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.*;
import com.itextpdf.layout.element.List;
import com.itextpdf.layout.element.ListItem;
//import com.itextpdf.layout.property.ListNumberingType;
import com.itextpdf.layout.properties.*;


/**
 * itext 7.2.1
 * @author geovindu
 * @version 1.0
 * 
 * 
 * */
public class DuiTextPdfHelper {
	
	
	 private static String FILE = "src/geovindu.pdf";
	   //PdfFont catFont =PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);// new Font(Font.FontFamily.TIMES_ROMAN, 18,Font.BOLD);
	    //  PdfFont redFont =PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);// new Font(Font.FontFamily.TIMES_ROMAN, 12,Font.NORMAL, BaseColor.RED);
	    //  PdfFont subFont = PdfFontFactory.createFont(StandardFonts.COURIER);//new Font(Font.FontFamily.TIMES_ROMAN, 16,Font.BOLD);
	    //  PdfFont smallBold =PdfFontFactory.createFont(StandardFonts.COURIER);// new Font(Font.FontFamily.TIMES_ROMAN, 12,Font.BOLD);	 
	   // PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);	   
	 
	    
	    public static void CreatePdf()
	    {
	        try {
	        	
	       	PdfFont catFont =PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);// new Font(Font.FontFamily.TIMES_ROMAN, 18,Font.BOLD);
	 	    PdfFont redFont =PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);// new Font(Font.FontFamily.TIMES_ROMAN, 12,Font.NORMAL, BaseColor.RED);
	 	     PdfFont subFont = PdfFontFactory.createFont(StandardFonts.COURIER);//new Font(Font.FontFamily.TIMES_ROMAN, 16,Font.BOLD);
	 	    PdfFont smallBold =PdfFontFactory.createFont(StandardFonts.COURIER);// new Font(Font.FontFamily.TIMES_ROMAN, 12,Font.BOLD);	
	 	    
	        	//PdfDocument pdf = new PdfDocument(new PdfWriter(dest),new WriterProperties().addXmpMetadata()));
	        	PdfWriter writer = new  PdfWriter(FILE);
	        	PdfDocument pdf = new  PdfDocument(writer); 
	        	Document document = new Document(pdf);
	           // PdfWriter.getInstance(document, new FileOutputStream(FILE)); 	            
	           // document.open();
	            
	            PdfFont russian = PdfFontFactory.createFont("src/geovindu/resources/fonts/FreeSans.ttf", "CP1251", pdf);
	            
	            addMetaData(document);
	            addTitlePage(document);
	            addContent(document);
	            document.close();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	    }
	    // iText allows to add metadata to the PDF which can be viewed in your Adobe
	    // Reader
	    // under File -> Properties
	    private static void addMetaData(Document document) {
	    	
	    	addCustomMetadadata(document,"Title","My first PDF");
	    	addCustomMetadadata(document,"Subject","My first PDF");
	    	addCustomMetadadata(document,"Keywords","My first PDF");
	    	addCustomMetadadata(document,"Author","geovindu");
	    	addCustomMetadadata(document,"Creator","geovindu");
	       // document.addTitle("My first PDF");	  
	       // document.addSubject("Using iText");
	       // document.addKeywords("Java, PDF, iText");
	       // document.addAuthor("geovindu");
	       // document.addCreator("geovindu");
	    }
	 
	    private static void addTitlePage(Document document)
	            throws Exception {
	        Paragraph preface = new Paragraph();
	        
	        PdfFont catFont =PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);	    
	 	    PdfFont redFont =PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);// new Font(Font.FontFamily.TIMES_ROMAN, 12,Font.NORMAL, BaseColor.RED);
	 	     PdfFont subFont = PdfFontFactory.createFont(StandardFonts.COURIER);//new Font(Font.FontFamily.TIMES_ROMAN, 16,Font.BOLD);
	 	    PdfFont smallBold =PdfFontFactory.createFont(StandardFonts.COURIER);// new Font(Font.FontFamily.TIMES_ROMAN, 12,Font.BOLD);	
	        // We add one empty line
	        addEmptyLine(preface, 1);
	        // Lets write a big header
	        preface.add(new Paragraph("Title of the document").setFont(catFont));
	 
	        addEmptyLine(preface, 1);
	        // Will create: Report generated by: _name, _date
	        preface.add(new Paragraph(
	                "Report generated by: " + System.getProperty("user.name") + ", " + new Date() //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	               ).setFont(smallBold));
	        addEmptyLine(preface, 3);
	        preface.add(new Paragraph(
	                "This document describes something which is very important ").setFont(smallBold));
	 
	        addEmptyLine(preface, 8);
	 
	        preface.add(new Paragraph(
	                "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).").setFont(redFont));
	 
	        document.add(preface);
	        // Start a new page
	        //document.();
	    }
	 
	    private static void addContent(Document document) throws Exception {
	    	
	        PdfFont subFont = PdfFontFactory.createFont(StandardFonts.COURIER);//new Font(Font.FontFamily.TIMES_ROMAN, 16,Font.BOLD);
	       	PdfFont catFont =PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);// new Font(Font.FontFamily.TIMES_ROMAN, 18,Font.BOLD);
	        Anchor anchor = new Anchor("First Chapter", catFont);
	        anchor.setName("First Chapter");
	 

	 	
	
	        
	        
	        // Second parameter is the number of the chapter
	        Chapter catPart = new Chapter(new Paragraph(anchor), 1);
	 
	        Paragraph subPara = new Paragraph("Subcategory 1").setFont(subFont);
	        Section subCatPart = catPart.addSection(subPara);
	        subCatPart.add(new Paragraph("Hello"));
	 
	        subPara = new Paragraph("Subcategory 2").setFont(subFont);
	        subCatPart = catPart.addSection(subPara);
	        subCatPart.add(new Paragraph("Paragraph 1"));
	        subCatPart.add(new Paragraph("Paragraph 2"));
	        subCatPart.add(new Paragraph("Paragraph 3"));
	 
	        // add a list
	        createList(subCatPart);
	        Paragraph paragraph = new Paragraph();
	        addEmptyLine(paragraph, 5);
	        subCatPart.add(paragraph);
	 
	        // add a table
	        createTable(subCatPart);
	 
	        // now add all this to the document
	        document.add(catPart);
	 
	        // Next section
	        anchor = new Anchor("Second Chapter", subFont);
	        anchor.setName("Second Chapter");
	 
	        // Second parameter is the number of the chapter
	        catPart = new Chapter(new Paragraph(anchor), 1);
	 
	        subPara = new Paragraph("Subcategory").setFont(catFont);
	        subCatPart = catPart.addSection(subPara);
	        subCatPart.add(new Paragraph("This is a very important message"));
	 
	        // now add all this to the document
	        document.add(catPart);
	 
	    }
	    
	    public static void addMetadata(Document document,String title, String subject, String author, String creator) {
			PdfDocumentInfo documentInfo = document.getPdfDocument().getDocumentInfo();
			if (title!="") {
				documentInfo.setTitle(title);
			}
			if (subject!="") {
				documentInfo.setSubject(subject);
			}
			if (author!="") {
				documentInfo.setAuthor(author);
			}
			if (creator!="") {
				documentInfo.setCreator(creator);
			}
		}

	    
		public static void addCustomMetadadata(Document document, String key,  String value) {
			PdfDocumentInfo documentInfo = document.getPdfDocument().getDocumentInfo();
			documentInfo.setMoreInfo(key, value);
		}
		
		
		
	    private static void createTable(Document subCatPart)
	            throws Exception {
	    	
	    	 PdfFont headerFont = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
	         PdfFont cellFont = PdfFontFactory.createFont(StandardFonts.COURIER);
	        //Table table = new Table(3);
	 
	        // t.setBorderColor(BaseColor.GRAY);
	        // t.setPadding(4);
	        // t.setSpacing(4);
	        // t.setBorderWidth(1);
	 
	        Table table = new Table(new float[]{4, 4, 4});
	        table.setWidth(UnitValue.createPercentValue(100));
	        // adding header
	        table.addHeaderCell(new Cell().add(new Paragraph(
	                "First Name").setFont(headerFont)));
	        table.addHeaderCell(new Cell().add(new Paragraph(
	                "Last Name").setFont(headerFont)));
	        table.addHeaderCell(new Cell().add(new Paragraph(
	                "Email").setFont(headerFont)));
	        
	        
	        
	       /* Cell c1 = new Cell(new Phrase("Table Header 1"));
	        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
	        table.addCell(c1);
	 
	        c1 = new Cell(new Phrase("Table Header 2"));
	        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
	        table.addCell(c1);
	 
	        c1 = new Cell(new Phrase("Table Header 3"));
	        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
	        table.addCell(c1);
	        table.setHeaderRows(1);
	        */
	        table.addCell("1.0 geovindu");
	        table.addCell("1.1");
	        table.addCell("1.2");
	        table.addCell("2.1");
	        table.addCell("2.2");
	        table.addCell("2.3");
	 
	        subCatPart.add(table);
	 
	    }
	 
	    private static void createList(Document subCatPart) {
	    	com.itextpdf.layout.element.List list = new com.itextpdf.layout.element.List().setSymbolIndent(14);//(true, false, 10);
	        list.add(new ListItem("First point"));
	        list.add(new ListItem("Second point"));
	        list.add(new ListItem("Third point"));
	        subCatPart.add(list);
	    }
	 
	    private void createTablePDF(String PDFPath){
	        PdfWriter writer;
	        try {
	          writer = new PdfWriter(new FileOutputStream(PDFPath));
	          PdfDocument pdf = new PdfDocument(writer);
	          Document document = new Document(pdf, new PageSize(PageSize.A4));
	          PdfFont headerFont = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
	          PdfFont cellFont = PdfFontFactory.createFont(StandardFonts.COURIER);
	          // Create table with 3 columns of similar length
	          Table table = new Table(new float[]{4, 4, 4});
	          table.setWidth(UnitValue.createPercentValue(100));
	          // adding header
	          table.addHeaderCell(new Cell().add(new Paragraph(
	                  "First Name").setFont(headerFont)));
	          table.addHeaderCell(new Cell().add(new Paragraph(
	                  "Last Name").setFont(headerFont)));
	          table.addHeaderCell(new Cell().add(new Paragraph(
	                  "Email").setFont(headerFont)));
	          java.util.List<User> users = getListOfUsers();
	          // adding rows
	          for(User user : users) {
	            table.addCell(new Cell().add(new Paragraph(
	                 user.getFirstName()).setFont(cellFont)));
	            table.addCell(new Cell().add(new Paragraph(
	                 user.getLastName()).setFont(cellFont)));
	            table.addCell(new Cell().add(new Paragraph(
	                 user.getEmail()).setFont(cellFont)));
	          }
	          document.add(table);
	          document.close();
	        } catch (IOException e) {
	          // TODO Auto-generated catch block
	          e.printStackTrace();
	        }    
	      }
	    
	    // Dummy method for adding List of Users
	    private java.util.List<User> getListOfUsers() {
	    	java.util.List<User> users = new ArrayList<User>();
	      users.add(new User("Jack", "Reacher", "[email protected]"));
	      users.add(new User("Remington", "Steele", "[email protected]"));
	      users.add(new User("Jonathan", "Raven", "[email protected]"));
	      return users;
	    }
	    
	    
	    protected void manipulatePdf(String dest) throws Exception {
	        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
	        Document doc = new Document(pdfDoc);
	        Table table = new Table(3);
	        float tableWidth = doc.getPdfDocument().getDefaultPageSize().getWidth()
	                - (doc.getLeftMargin() + doc.getRightMargin());
	        table.setWidth(tableWidth);

	        Cell cell1 = new Cell();
	        Paragraph p = new Paragraph("1");
	        p.setProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
	        cell1.add(p);
	        table.addCell(cell1);

	        Cell cell2 = new Cell();
	        Paragraph p2 = new Paragraph("CamLane_Disp_Warn_Rq_Pr2_e0h2tjvjx5d9y5cbvxqsnhwa7");
	        p2.setProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
	        cell2.add(p2);
	        table.addCell(cell2);

	        Cell cell3 = new Cell();
	        Paragraph p3 = new Paragraph("CamLane_Disp_Warn_Rq_AR2");
	        p3.setProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
	        cell3.add(p3);
	        table.addCell(cell3);

	        Cell cell4 = new Cell();
	        Paragraph p4 = new Paragraph("SQC/CRC");
	        p4.setProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
	        cell4.add(p4);
	        table.addCell(cell4);

	        Cell cell5 = new Cell();
	        Paragraph p5 = new Paragraph("SPV_EngRq1_VAN_Pr2_vx0c4n6d46wgrav5gmco6bvc");
	        p5.setProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
	        cell5.add(p5);
	        table.addCell(cell5);

	        Cell cell6 = new Cell();
	        Paragraph p6 = new Paragraph("Bckl_Sw_Ft_Stat_Pr2_b14xqvpzjykdbhltdyma53upe");
	        p6.setProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
	        cell6.add(p6);
	        table.addCell(cell6);
	        doc.add(table);
	        doc.close();
	    }
	    
	    private static void addEmptyLine(Paragraph paragraph, int number) {
	        for (int i = 0; i < number; i++) {
	            paragraph.add(new Paragraph(" "));
	        }
	    }
	    
	    
	    private void addImageToPDF(String PDFPath){
	        PdfWriter writer;
	        try {
	          writer = new PdfWriter(new FileOutputStream(PDFPath));
	          PdfDocument pdfDoc = new PdfDocument(writer);
	          Document document = new Document(pdfDoc);
	          PageSize pageSize = new PageSize(PageSize.A4).rotate();
	       
	          PdfCanvas canvas = new PdfCanvas(pdfDoc.addNewPage());
	          // creating image data instance by passing the path to image
	          ImageData img = ImageDataFactory.create("resources//netjs.png");
	          canvas.saveState();
	          // graphic state
	          PdfExtGState state = new PdfExtGState();
	          state.setFillOpacity(0.2f);
	          canvas.setExtGState(state);
	          canvas.addImage(img, 20, 650, pageSize.getWidth()/2, false);
	          canvas.restoreState();
	          document.add(new Paragraph("Adding image to PDF Example"));      
	          document.close();
	        } catch (IOException e) {
	          // TODO Auto-generated catch block
	          e.printStackTrace();
	        } 
	      }
	    
	    
	    private void addImageToPDF(String PDFPath){
	        PdfWriter writer;
	        try {
	          // creating image data instance by passing the path to image
	        	String imFile="resources//netjs.png";
	        	ImageData data = https://www.cnblogs.com/geovindu/p/ImageDataFactory.create(imFile);
	         Image image = new image(data);
	          writer = new PdfWriter(new FileOutputStream(PDFPath));
	          PdfDocument pdfDoc = new PdfDocument(writer);
	          Document document = new Document(pdfDoc);       
	          document.add(new Paragraph("Adding image to PDF Example"));
	          document.add(image);      
	          document.close();
	        } catch (IOException e) {
	          // TODO Auto-generated catch block
	          e.printStackTrace();
	        } 
	      }
	    
	    private void addImageToPDF2(String PDFPath){
	        PdfWriter writer;
	        try {
	          writer = new PdfWriter(new FileOutputStream(PDFPath));
	          PdfDocument pdfDoc = new PdfDocument(writer);
	          Document document = new Document(pdfDoc);       
	          document.add(new Paragraph("Choices Are (Using English Letters)"));
	                // for offset (space from the left)
	          com.itextpdf.layout.element.List list = new com.itextpdf.layout.element.List().setSymbolIndent(14) 
	                                .setListSymbol(ListNumberingType.ENGLISH_LOWER);
	           
	          // Add ListItem objects
	          list.add(new ListItem("Aerobic"))
	              .add(new ListItem("Anaerobic"))
	              .add(new ListItem("Flexibility Training"));
	          // Add the list
	          document.add(list);
	          
	          document.add(new Paragraph("Choices Are (Using Roman upper)"));
	          list = new com.itextpdf.layout.element.List()
	               .setSymbolIndent(14)
	               .setListSymbol(ListNumberingType.ROMAN_UPPER);
	          // Add ListItem objects
	          list.add(new ListItem("Aerobic"))
	              .add(new ListItem("Anaerobic"))
	              .add(new ListItem("Flexibility Training"));
	          // Add the list
	          document.add(list);
	          
	          document.add(new Paragraph("Choices Are (Using bullet symbol)"));
	          list = new com.itextpdf.layout.element.List()
	               .setSymbolIndent(14) 
	               .setListSymbol("\u2022"); // Passing unicode for bullet
	          // Add ListItem objects
	          list.add(new ListItem("Aerobic"))
	              .add(new ListItem("Anaerobic"))
	              .add(new ListItem("Flexibility Training"));
	          // Add the list
	          document.add(list);            
	          document.close();         
	        } catch (IOException e) {
	          // TODO Auto-generated catch block
	          e.printStackTrace();
	        } 
	      }
	

}

  

 https://github.com/arnosthavelka/itext-poc/blob/develop/src/main/java/com/github/aha/poc/itext/DocumentBuilder.java

 

 

5.2.1

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.io.*;

import com.itextpdf.text.Image; 
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Header;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.TextField;
 
 
import com.itextpdf.text.Anchor;
import com.itextpdf.text.BadElementException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chapter;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Section;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.FontFactory;


/**
 * itextpdf 5.2.1
 * itext-asian-5.2.0
 * itext-rtf-2.1.7
 * @author geovindu
 * @version 1.0
 * 
 * 
 * 
 * */

public class iTextPdfHelper {
	
	
	 private static String FILE = "src/geovindu.pdf";
	 //中文字體
	 private static String path = "C:/WINDOWS/Fonts/STFANGSO.TTF";//windows里的字體資源路徑simhei.ttf
	 private static Font dufont = FontFactory.getFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED,10f, Font.NORMAL, BaseColor.BLACK);
	    private static Font catFont =FontFactory.getFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED,18f, Font.NORMAL, BaseColor.BLACK);// new Font(Font.FontFamily.TIMES_ROMAN, 18,Font.BOLD);
	    private static Font redFont =FontFactory.getFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED,12f, Font.NORMAL, BaseColor.BLACK);// new Font(Font.FontFamily.TIMES_ROMAN, 12,Font.NORMAL, BaseColor.RED);
	    private static Font subFont =FontFactory.getFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED,16f, Font.NORMAL, BaseColor.BLACK);// new Font(Font.FontFamily.TIMES_ROMAN, 16,Font.BOLD);
	    private static Font smallBold =FontFactory.getFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED,12f, Font.NORMAL, BaseColor.BLACK);// new Font(Font.FontFamily.TIMES_ROMAN, 12,Font.BOLD);
	 
	    public static void CreatePdf()
	    {
	        try {
	            Document document = new Document();
	            PdfWriter.getInstance(document, new FileOutputStream(FILE));
	            document.open();
	            addMetaData(document);
	            addTitlePage(document);
	            addContent(document);
	            document.close();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	    }
	    // iText allows to add metadata to the PDF which can be viewed in your Adobe
	    // Reader
	    // under File -> Properties
	    private static void addMetaData(Document document) {
	        document.addTitle("My first PDF");
	        document.addSubject("Using iText");
	        document.addKeywords("Java, PDF, iText");
	        document.addAuthor("geovindu");
	        document.addCreator("geovindu");
	    }
	 
	    private static void addTitlePage(Document document)
	            throws DocumentException {
	        Paragraph preface = new Paragraph();
	        // We add one empty line
	        addEmptyLine(preface, 1);
	        // Lets write a big header
	        preface.add(new Paragraph("Title of the document", catFont));
	 
	        addEmptyLine(preface, 1);
	        // Will create: Report generated by: _name, _date
	        preface.add(new Paragraph(
	                "Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	                smallBold));
	        addEmptyLine(preface, 3);
	        preface.add(new Paragraph("This document describes something which is very important ",smallBold));
	 
	        addEmptyLine(preface, 8);
	 
	        preface.add(new Paragraph(
	                "This document is a preliminary version and not涂聚文 subject to your license agreement or any other agreement with vogella.com ;-).",
	                redFont));
	 
	        document.add(preface);
	        // Start a new page
	        document.newPage();
	    }
	 
	    private static void addContent(Document document) throws DocumentException {
	        Anchor anchor = new Anchor("First Chapter", catFont);
	        anchor.setName("First Chapter");
	 
	        // Second parameter is the number of the chapter
	        Chapter catPart = new Chapter(new Paragraph(anchor), 1);
	 
	        Paragraph subPara = new Paragraph("Subcategory 1", subFont);
	        Section subCatPart = catPart.addSection(subPara);
	        subCatPart.add(new Paragraph("Hello"));
	 
	        subPara = new Paragraph("Subcategory 2", subFont);
	        subCatPart = catPart.addSection(subPara);
	        subCatPart.add(new Paragraph("Paragraph 1 涂聚文",subFont));
	        subCatPart.add(new Paragraph("Paragraph 2涂聚文涂聚文",subFont));
	        subCatPart.add(new Paragraph("Paragraph 3涂聚文",subFont));
	 
	        // add a list
	        createList(subCatPart);
	        Paragraph paragraph = new Paragraph();
	        addEmptyLine(paragraph, 5);
	        subCatPart.add(paragraph);
	 
	        // add a table
	        createTable(subCatPart);
	 
	        // now add all this to the document
	        document.add(catPart);
	 
	        // Next section
	        anchor = new Anchor("Second Chapter", catFont);
	        anchor.setName("Second Chapter");
	 
	        // Second parameter is the number of the chapter
	        catPart = new Chapter(new Paragraph(anchor), 1);
	 
	        subPara = new Paragraph("Subcategory", subFont);
	        subCatPart = catPart.addSection(subPara);
	        subCatPart.add(new Paragraph("This is a very important message",subFont));
	 
	        // now add all this to the document
	        document.add(catPart);
	 
	    }
	 
	    private static void createTable(Section subCatPart)
	            throws BadElementException {
	        PdfPTable table = new PdfPTable(3);
	 
	        // t.setBorderColor(BaseColor.GRAY);
	        // t.setPadding(4);
	        // t.setSpacing(4);
	        // t.setBorderWidth(1);
	        Phrase pp=new Phrase("Table Header油料作物  1",subFont);	        
	        PdfPCell c1 = new PdfPCell(pp);
	        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
	        table.addCell(c1);
	 
	        c1 = new PdfPCell(new Phrase("Table Header涂 2",subFont));
	        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
	        table.addCell(c1);
	 
	        c1 = new PdfPCell(new Phrase("Table Header 聚文3",subFont));
	        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
	        table.addCell(c1);
	        table.setHeaderRows(1);
	 
	        table.addCell(new Phrase("1.0涂聚文",subFont));
	        table.addCell(new Phrase("1.1涂聚文",subFont));
	        table.addCell(new Phrase("1.2涂聚文",subFont));
	        table.addCell(new Phrase("2.1塗聚文工團",subFont));
	        table.addCell(new Phrase("2.2涂聚文",subFont));
	        table.addCell(new Phrase("2.3",subFont));
	 
	        subCatPart.add(table);
	 
	    }
	 
	    private static void createList(Section subCatPart) {
	        List list = new List(true, false, 10);
	        list.add(new ListItem("First point"));
	        list.add(new ListItem("Second point"));
	        list.add(new ListItem("Third point"));
	        subCatPart.add(list);
	    }
	 
	    private static void addEmptyLine(Paragraph paragraph, int number) {
	        for (int i = 0; i < number; i++) {
	            paragraph.add(new Paragraph(" "));
	        }
	    }
	    
	    
	    
	    /**
	     * 生成pdf檔案
	     */
	    public void createPdf(Font font) throws FileNotFoundException, DocumentException {
	        
	        String path = "src/"+System.currentTimeMillis()+".pdf";
	        File file = new File(path);
	        file.getParentFile().mkdirs();
	        Document doc = new Document(PageSize.A4);
	        PdfWriter.getInstance(doc, new FileOutputStream(file));
	        doc.open();
	        doc.add(new Paragraph("字體測驗",font));
	        doc.close();
	    }
	    
	  
	    /**
	     * 使用windows系統下的字體,new Font方式
	     */
	    public void DusetFont() throws DocumentException, IOException {
	        String path = "C:/WINDOWS/Fonts/simhei.ttf";//windows里的字體資源路徑
	        BaseFont bf = BaseFont.createFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
	        Font font = new Font(bf, 10f, Font.NORMAL, BaseColor.BLACK);
	        createPdf(font);
	    }
	    
	   
	    /**
	     * 使用windows系統下的字體,FontFactory方式
	     */
	    public void DusetFont2() throws DocumentException, IOException {
	        String path = "C:/WINDOWS/Fonts/simhei.ttf";//windows里的字體資源路徑
	        Font font = FontFactory.getFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED,10f, Font.NORMAL, BaseColor.BLACK);
	        createPdf(font);
	    }
	    
	  
	    /**
	     * 使用自己查找的字體,FontFactory方式
	     */
	    public void DusetFont3() throws DocumentException, IOException {
	        String path = "src/main/resources/file/pdf/font/SIMYOU.TTF";//自己的字體資源路徑
	        Font font = FontFactory.getFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED,10f, Font.NORMAL, BaseColor.BLACK);
	        createPdf(font);
	    }
	    
	    
	    /**
	     * 使用iTextAsian.jar中的字體,FontFactory方式
	     */
	  
	    public void DusetFont4() throws DocumentException, IOException {
	        Font font = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED,10f, Font.NORMAL, BaseColor.BLACK);
	        createPdf(font);
	    }
	    
	    

}

  

 

哲學管理(學)人生, 文學藝術生活, 自動(計算機學)物理(學)作業, 生物(學)化學逆境, 歷史(學)測繪(學)時間, 經濟(學)數學金錢(理財), 心理(學)醫學情緒, 詩詞美容情感, 美學建筑(學)家園, 解構建構(分析)整合學習, 智商情商(IQ、EQ)運籌(學)成功.---Geovin Du(涂聚文)

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415898.html

標籤:Java

上一篇:在批處理檔案中運行powershell命令后更改了圖形CLI

下一篇:ThreadLocal

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more