Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jwt.struts.action;
- import com.itextpdf.text.BaseColor;
- import com.itextpdf.text.Document;
- import com.itextpdf.text.Element;
- import com.itextpdf.text.Paragraph;
- import com.itextpdf.text.pdf.PdfPCell;
- import com.itextpdf.text.pdf.PdfPTable;
- import com.itextpdf.text.pdf.PdfWriter;
- import com.jwt.struts.dao.UserRegisterDAO;
- import com.jwt.struts.form.UserQueryForm;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.OutputStream;
- import java.sql.ResultSet;
- public class GeneratePDFaction {
- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response)
- throws Exception {
- HttpSession ses = request.getSession(true);
- UserQueryForm registerForm = (UserQueryForm) form;
- String userName = registerForm.getUserName();
- UserRegisterDAO dao = new UserRegisterDAO();
- ResultSet result = dao.consultarPorUsuario(userName);
- String firstName = result.getString(0);
- String lastName = result.getString(1);
- String uName = result.getString(2);
- String password = result.getString(3);
- String email = result.getString(4);
- String phone = result.getString(5);
- OutputStream file = new FileOutputStream(new File("C:\\PDF_Java4s.pdf"));;;;;
- Document document = new Document();
- PdfWriter.getInstance(document, file);
- PdfPTable table=new PdfPTable(3);
- PdfPCell cell = new PdfPCell (new Paragraph("Java4s.com"));
- cell.setColspan (3);
- cell.setHorizontalAlignment (Element.ALIGN_CENTER);
- cell.setPadding (10.0f);
- cell.setBackgroundColor (new BaseColor(140, 221, 8));
- table.addCell(cell);
- table.addCell("nombre");
- table.addCell("apellidos");
- table.addCell("nombre de usuario");
- table.addCell("contraseña");
- table.addCell("email");
- table.addCell("telefono");
- table.setSpacingBefore(30.0f);
- table.setSpacingAfter(30.0f);
- table.addCell(firstName);
- table.addCell(lastName);
- table.addCell(uName);
- table.addCell(password);
- table.addCell(email);
- table.addCell(phone);
- document.add(table);
- document.newPage();
- document.close();
- file.close();
- System.out.println("Pdf created successfully..");
- return mapping.findForward("success");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement