public void beginDraw() { // long t0 = System.currentTimeMillis(); if (document == null) { document = new Document(new Rectangle(width, height)); try { if (file != null) { // BufferedOutputStream output = new BufferedOutputStream(stream, 16384); output = new BufferedOutputStream(new FileOutputStream(file), 16384); } else if (output == null) { throw new RuntimeException( "PGraphicsPDF requires a path " + "for the location of the output file."); } writer = PdfWriter.getInstance(document, output); document.open(); content = writer.getDirectContent(); // template = content.createTemplate(width, height); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Problem saving the PDF file."); } // System.out.println("beginDraw fonts " + (System.currentTimeMillis() - t)); g2 = content.createGraphics(width, height, getMapper()); // g2 = template.createGraphics(width, height, mapper); } // System.out.println("beginDraw " + (System.currentTimeMillis() - t0)); super.beginDraw(); }
public void pv() { try { Document document = new Document(PageSize.A4, 36, 72, 108, 180); PdfWriter.getInstance(document, new FileOutputStream("pdfFile.pdf")); File f = new File("abc.txt"); FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); String i; while ((i = br.readLine()) != null) { document.open(); document.add(new Paragraph(i)); } System.out.println("fetched database is inserted into pdf file"); document.close(); } catch (Exception e) { } }
protected int writePdf(PdfWriter w, boolean spacing) throws IOException { DataOutputStream dos = w.getDataOutputStream(); int count = 2; // for [ and ] dos.write('['); boolean first = true; for (Iterator p = _a.iterator(); p.hasNext(); ) { PdfObject obj = (PdfObject) p.next(); if (first) { count += obj.writePdf(w, false); first = false; } else { count += obj.writePdf(w, true); } } dos.write(']'); return count; }
public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { regService = new RegService(); nuser = (RegForm) form; nuser = regService.authenticate(nuser); String uname = nuser.getUserName(); String pwd = nuser.getFpassword(); String cpwd = nuser.getCpassword(); String acc = nuser.getAccno(); String fn = nuser.getFirstName(); String ln = nuser.getLastName(); String sx = nuser.getSex(); String add = nuser.getAddress(); String co = nuser.getCountry(); String zp = nuser.getZip(); String mb = nuser.getMobile(); String em = nuser.getEmail(); RegForm regForm = (RegForm) form; Rectangle pageSize = new Rectangle(400, 400); pageSize.setBackgroundColor(new java.awt.Color(0xDF, 0xFF, 0xDE)); Document document = new Document(pageSize); PdfWriter.getInstance( document, new FileOutputStream("D:/kowthal training/java/31rep/Report.pdf")); document.open(); PdfPTable table = new PdfPTable(2); table.addCell("UserName"); table.addCell(uname); table.addCell("Password"); table.addCell(pwd); table.addCell("Confirm Password"); table.addCell(cpwd); table.addCell("First Name"); table.addCell(fn); table.addCell("Last Name"); table.addCell(ln); table.addCell("Sex"); table.addCell(sx); table.addCell("Address"); table.addCell(add); table.addCell("Country"); table.addCell(co); table.addCell("Zip Code"); table.addCell(zp); table.addCell("Mobile"); table.addCell(mb); table.addCell("E-mail id"); table.addCell(em); System.out.println("before fetch"); document.add(table); System.out.println("after fetch"); document.add(new Paragraph("Created by Kowthal(947)")); document.close(); target = "success"; return mapping.findForward(target); }