| | |
| | | } |
| | | TrueTypeCollection ttc = new TrueTypeCollection(fontFile); |
| | | // 通过字体名称获取(如 "SimSun") |
| | | PDType0Font font = PDType0Font.load(document, ttc.getFontByName("SimSun"), true); |
| | | // PDType0Font font = PDType0Font.load(document, fontFile); |
| | | // PDType0Font font = PDType0Font.load(document, ttc.getFontByName("SimSun"), true); |
| | | PDType0Font font = PDType0Font.load(document, fontFile); |
| | | float fontSize = 10; |
| | | float margin = 50; |
| | | float leading = 1.2f * fontSize; // 行距 |
| | |
| | | try { |
| | | // 1. 从文本文件创建 PDF |
| | | // createPdfFromTextFile("E://新建1.txt", "E://新建1.pdf"); |
| | | createPdfWithCode("E:\\PROJECT\\Product\\后端\\product\\product-server\\product-server-file\\src\\main\\java\\com\\product\\file\\util\\FileUtil.java", "E://新建1.pdf"); |
| | | createPdfWithCode("C:\\Users\\shi\\Desktop\\产品\\code.txt", "E://新建1.pdf"); |
| | | |
| | | // 2. 读取 PDF 内容 |
| | | String content = readPdfContent("E://新建1.pdf"); |