使用itextpdf操作pdf的實例講解
更新時間:2018年01月03日 14:24:59 作者:悠閑咖啡007
下面小編就為大家分享一篇使用itextpdf操作pdf的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
使用maven引入jar
<dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> <version>5.2.0</version> </dependency> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itext-asian</artifactId> <version>5.2.0</version> </dependency>
創(chuàng)建exportToPDF工具類
package com.os.core.util.file.exportPdf;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.FontSelector;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
/**
* Created by PengSongHe on 2016/10/20 0020.
*/
public class exportToPDF {
public static void main(String[] args) {
try {
Document document = new Document();//默認A4
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("d:/HelloWorld.pdf"));
writer.setPdfVersion(PdfWriter.PDF_VERSION_1_7);
document.addCreationDate();
document.addCreator("飛翔家族");
document.addTitle("export pdf");
document.addKeywords("export");
document.addSubject("飛翔家族 export pdf");
document.open();
//處理中文,需要itextasian.jar支持
FontSelector selector = new FontSelector();
selector.addFont(FontFactory.getFont(FontFactory.TIMES_ROMAN, 12));
selector.addFont(FontFactory.getFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED));
Phrase phrase = selector.process("HelloWord!你好。\u4fdd\u5b58");
document.add(new Paragraph(phrase));
//添加新頁
//document.newPage();
//writer.setPageEmpty(false);
//document.add(new Paragraph("New page"));
document.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
以上這篇使用itextpdf操作pdf的實例講解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
MybatisPlus更新為null的字段及自定義sql注入
mybatis-plus在執(zhí)行更新操作,當更新字段為空字符串或者null的則不會執(zhí)行更新,本文主要介紹了MybatisPlus更新為null的字段及自定義sql注入,感興趣的可以了解一下2024-05-05
Activiti進階之組任務(wù)實現(xiàn)示例詳解
這篇文章主要為大家介紹了Activiti進階之組任務(wù)實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-08-08
SpringBoot開發(fā)技巧啟動時配置校驗實現(xiàn)示例
這篇文章主要為大家介紹了SpringBoot開發(fā)在啟動時自動配置校驗的實現(xiàn)示例及原理解析,有需要的朋友可以借鑒參考下希望能夠有所幫助2021-10-10
IntelliJ IDEA2019實現(xiàn)Web項目創(chuàng)建示例
這篇文章主要介紹了IntelliJ IDEA2019實現(xiàn)Web項目創(chuàng)建示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-04-04
關(guān)于MyBatis plus條件構(gòu)造器的逐條詳解
什么是條件構(gòu)造器呢?簡單來說,條件構(gòu)造器就是用來生成我們查數(shù)據(jù)庫的sql。它可以簡化sql代碼的編寫,靈活、方便且易于維護2021-09-09
Mybatis(ParameterType)傳遞多個不同類型的參數(shù)方式
這篇文章主要介紹了Mybatis(ParameterType)傳遞多個不同類型的參數(shù)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04

