使用Itext写入pdf文件内容

╰+攻爆jí腚メ 2023-06-13 06:02 143阅读 0赞
  1. try {
  2. Document document = new Document(PageSize.A4, 50, 50, 50, 50);
  3. //temDir 文件路径,如c:/aa.pdf
  4. PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream(temDir));
  5. document.open();
  6. Anchor anchorTarget = new Anchor("First page of the document.");
  7. anchorTarget.setName("BackToTop");
  8. Paragraph paragraph1 = new Paragraph();
  9. paragraph1.setSpacingBefore(50);
  10. paragraph1.add(anchorTarget);
  11. document.add(paragraph1);
  12. document.add(new Paragraph("hello word!",
  13. FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new CMYKColor(0, 255, 0, 0))));
  14. writer.close();
  15. document.close();
  16. } catch (Exception e) {
  17. System.out.println(e);
  18. }

发表评论

表情:
评论列表 (有 0 条评论,143人围观)

还没有评论,来说两句吧...

相关阅读

    相关 itext生成pdf

    最近做一个结算项目,客户提出需要将结算出来的结果,批量的发给相应供应商进行价钱确认,确认完成后,再进行开票操作,最重要的是要把公司的公章用上。 就考虑了生成pdf的方式来实

    相关 Itext生成PDF文件

    最近做一个项目的报表,设计导出问题,要求pdf、excel、word。说实话一个字,烦。写个备忘录吧。。。虽然还是很烦 所需依赖:itext-asian-5.2.0.jar

    相关 itext 生成pdf

      iText是著名的开 放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库。通过iText不仅可以生成PDF或rtf的文档,而且可以将 XM