如何将文件生成为PDF?

时间:2014-07-31 03:28:27

标签: java sql-server servlets pdf

我想将简历生成为PDF。首先,通过获取用户的id来查看简历。下一步是将简历生成为PDF。

下面是servlet和SQLCommands.java的代码。我该怎么办?

的Servlet

package com.dls.csb.process.web.controller;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Blob;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dls.csb.utility.SQLOperations;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

@WebServlet("/generateresume.html")
public class GenerateResume extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int id = Integer.parseInt(request.getParameter("id"));
        Document dc = new Document();
        try {

            ResultSet rs = SQLOperations.viewResume(id);
            while (rs.next()) {

                   dc.open();
                   dc.add(new Paragraph(rs.getBlob("resume")));

                   dc.close();    


                              }

             }
            catch (DocumentException de) {
                de.printStackTrace();
            }
            catch (SQLException e) {

            e.printStackTrace();
            }


        }

   }

SQLCommands.java

package com.dls.csb.utility;

public interface SQLCommands {

String VIEW_RESUME ="select resume from account where id=?"
}

0 个答案:

没有答案