\u4e2d\u6587<\/strong><\/div>\niText \u4e0d\u652f\u6301\u9ed8\u8ba4\u662f\u4e0d\u652f\u6301\u4e2d\u6587\u5b57\u4f53\u7684\uff0c\u6240\u4ee5\u9700\u8981\u5b9a\u4e49 PdfFont \u4e2d\u6587\u5b57\u4f53\u6837\u5f0f\u3002\u4f7f\u7528 PdfFontFactory \u7684 createFont \u521b\u5efa\u4e00\u4e2a\u4e2d\u6587\u5b57\u4f53\uff0c\u5e76\u5c06\u4e2d\u6587\u5b57\u4f53\u8bbe\u7f6e\u5230 document \u4e2d\u3002<\/p>\n
\r\npublic static void main(String[] args) { \r\n try{ \r\n PdfWriter pdfWriter = new PdfWriter(\".\/demo1.pdf\"); \r\n PdfDocument pdfDocument = new PdfDocument(pdfWriter); \r\n \/\/\u5b57\u4f53\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528 windows \u7cfb\u7edf\u4e2d\u7684 \r\n PdfFont font = PdfFontFactory.createFont(\"E:\\\\pdfProject\\\\src\\\\main\\\\java\\\\simhei.ttf\"); \r\n Document document = new Document(pdfDocument).setFont(font); \r\n document.add(new Paragraph(\"Hello World!\u4f60\u597d,itext\")); \r\n document.close(); \r\n }catch(Exception e){ \r\n e.printStackTrace(); \r\n } \r\n} <\/pre>\n\u793a\u4f8b\u7ed3\u679c\uff1a
\n<\/p>\n
\u8868\u683c<\/strong><\/div>\n\u5728\u9879\u76ee\u4e2d\u7ecf\u5e38\u9700\u8981 PDF \u6587\u4ef6\u4e2d\u6253\u5370\u8868\u683c\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u4f7f\u7528 Table \u5bf9\u8c61\uff0c\u521b\u5efa\u4e00\u4e2a\u4e2a\u5355\u5143\u683c\u5e76\u5c06\u8868\u683c\u5185\u5bb9\u5199\u5165\u5355\u5143\u683c\u4e2d\u3002<\/p>\n
\r\npublic static void main(String[] args) { \r\n try{ \r\n PdfWriter pdfWriter = new PdfWriter(\".\/demo2.pdf\"); \r\n PdfDocument pdfDocument = new PdfDocument(pdfWriter); \r\n PdfFont font = PdfFontFactory.createFont(\"E:\\\\pdfProject\\\\src\\\\main\\\\java\\\\simhei.ttf\"); \r\n Document document = new Document(pdfDocument).setFont(font); \r\n Table table = new Table(4); \r\n table.setWidth(500); \r\n table.addHeaderCell(\"header 1\").addHeaderCell(\"header 2\").addHeaderCell(\"header 3\").addHeaderCell(\"header 4\"); \r\n for(int i = 0; i < 16; i++) { \r\n table.addCell(\"cell \" + i); \r\n } \r\n document.add(table); \r\n \r\n document.close(); \r\n }catch(Exception e){ \r\n e.printStackTrace(); \r\n } \r\n} <\/pre>\n\u793a\u4f8b\u7ed3\u679c\uff1a
\n<\/p>\n
\u56fe\u7247<\/strong><\/div>\n\u56fe\u7247\u7684\u8bbe\u7f6e\u4e5f\u5f88\u7b80\u5355\uff0c\u521b\u5efa Image \u5bf9\u8c61\u586b\u5145\u5230 document \u4e2d\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n
\r\npublic static void main(String[] args) { \r\n try{ \r\n PdfWriter pdfWriter = new PdfWriter(\".\/demo3.pdf\"); \r\n PdfDocument pdfDocument = new PdfDocument(pdfWriter); \r\n PdfFont font = PdfFontFactory.createFont(\"E:\\\\pdfProject\\\\src\\\\main\\\\java\\\\simhei.ttf\"); \r\n Document document = new Document(pdfDocument).setFont(font); \r\n Image img = new Image(ImageDataFactory.create(\"E:\\\\pdfProject\\\\src\\\\main\\\\java\\\\img.png\")); \r\n document.add(img.setAutoScale(true)); \r\n \r\n document.close(); \r\n }catch(Exception e){ \r\n e.printStackTrace(); \r\n } \r\n}<\/pre>\n\u793a\u4f8b\u7ed3\u679c\uff1a
\n<\/p>\n
\u603b\u7ed3<\/strong><\/div>\n\u672c\u6587\u4ece iText \u6700\u57fa\u672c\u7684\u7528\u6cd5\uff0c\u5206\u522b\u4ecb\u7ecd\u4ece\u8868\u683c,\u56fe\u7247\uff0c\u4e2d\u6587\u6765\u4ecb\u7ecd iText\uff0c\u5e0c\u671b\u80fd\u591f\u5e2e\u52a9\u5230\u4f60\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u4f7f\u7528 iText \u7684\u65f6\u5019\u9700\u8981\u7528 maven \u4f9d\u8d56\u5982\u4e0b\uff1a <dependency> <grou […]<\/p>\n","protected":false},"author":1329,"featured_media":231830,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-231823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/231823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=231823"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/231823\/revisions"}],"predecessor-version":[{"id":231833,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/231823\/revisions\/231833"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/231830"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=231823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=231823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=231823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}