我是靠谱客的博主 昏睡手机,这篇文章主要介绍使用ITXT生成PDF文件学习,现在分享给大家,希望可以做个参考。

今天想生成一个PDF文件,带中文的,从网络上找了好多资料,最中中文还是有问题,最后参照官方的文档才将这个给解决了,

代码 :

 response.setContentType("application/pdf");
  String filename="card"+Datetime.Time_Article()+".pdf";
  Document document=new Document(PageSize.A4);
  BaseFont bfChinese = BaseFont.createFont("c://winnt//fonts//msgothic.ttc,0",BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
  Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);
  //ServletOutputStream yeout=response.getOutputStream();
  try{
    PdfWriter.getInstance(document,new FileOutputStream("D://Java//tomcat5.5//webapps//card//cardpdf//"+filename));
   // PdfWriter.getInstance(document,new FileOutputStream("//"+filename));
     String[][] yemzi=(String[][])session.getAttribute("yemzi");
     //document.
     String cardmoney=(String)session.getAttribute("cardmoney");
     int number=Integer.parseInt((String)session.getAttribute("number"));
     document.open();
     Table td=new Table(3);
     td.setBorder(1);
     td.setBorderColor(new Color(255,255,255));
     td.setPadding(2);
     td.setSpacing(2);
     Cell yecell=new Cell();
     //String str=new String("?????".getBytes("ISO-8859-1"),"GB2312");
     document.add(new Paragraph("/u5361/u53f7/u548c/u5bc6/u7801/u5217/u8868",FontChinese));
     yecell=new Cell(new Paragraph("/u5361/u53f7",FontChinese));
     yecell.setHorizontalAlignment("center");
     td.addCell(yecell);
     yecell=new Cell(new Paragraph("/u5bc6/u7801",FontChinese));
     yecell.setHorizontalAlignment("center");
     td.addCell(yecell);
     yecell=new Cell(new Paragraph("/u91d1/u989d",FontChinese));
     yecell.setHorizontalAlignment("center");
     td.addCell(yecell);
     for(int i=0;i<number;i++)
     {
       yecell=new Cell(yemzi[i][0]);
       yecell.setHorizontalAlignment("center");
       td.addCell(yecell);
       yecell=new Cell(yemzi[i][1]);
       yecell.setHorizontalAlignment("center");
       td.addCell(yecell);
       yecell=new Cell(cardmoney);
       yecell.setHorizontalAlignment("center");
       td.addCell(yecell);
     }
     document.add(td);
     document.close();
  }catch(FileNotFoundException  ex)
  {
    ex.printStackTrace();
    out.println("??PDF??????"+ex.getMessage());
  }catch(DocumentException ye)
  {
    ye.printStackTrace();
    out.println("??PDF??????1"+ye.getMessage());
  }

最后

以上就是昏睡手机最近收集整理的关于使用ITXT生成PDF文件学习的全部内容,更多相关使用ITXT生成PDF文件学习内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部