zoukankan      html  css  js  c++  java
  • 预览PDF

    1.

    web.xml


    <servlet>
    <servlet-name>FundPaymentServlet</servlet-name>
    <servlet-class>com.dnion.dayu.jasper.FundPaymentServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>FundPaymentServlet</servlet-name>
    <url-pattern>/fundpayment</url-pattern>
    </servlet-mapping>

    2.

    按钮触发时执行的代码:

    String url = "/fundpayment";

    Executions.getCurrent().sendRedirect(url, "_blank");

    3.

    FundPaymentServlet.java

    public class FundPaymentServlet extends HttpServlet{

    public void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {

    Rectangle rect = new Rectangle(800,600); 

    Document document = new Document(rect); 

    response.setContentType("application/pdf"); 

     PdfWriter.getInstance(document, response.getOutputStream());

    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

    com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese, 8, com.lowagie.text.Font.NORMAL);

    Modules module = new Modules(FontChinese);​

    HeaderFooter footer = new HeaderFooter(new Paragraph("表单编号:Dnion 4-114   版本1.0", FontChinese), false);

    footer.setBorder(Rectangle.NO_BORDER);

    footer.setAlignment(Element.ALIGN_RIGHT);

    document.setFooter( footer);

    document.open();

    //标题栏

    document.add(module.getTitle( request , term.getContract(),title,FontChinese,"客户信息"));

  • 相关阅读:
    Python
    Django
    Markdown基础教程
    LR之Oracle 2tier协议录制Oracle脚本
    Python实现自动连接密码本破解wifi
    LoadRunner替换url字符串(可以同时替换多个)
    LoadRunner接口HTTP请求中中文乱码解决方案
    在WSL2中安装ArchLinux
    解决FastJson中"$ref重复引用"的问题方法
    java 后台通过IO流把文件传到前端并下载
  • 原文地址:https://www.cnblogs.com/kisstear/p/4789110.html
Copyright © 2011-2022 走看看