List of usage examples for com.itextpdf.text Document addTitle
public boolean addTitle(String title)
From source file:Servlets.ReportsServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w ww . j a va2s . c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Paragraph pp; Paragraph palaglapgh, signParagraph, dateParagrapgh; Chunk chk; Paragraph underText; Chunk chuk1; Chunk chuk2; Paragraph regionText; String x; ResultSet dir; Paragraph regionTexts; String repLot; repLot = request.getParameter("report"); String repNum = request.getParameter("ITLot"); Paragraph newDate; response.setContentType("application/pdf"); OutputStream out = response.getOutputStream(); //Create document for pdf Document doc = new Document(); //PDF writer to write into document PdfWriter docwriter = null; DecimalFormat df = new DecimalFormat("0.00"); switch (repLot) { default: break; case "IT Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(20f, 20f, 10f, 10f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .25f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "TR Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); //doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); // 0.1 thickness and -2 position chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .1f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "RP Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFreplants(repNum); try { if (dir.next()) { x = dir.getString(22); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(RPreport(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "Rehab Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(5f, 5f, 3f, 3f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("Component 1 Rehabilitation Tree Removal Cost From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", bfBold12); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum, bfBold12); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFRehab(repNum);//SHOULD BE CHANGED!!!! try { if (dir.next()) { x = dir.getString(21); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); //Copied CODES break; } } catch (DocumentException ex) { Logger.getLogger(ReportsServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:sipl.recursos.GenerarPDFGrafica.java
private void addMetaData(Document document) { document.addTitle(Titulo); document.addSubject("Grfica"); document.addKeywords("Java, Grfica, PDF, iText"); document.addAuthor("Wilmar Gonzlez - Sandra Vera"); document.addCreator("SIPL"); }
From source file:sipl.recursos.GenerarPDFListar.java
private void addMetaData(Document document) { document.addTitle(Titulo); document.addSubject("Lista especfica"); document.addKeywords("Java, PDF, iText"); document.addAuthor("Wilmar Gonzlez - Sandra Vera"); document.addCreator("SIPL"); }
From source file:sipl.recursos.GenerarPDFtipomaterial.java
private static void addMetaData(Document document) { document.addTitle(Titulo); document.addSubject("Grfica"); document.addKeywords("Java, Grfica, PDF, iText"); document.addAuthor("Wilmar Gonzlez - Sandra Vera"); document.addCreator("SIPL"); }
From source file:sistemafacturacionlibros.PDFCreator.java
public void addMetaData(Document document) { document.addTitle("PDF Report"); document.addSubject("Using iText"); document.addKeywords("Java, PDF, iText"); document.addAuthor(System.getProperty("user.name")); document.addCreator(System.getProperty("user.name")); }
From source file:sqlsentinel.report.PDFGenerator.java
License:Open Source License
private static void addMetaData(Document document) { document.addTitle("SQLSentinel Report"); document.addSubject("site: " + url); document.addKeywords(""); document.addAuthor("SQLSentinel"); document.addCreator("SQLSentinel"); }
From source file:staff.cashier.CashierController.java
@FXML private void onClickGetPayment(ActionEvent e) throws SQLException, IOException, ClassNotFoundException, DocumentException, DecoderException { PendingBill currBill = cashierView.getSelectionModel().getSelectedItem(); System.out.println(currBill.getCusName() + " " + currBill.getOrderID() + " " + currBill.getBill()); int orderid = currBill.getOrderID(); int bill_status = 1; Statement st = conn.createStatement(); Statement st1 = conn.createStatement(); Statement st2 = conn.createStatement(); // set bill status 1 in order_info table. String query = "update order_info set bill_paid='" + bill_status + "' where order_id='" + currBill.getOrderID() + "'"; st.executeUpdate(query);//from w w w. ja va2 s .c om // set cus_id=0 in corrosponding table. String query1 = "select * from order_info where order_id='" + currBill.getOrderID() + "'"; ResultSet rs = st1.executeQuery(query1); rs.next(); BigInteger cus_id = new BigInteger(Long.toString(rs.getLong("c_id"))); BigInteger new_cid = BigInteger.ZERO; String query2 = "update table_info set c_id='" + new_cid + "',order_taken=0 where c_id='" + cus_id + "'"; st2.executeUpdate(query2); //deleting the row ObservableList<PendingBill> billSelected, allBill; allBill = cashierView.getItems(); allBill.remove((currBill)); //Inserting into `bill` schema int counter = 0; //fetching the bill_id of the last order query = "select * from bill"; rs = st.executeQuery(query); while (rs.next()) { counter = rs.getInt("bill_id"); } counter++; String query3 = "insert into bill values(" + counter + "," + currBill.bill + ")"; st.executeUpdate(query3); //Updating the bill_generation schema String query4 = "insert into bill_generation values(" + currBill.orderID + ",'" + caid + "'," + counter + ")"; st.executeUpdate(query4); //GENERATING THE BILL IN PDF FORM String query5 = "select * from order_info where order_id=" + orderid + " "; ResultSet rs1 = st.executeQuery(query5); rs1.next(); String itemList = rs1.getString("list"); int tis = rs1.getInt("table_id"); float cc = rs1.getFloat("cost"); //String itemDetails=rs1.getString("item_qty"); int coupon = rs1.getInt("coupon_id"); float disc_p = 0; //FETCHING THE DISCOUNT PERCENT CORRESPONDING TO THAT COUPON if (coupon != 0) { Statement st4 = conn.createStatement(); String q4 = "select discount_percent from coupon where coupon_id=" + coupon; ResultSet rs4 = st4.executeQuery(q4); rs4.next(); disc_p = rs4.getFloat("discount_percent"); } //FETCHING CUSTOMER NAME String query6 = "select * from customer where c_id=" + cus_id + ""; ResultSet rs2 = st.executeQuery(query6); rs2.next(); String cusname = rs2.getString("c_name"); String email = rs2.getString("c_email"); String itemsInfo = ""; /*----------------DESERIALIZATION ByteArrayInputStream in = new ByteArrayInputStream(Hex.decodeHex(itemList.toCharArray())); String[] aa= (String[]) (new ObjectInputStream(in).readObject()); //System.out.println(Arrays.toString(); try{ for (String aa1 : aa) { if(aa1!=null){ int i; String tmp=""; for( i=0;i<(aa1.length()-1);i++) { tmp+=aa1.charAt(i); } int qty=Integer.parseInt(""+aa1.charAt(i)); itemsInfo+="Item name: "+tmp+" Qty:"+qty+"\n\n"; } } } catch(Exception ee){} -----------------------------------------*/ //EXTRACTING INFORMATION ABOUT ORDERED ITEMS String tmp = ""; for (int i = 0; i < (itemList.length() - 1); i++) { if (itemList.charAt(i + 1) == '-') { int qty = Integer.parseInt("" + itemList.charAt(i)); Statement st3 = conn.createStatement(); String q3 = "Select price from menu where d_name='" + tmp + "'"; ResultSet rs3 = st3.executeQuery(q3); rs3.next(); float p = rs3.getFloat("price"); itemsInfo += "Item name:" + tmp + " Qty:" + qty + " Price:+" + p + " Total:" + (qty * p) + "\n\n"; tmp = ""; i++; } else tmp += itemList.charAt(i); } itemsInfo += "Total Cost :" + cc + "\n\n"; if (coupon != 0) { float tprice = cc - ((disc_p * cc) / 100); itemsInfo += "You have been given a discount of " + disc_p + "%\n\nFinal Cost : Rs." + tprice + "\n\n"; } System.out.println("Item info:" + itemsInfo); //WRITING TO PDF Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("Order" + orderid + ".pdf")); doc.open(); doc.addTitle("CENTRICO RESTAURANT"); doc.addCreationDate(); doc.addSubject("BILL"); //System.out.println(itemDetails); doc.add(new Paragraph(" CENTRICO RESTAURANT\n\nORDER ID : " + orderid + "\n\nTABLE ID : " + tis + "\n\nCUSTOMER NAME : " + cusname + "\n\nEMAIL ID : " + email + "\n\n" + itemsInfo + "\n\n")); doc.close(); writer.close(); //SENDING THE BILL IN MAIL TO THE CUSTOMER GmailQuickstart a = new GmailQuickstart(); a.setCusemail(email); a.setCusmessage("Thankyou so much " + cusname + " for coming here.Please visit us again :) \n Please find your bill attached below\n"); a.setCussubject("Bill for order number " + orderid); a.setFileName("Order" + orderid + ".pdf"); Thread t = new Thread(a); t.start(); //alert Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Information dialog"); alert.setHeaderText(null); alert.setContentText(" Payment has Received Successfully"); alert.showAndWait(); }
From source file:SystemOperations.PdfGen.java
private static void addMetaData(Document document, String title) { document.addTitle("My first PDF"); document.addAuthor("Super Rent"); document.addCreator("Super Rent"); }
From source file:tn.com.hitechart.eds.Util.pdfRpport.FirstPdf.java
private void addMetaData(Document document) { document.addTitle("My first PDF"); document.addSubject("Using iText"); document.addKeywords("Java, PDF, iText"); document.addAuthor("AHMED BEJ"); document.addCreator("AHMED BEJ"); }
From source file:tn.esprit.twin1.brogrammers.eventify.Eventify.util.TicketGenerator.java
public static void GenerateTicket(Ticket ticket) { Document document = new Document(); try {//from w w w. j a va 2 s .co m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE)); Rectangle pagesize = new Rectangle(700, 300); document.open(); Paragraph emptyline = new Paragraph(); emptyline.add(new Paragraph(" ")); document.setPageSize(pagesize); document.newPage(); //PIC PdfContentByte canvas = writer.getDirectContentUnder(); Image image = Image.getInstance(IMAGE); //image.scaleAbsolute(pagesize.rotate()); image.setAbsolutePosition(0, 0); canvas.addImage(image); //PIC document.addTitle("Your Access To" + ticket.getEvent().getTitle()); document.addSubject(ticket.getEvent().getTheme()); document.addKeywords(ticket.getEvent().getTitle() + "Ticket"); document.addAuthor("Mohamed Firas Ouertani"); document.addCreator("Mohamed Firas Ouertani"); Paragraph prefacetitle = new Paragraph(); prefacetitle.add(new Paragraph("Your Ticket For " + ticket.getEvent().getTitle(), bigFont)); document.add(prefacetitle); document.add(emptyline); Paragraph prefacetime = new Paragraph(); prefacetime.add(new Paragraph(ticket.getEvent().getStartTime().toString(), greyFont)); document.add(prefacetime); document.add(emptyline); document.add(emptyline); Paragraph prefacetype = new Paragraph(); prefacetype.add(new Paragraph("You Reserved For: " + ticket.getTypeTicket(), catFont)); document.add(prefacetype); //QR BarcodeQRCode qrcode = new BarcodeQRCode( "REF:#" + ticket.getEvent().getId() + "" + ticket.getEvent().getTitle().trim(), 1, 1, null); Image qrcodeImage = qrcode.getImage(); qrcodeImage.setAbsolutePosition(520, 70); qrcodeImage.scalePercent(400); document.add(qrcodeImage); //QR //Bar PdfContentByte cb = writer.getDirectContent(); Barcode128 code128 = new Barcode128(); BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCode("REF:#" + ticket.getEvent().getId() + "" + ticket.getEvent().getTitle().trim()); codeEAN.setCodeType(BarcodeEAN.EAN13); Image codeEANImage = code128.createImageWithBarcode(cb, null, null); codeEANImage.setAbsolutePosition(10, 10); codeEANImage.scalePercent(125); document.add(codeEANImage); //Bar document.close(); } catch (Exception e) { e.printStackTrace(); } }