一、直接导出成PDF
Java代码
1. import java.io.FileNotFoundException;
2. import java.io.FileOutputStream;
3.
4. import com.itextpdf.text.Document;
5. import com.itextpdf.text.DocumentException;
6. import com.itextpdf.text.Paragraph;
7. import com.itextpdf.text.pdf.PdfWriter;
8.
9. public class ItextProduce {
10.
11. public static void main(String[] args) {
12. Document doc = null;
13. try {
14. doc = new Document();
15. PdfWriter.getInstance(doc, new FileOutputStream("C:\\itext.pdf"));
16. doc.open();
17. doc.add(new Paragraph("Hello World"));
18. } catch (FileNotFoundException e) {
19. e.printStackTrace();
20. } catch