ITEXT document.addTitle("123")没有任何效果,没有标题
答案:2 悬赏:0 手机版
解决时间 2021-02-22 11:15
- 提问者网友:容嬷嬷拿针来
- 2021-02-22 07:22
ITEXT document.addTitle("123")没有任何效果,没有标题
最佳答案
- 五星知识达人网友:一把行者刀
- 2021-02-22 08:32
1 import java.io.FileOutputStream;
2
3 import com.lowagie.text.Document;
4 import com.lowagie.text.Font;
5 import com.lowagie.text.PageSize;
6 import com.lowagie.text.Paragraph;
7 import com.lowagie.text.pdf.BaseFont;
8 import com.lowagie.text.pdf.PdfWriter;
9
10 public class Formatter {
11
12 public static void main(String[] args) throws Exception {
13 Document document = new Document(PageSize.A4);
14 try {
15 System.out.print("Generating PDF");
16 PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
17 document.open();
18 //iText自带的中文字体
19 BaseFont bf1 = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
20 //自定义字体
21 BaseFont bf2 = BaseFont.createFont("wqy-zenhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
22 Font font = new Font(bf2, 12, Font.NORMAL);
23 Paragraph p = new Paragraph("测试abc中文123", font);
24 document.add(p);
25 System.out.println("Done.");
26 } finally {
27 document.close();
28 }
29 }
30
31 }
2
3 import com.lowagie.text.Document;
4 import com.lowagie.text.Font;
5 import com.lowagie.text.PageSize;
6 import com.lowagie.text.Paragraph;
7 import com.lowagie.text.pdf.BaseFont;
8 import com.lowagie.text.pdf.PdfWriter;
9
10 public class Formatter {
11
12 public static void main(String[] args) throws Exception {
13 Document document = new Document(PageSize.A4);
14 try {
15 System.out.print("Generating PDF");
16 PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
17 document.open();
18 //iText自带的中文字体
19 BaseFont bf1 = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
20 //自定义字体
21 BaseFont bf2 = BaseFont.createFont("wqy-zenhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
22 Font font = new Font(bf2, 12, Font.NORMAL);
23 Paragraph p = new Paragraph("测试abc中文123", font);
24 document.add(p);
25 System.out.println("Done.");
26 } finally {
27 document.close();
28 }
29 }
30
31 }
全部回答
- 1楼网友:白昼之月
- 2021-02-22 09:44
期待看到有用的回答!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯