List of usage examples for com.itextpdf.text Font Font
public Font(final FontFamily family, final float size, final int style)
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * Default ?(RED)//from w w w . ja va2s .c o m * * @param text text * @param style Font style * @return Paragraph */ public static Paragraph getDefaultRed(String text, int style) { Font font = new Font(bfKorean, 10, style); font.setColor(new BaseColor(255, 0, 0)); Paragraph ph = new Paragraph(text, font); ph.setMultipliedLeading(1.8F); ph.setIndentationLeft(45); ph.setSpacingAfter(14); return ph; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
public String gerarPdfDaVenda(Venda v, List<ItemDeVenda> itens, File destino) throws IOException { Document doc = new Document(); try {//from w ww .j ava 2 s.c o m String path = a.getRelatorio().getCanonicalPath() + "/Venda_" + v.getId() + ".pdf"; PdfWriter.getInstance(doc, new FileOutputStream(path)); doc.open(); String subTitulo = "Venda Realizada no dia " + new SimpleDateFormat("dd/MM/yyyy HH:mm").format(v.getDia().getTime()); try { inserirHead(doc, "Venda do Cliente " + v.getCliente().getNome(), subTitulo); } catch (NullPointerException ne) { inserirHead(doc, "Venda vista ID: " + v.getId(), subTitulo); } PdfPTable table = getTableDeItens(itens); doc.add(table); Paragraph p2 = new Paragraph("Total: " + new DecimalFormat("0.00").format(v.getTotal()) + " \n Funcionrio: " + v.getFuncionario().getNome(), new Font(Font.FontFamily.COURIER, 16, Font.BOLD)); doc.add(p2); doc.close(); Arquivo.copyFile(new File(path), destino); return destino.getAbsolutePath(); } catch (DocumentException e) { e.printStackTrace(); return ""; } }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
public String gerarPdfDaVenda(Venda v, List<ItemDeVenda> itens) { Document doc = new Document(); try {//w ww . j a va2 s . co m String path = a.getRelatorio().getCanonicalPath() + "/Venda_" + v.getId() + ".pdf"; PdfWriter.getInstance(doc, new FileOutputStream(path)); doc.open(); String subTitulo = "Venda Realizada no dia " + new SimpleDateFormat("dd/MM/yyyy HH:mm").format(v.getDia().getTime()); if (v.getCliente() != null) { inserirHead(doc, "Venda do Cliente " + v.getCliente().getNome(), subTitulo); } else {//venda a vista inserirHead(doc, "Venda Vista", subTitulo); } PdfPTable table = getTableDeItens(itens); doc.add(table); Paragraph p2 = new Paragraph("Total: " + new DecimalFormat("0.00").format(v.getTotal()) + " \n Funcionrio: " + v.getFuncionario().getNome(), new Font(Font.FontFamily.COURIER, 16, Font.BOLD)); doc.add(p2); doc.close(); return path; } catch (DocumentException | IOException e) { e.printStackTrace(); return ""; } }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
public void inserirHead(Document doc, String titulo, String subTitulo) throws MalformedURLException, DocumentException { Image img = null;//from ww w . jav a 2s . co m try { img = Image.getInstance(IMG.class.getResource("logo_relatorio.png")); img.setAlignment(Element.ALIGN_LEFT); doc.add(img); } catch (IOException e) { e.printStackTrace(); } Font f = new Font(Font.FontFamily.COURIER, 20, Font.BOLD); Paragraph p = new Paragraph(titulo, f); Paragraph p2 = new Paragraph(subTitulo, new Font(Font.FontFamily.COURIER, 16, Font.BOLD)); p.setAlignment(Element.ALIGN_CENTER); doc.add(p); doc.add(p2); }
From source file:com.dexter.fms.mbean.ReportsMBean.java
@SuppressWarnings("unchecked") public void createPDF(int type, String filename, int pageType) { try {//from w w w . ja v a 2 s. c o m FacesContext context = FacesContext.getCurrentInstance(); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new HeaderFooter()); writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788)); if (!document.isOpen()) { document.open(); } switch (pageType) { case 1: document.setPageSize(PageSize.A4); break; case 2: document.setPageSize(PageSize.A4.rotate()); break; } document.addAuthor("FMS"); document.addCreationDate(); document.addCreator("FMS"); document.addSubject("Report"); document.addTitle(getReport_title()); PdfPTable headerTable = new PdfPTable(1); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "satraklogo.jpg"; Hashtable<String, Object> params = new Hashtable<String, Object>(); params.put("partner", dashBean.getUser().getPartner()); GeneralDAO gDAO = new GeneralDAO(); Object pSettingsObj = gDAO.search("PartnerSetting", params); PartnerSetting setting = null; if (pSettingsObj != null) { Vector<PartnerSetting> pSettingsList = (Vector<PartnerSetting>) pSettingsObj; for (PartnerSetting e : pSettingsList) { setting = e; } } gDAO.destroy(); PdfPCell c = null; if (setting != null && setting.getLogo() != null) { Image logoImg = Image.getInstance(setting.getLogo()); logoImg.scaleToFit(212, 51); c = new PdfPCell(logoImg); } else c = new PdfPCell(Image.getInstance(logo)); c.setBorder(0); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); Paragraph stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { //font exception } Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph(getReport_title(), font)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); if (getReport_start_dt() != null && getReport_end_dt() != null) { stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(10); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); new Font(helvetica, 12, Font.NORMAL); Paragraph ch = new Paragraph("From " + getReport_start_dt() + " to " + getReport_end_dt(), font); c = new PdfPCell(ch); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); } stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); document.add(headerTable); PdfPTable pdfTable = exportPDFTable(type); if (pdfTable != null) document.add(pdfTable); //Keep modifying your pdf file (add pages and more) document.close(); String fileName = filename + ".pdf"; writeFileToResponse(context.getExternalContext(), baos, fileName, "application/pdf"); context.responseComplete(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.dexter.fms.mbean.ReportsMBean.java
@SuppressWarnings("deprecation") private PdfPTable exportPDFTable(int type) { int numberOfColumns = 0; PdfPTable pdfTable = null;//from w ww. j a va 2 s. co m switch (type) { case 1: // all users report { numberOfColumns = 7; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("User name", font)); pdfTable.addCell(new Paragraph("Full name", font)); pdfTable.addCell(new Paragraph("Email", font)); pdfTable.addCell(new Paragraph("Department", font)); pdfTable.addCell(new Paragraph("Region", font)); pdfTable.addCell(new Paragraph("Phone", font)); pdfTable.addCell(new Paragraph("Position", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getAllUsers() != null) { for (PartnerUser e : getAllUsers()) { pdfTable.addCell(new Paragraph(e.getUsername(), font)); pdfTable.addCell(new Paragraph( e.getPersonel().getFirstname() + " " + e.getPersonel().getLastname(), font)); pdfTable.addCell(new Paragraph(e.getPersonel().getEmail(), font)); pdfTable.addCell(new Paragraph( (e.getPersonel().getDepartment() != null) ? e.getPersonel().getDepartment().getName() : "N/A", font)); pdfTable.addCell(new Paragraph( (e.getPersonel().getRegion() != null) ? e.getPersonel().getRegion().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getPersonel().getPhone(), font)); pdfTable.addCell(new Paragraph(e.getPersonel().getPosition(), font)); } } break; } case 2: // due driver's license { numberOfColumns = 6; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Full Name", font)); pdfTable.addCell(new Paragraph("Dept", font)); pdfTable.addCell(new Paragraph("Region", font)); pdfTable.addCell(new Paragraph("Phone", font)); pdfTable.addCell(new Paragraph("Position", font)); pdfTable.addCell(new Paragraph("License Due Date", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getDueDriversLic() != null) { for (DriverLicense e : getDueDriversLic()) { pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getFirstname() + " " + e.getDriver().getPersonel().getLastname(), font)); pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getDepartment() != null ? e.getDriver().getPersonel().getDepartment().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getRegion() != null ? e.getDriver().getPersonel().getRegion().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getPhone(), font)); pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getPosition(), font)); pdfTable.addCell(new Paragraph(e.getLic_end_dt().toLocaleString(), font)); } } break; } case 3: // accidents { numberOfColumns = 8; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Accident Date", font)); pdfTable.addCell(new Paragraph("Description", font)); pdfTable.addCell(new Paragraph("Driver", font)); pdfTable.addCell(new Paragraph("Driver Comment", font)); pdfTable.addCell(new Paragraph("Police Officer", font)); pdfTable.addCell(new Paragraph("Police Station", font)); pdfTable.addCell(new Paragraph("Police Comment", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getVehicleAccidents() != null) { for (VehicleAccident e : getVehicleAccidents()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getAccident_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getAccidentDescription(), font)); pdfTable.addCell(new Paragraph(e.getDriver_name(), font)); pdfTable.addCell(new Paragraph(e.getDriverComment(), font)); pdfTable.addCell(new Paragraph(e.getPoliceOfficer(), font)); pdfTable.addCell(new Paragraph(e.getPoliceStation(), font)); pdfTable.addCell(new Paragraph(e.getPoliceComment(), font)); } } break; } case 4: // vehicles by brand { numberOfColumns = 4; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Make", font)); pdfTable.addCell(new Paragraph("Model", font)); pdfTable.addCell(new Paragraph("Year", font)); pdfTable.addCell(new Paragraph("Reg No.", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getVehiclesByBrand() != null) { for (Vehicle e : getVehiclesByBrand()) { pdfTable.addCell(new Paragraph(e.getModel().getMaker().getName(), font)); pdfTable.addCell(new Paragraph(e.getModel().getName(), font)); pdfTable.addCell(new Paragraph(e.getModel().getYear(), font)); pdfTable.addCell(new Paragraph(e.getRegistrationNo(), font)); } } break; } case 5: // routine maintenance { numberOfColumns = 8; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Requester", font)); pdfTable.addCell(new Paragraph("Description", font)); pdfTable.addCell(new Paragraph("Start Date", font)); pdfTable.addCell(new Paragraph("Initial Cost", font)); pdfTable.addCell(new Paragraph("Status", font)); pdfTable.addCell(new Paragraph("Close Date", font)); pdfTable.addCell(new Paragraph("Final Cost", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getRmaints() != null) { for (VehicleRoutineMaintenance e : getRmaints()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getCreatedBy().getPersonel().getFirstname() + " " + e.getCreatedBy().getPersonel().getLastname(), font)); pdfTable.addCell(new Paragraph(e.getDescription(), font)); pdfTable.addCell(new Paragraph(e.getStart_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getInitial_amount().toPlainString(), font)); pdfTable.addCell(new Paragraph(e.getStatus(), font)); pdfTable.addCell(new Paragraph(e.getClose_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getClosed_amount().toPlainString(), font)); } } break; } case 6: // ad hoc maintenance { numberOfColumns = 8; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Requester", font)); pdfTable.addCell(new Paragraph("Description", font)); pdfTable.addCell(new Paragraph("Start Date", font)); pdfTable.addCell(new Paragraph("Initial Cost", font)); pdfTable.addCell(new Paragraph("Status", font)); pdfTable.addCell(new Paragraph("Close Date", font)); pdfTable.addCell(new Paragraph("Final Cost", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getAdhocmaints() != null) { for (VehicleAdHocMaintenance e : getAdhocmaints()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getCreatedBy().getPersonel().getFirstname() + " " + e.getCreatedBy().getPersonel().getLastname(), font)); pdfTable.addCell(new Paragraph(e.getDescription(), font)); pdfTable.addCell(new Paragraph(e.getStart_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getInitial_cost().toPlainString(), font)); pdfTable.addCell(new Paragraph(e.getStatus(), font)); pdfTable.addCell(new Paragraph(e.getClose_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getClosed_cost().toPlainString(), font)); } } break; } case 7: // active accidents { numberOfColumns = 8; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Accident Date", font)); pdfTable.addCell(new Paragraph("Description", font)); pdfTable.addCell(new Paragraph("Driver Name", font)); pdfTable.addCell(new Paragraph("Driver Comment", font)); pdfTable.addCell(new Paragraph("Police Name", font)); pdfTable.addCell(new Paragraph("Station Name", font)); pdfTable.addCell(new Paragraph("Police Comment", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getActiveAccidents() != null) { for (VehicleAccident e : getActiveAccidents()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getAccident_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getAccidentDescription(), font)); pdfTable.addCell(new Paragraph(e.getDriver_name(), font)); pdfTable.addCell(new Paragraph(e.getDriverComment(), font)); pdfTable.addCell(new Paragraph(e.getPoliceOfficer(), font)); pdfTable.addCell(new Paragraph(e.getPoliceStation(), font)); pdfTable.addCell(new Paragraph(e.getPoliceComment(), font)); } } break; } case 8: // coporate trips { numberOfColumns = 9; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 6, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Requester", font)); pdfTable.addCell(new Paragraph("Department", font)); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Departure Location", font)); pdfTable.addCell(new Paragraph("Arrival Location", font)); pdfTable.addCell(new Paragraph("Departure Date and Time", font)); pdfTable.addCell(new Paragraph("Est. Arrival Date and Time", font)); pdfTable.addCell(new Paragraph("Act. Arrival Date and Time", font)); pdfTable.addCell(new Paragraph("Status", font)); font = new Font(helvetica, 6, Font.NORMAL); if (getCorTrips() != null) { for (CorporateTrip e : getCorTrips()) { pdfTable.addCell( new Paragraph(e.getStaff().getFirstname() + " " + e.getStaff().getLastname(), font)); pdfTable.addCell(new Paragraph( (e.getStaff().getDepartment() != null) ? e.getStaff().getDepartment().getName() : "N/A", font)); pdfTable.addCell(new Paragraph( e.getVehicle() != null ? e.getVehicle().getRegistrationNo() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getDepartureLocation(), font)); pdfTable.addCell(new Paragraph(e.getArrivalLocation(), font)); pdfTable.addCell(new Paragraph(e.getDepartureDateTime().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getEstimatedArrivalDateTime().toLocaleString(), font)); pdfTable.addCell(new Paragraph( e.getCompleteRequestDateTime() != null ? e.getCompleteRequestDateTime().toLocaleString() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getTripStatus(), font)); } } break; } case 9: // expense report { numberOfColumns = 4; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Type", font)); pdfTable.addCell(new Paragraph("Date", font)); pdfTable.addCell(new Paragraph("Amount", font)); pdfTable.addCell(new Paragraph("Detail", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getExpenses() != null) { for (Expense e : getExpenses()) { pdfTable.addCell(new Paragraph(e.getType().getName(), font)); pdfTable.addCell(new Paragraph(e.getExpense_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph("" + e.getAmount(), font)); pdfTable.addCell(new Paragraph(e.getRemarks(), font)); } } break; } case 10: // vehicle ages { numberOfColumns = 6; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Make", font)); pdfTable.addCell(new Paragraph("Model", font)); pdfTable.addCell(new Paragraph("Year", font)); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Date of Purchase", font)); pdfTable.addCell(new Paragraph("Age (in years)", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getVehiclesAges() != null) { for (Vehicle e : getVehiclesAges()) { pdfTable.addCell(new Paragraph( e.getModel().getMaker() != null ? e.getModel().getMaker().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getModel() != null ? e.getModel().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getModel() != null ? e.getModel().getYear() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getRegistrationNo(), font)); pdfTable.addCell(new Paragraph( e.getPurchaseDate() != null ? e.getPurchaseDate().toLocaleString() : "N/A", font)); pdfTable.addCell(new Paragraph("" + e.getAge(), font)); } } break; } case 11: // vehicle fuelings { numberOfColumns = 5; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Date", font)); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Litres", font)); pdfTable.addCell(new Paragraph("Amount", font)); pdfTable.addCell(new Paragraph("Source", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getFuelings() != null) { for (VehicleFueling e : getFuelings()) { pdfTable.addCell(new Paragraph(e.getCaptured_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph("" + e.getLitres(), font)); pdfTable.addCell(new Paragraph("" + e.getAmt(), font)); pdfTable.addCell(new Paragraph(e.getSource(), font)); } } break; } case 12: // due vehicle licenses { numberOfColumns = 5; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Fleet", font)); pdfTable.addCell(new Paragraph("Make", font)); pdfTable.addCell(new Paragraph("Model", font)); pdfTable.addCell(new Paragraph("License Due Date", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getDueVehicleLicenses() != null) { for (VehicleLicense e : getDueVehicleLicenses()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getVehicle().getFleet().getName(), font)); pdfTable.addCell(new Paragraph( e.getVehicle().getModel() != null ? e.getVehicle().getModel().getMaker().getName() : "N/A", font)); pdfTable.addCell(new Paragraph( e.getVehicle().getModel() != null ? e.getVehicle().getModel().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getLic_end_dt().toLocaleString(), font)); } } break; } } pdfTable.setWidthPercentage(100); return pdfTable; }
From source file:com.dexter.fuelcard.mbean.UtilMBean.java
public byte[] createInvoicePDF(int pageType, String title, String dateperiod, String amount, String chargeType, String chargeAmount, String total) { try {//from ww w .j ava 2s. c o m Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new HeaderFooter()); writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788)); if (!document.isOpen()) { document.open(); } switch (pageType) { case 1: document.setPageSize(PageSize.A4); break; case 2: document.setPageSize(PageSize.A4.rotate()); break; } document.addAuthor("FUELCARD"); document.addCreationDate(); document.addCreator("FUELCARD"); document.addSubject("Invoice"); document.addTitle(title); PdfPTable headerTable = new PdfPTable(1); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "satraklogo.jpg"; PdfPCell c = new PdfPCell(Image.getInstance(logo)); c.setBorder(0); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); Paragraph stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { //font exception } Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph(title, font)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); if (dateperiod != null) { stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(10); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); new Font(helvetica, 12, Font.NORMAL); Paragraph ch = new Paragraph("For " + dateperiod, font); c = new PdfPCell(ch); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); } stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); document.add(headerTable); PdfPTable pdfTable = new PdfPTable(4); try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Charge Type", font)); // % per transaction or flat per license pdfTable.addCell(new Paragraph("Charge Amount", font)); // the amount of the charge setting if (chargeType.equalsIgnoreCase("Percent-Per-Tran")) { pdfTable.addCell(new Paragraph("Total Amount", font)); // the amount of the charge setting } else { pdfTable.addCell(new Paragraph("Total License", font)); // the amount of the charge setting } //pdfTable.addCell(new Paragraph("Description", font)); // the pdfTable.addCell(new Paragraph("Amount Due", font)); font = new Font(helvetica, 8, Font.NORMAL); pdfTable.addCell(new Paragraph(chargeType, font)); pdfTable.addCell(new Paragraph(chargeAmount, font)); pdfTable.addCell(new Paragraph(total, font)); pdfTable.addCell(new Paragraph(amount, font)); pdfTable.setWidthPercentage(100); if (pdfTable != null) document.add(pdfTable); //Keep modifying your pdf file (add pages and more) document.close(); return baos.toByteArray(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.farouk.projectapp.ManagerGUI.java
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed String pdfName = JOptionPane.showInputDialog(rootPane, "Enter Title", "Please enter a title", WIDTH); if (pdfName.isEmpty()) { pdfName = "Global Report"; }//from www .j a va 2 s . co m Document document = new Document(); int numEMployees = 1; try { PdfWriter.getInstance(document, new FileOutputStream(pdfName + ".pdf")); document.open(); document.addAuthor("TeamPirates"); document.addTitle("Global Report"); Font font1 = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD); Font font2 = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.UNDERLINE); for (User u : SQLConnectMana.getEmployeesFromDb()) { JTable jTableTran = new JTable(); JTable jTableReport = new JTable(); Chapter chapter = new Chapter( new Paragraph(new Phrase("Employee : " + u.getLogin() + "\n\n", font1)), numEMployees); Section section1 = chapter.addSection(new Paragraph(new Phrase("Recent Transactions :\n", font2)), 9); Section section2 = chapter.addSection(new Paragraph(new Phrase("Reported Companies :\n", font2)), 9); // Transactions : DefaultTableModel modelPDFtrans = new DefaultTableModel(); modelPDFtrans.setColumnIdentifiers( new String[] { "Name", "Operation", "Quantity", "Price Paid", "Date" }); for (Transaction t : SQLConnectMana.getTransactions(u.getId())) { modelPDFtrans.addRow(new String[] { t.getSymbol(), t.getOperation(), Integer.toString(t.getQuantity()), Double.toString(t.getPricePaid()), t.getDate() }); } jTableTran.setModel(modelPDFtrans); PdfPTable pdfTableTrans = new PdfPTable(jTableTran.getColumnCount()); for (int i = 0; i < jTableTran.getColumnCount(); i++) { pdfTableTrans.addCell(jTableTran.getColumnName(i)); } //extracting data from the JTable and inserting it to PdfPTable for (int rows = 0; rows < jTableTran.getRowCount(); rows++) { for (int cols = 0; cols < jTableTran.getColumnCount(); cols++) { pdfTableTrans.addCell(jTableTran.getModel().getValueAt(rows, cols).toString()); } } Paragraph blank = new Paragraph("\n\n"); section1.add(blank); section1.add(pdfTableTrans); section1.add(blank); //Reported Companies : DefaultTableModel modelPDFReported = new DefaultTableModel(); modelPDFReported.setColumnIdentifiers( new String[] { "Name", "Symbol", "Stock Price ()", "Quantity Bought" }); for (Company c : SQLConnectMana.getNameOfReported(u.getId())) { modelPDFReported.addRow(new String[] { c.getName(), c.getSymbol(), String.valueOf(c.getStockPrice().doubleValue()), Integer.toString(c.getNumberOwned()) }); } jTableReport.setModel(modelPDFReported); PdfPTable pdfTableReport = new PdfPTable(jTableReport.getColumnCount()); for (int i = 0; i < jTableReport.getColumnCount(); i++) { pdfTableReport.addCell(jTableReport.getColumnName(i)); } //extracting data from the JTable and inserting it to PdfPTable for (int rows = 0; rows < jTableReport.getRowCount(); rows++) { for (int cols = 0; cols < jTableReport.getColumnCount(); cols++) { pdfTableReport.addCell(jTableReport.getModel().getValueAt(rows, cols).toString()); } } section2.add(blank); section2.add(pdfTableReport); section2.add(blank); //End of doc for a single employee document.add(chapter); numEMployees++; } Chapter ban = new Chapter(new Paragraph(new Phrase("Prohibited Companies :\n\n", font1)), ++numEMployees); com.itextpdf.text.List bannedCompanies = new List(List.ORDERED); for (String lii : SQLConnectMana.getBannedCompForAll()) { bannedCompanies.add(new com.itextpdf.text.ListItem(lii)); } ban.add(bannedCompanies); document.add(ban); document.close(); } catch (DocumentException | FileNotFoundException e) { System.err.println("Sorry Problem in pdf.\n" + e); } }
From source file:com.gadroves.gsisinve.controller.FacturarController.java
void PrintToPDF(TbFacturaVenta facturaVenta, TbCLienteFactura cLienteFactura) throws DocumentException, IOException { Font header = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font normalBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font normal = new Font(Font.FontFamily.HELVETICA, 12); String fileName = "Factura_" + facturaVenta.getId() + ".pdf"; // step 1// w ww .j a va2s . c o m Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(fileName)); // step 3 document.open(); // step 4 document.add(new Paragraph("Gadroves S.A Factura De Venta", header)); document.add(new Paragraph(" ")); document.add(new Paragraph("Factura N" + facturaVenta.getId(), normalBold)); document.add(new Chunk("Cliente: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getName(), normal)); document.add(new Paragraph()); document.add(new Chunk("Direccin: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getAddress(), normal)); document.add(new Paragraph()); document.add(new Chunk("Identificacion: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getId(), normal)); document.add(new Paragraph()); document.add(new Chunk("Credito: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(Boolean.FALSE.toString(), normal)); document.add(new Paragraph()); for (int i = 0; i < 3; i++) document.add(new Paragraph(" ")); createItemsTable(document, facturaVenta); document.add(new Paragraph(" ")); Paragraph subs = new Paragraph(); subs.setAlignment(Element.ALIGN_RIGHT); subs.setIndentationRight(40); subs.add(new Chunk("Subtotal: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getSub())))); subs.add(Chunk.NEWLINE); subs.add(new Chunk( "Impuestos: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getImpuestos())))); subs.add(Chunk.NEWLINE); subs.add(new Chunk( "Total: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getTotal())))); subs.add(Chunk.NEWLINE); document.add(subs); // step 5 document.close(); Desktop.getDesktop().open(new File(fileName)); }
From source file:com.github.luischavez.levsym.modulos.funcion.PDF.java
License:Open Source License
public void GeneraPDF(ResultSet Resultados) throws Exception { ResultSetMetaData metaData = Resultados.getMetaData(); Object[] Columnas = new Object[metaData.getColumnCount()]; String encabezado = "Reportes del Sistema Administrativo" + "\n" + "REGISTROS ACTUALES EN AL BASE DE DATOS" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n"; Calendar c = Calendar.getInstance(); String date = Integer.toString(c.get(Calendar.DAY_OF_MONTH)) + "-" + Integer.toString(c.get(Calendar.MONTH)) + "-" + Integer.toString(c.get(Calendar.YEAR)) + " " + Integer.toString(c.get(Calendar.HOUR_OF_DAY)) + "-" + Integer.toString(c.get(Calendar.MINUTE)) + "-" + Integer.toString(c.get(Calendar.SECOND)); Font fuente = new Font(Font.getFamily("ARIAL"), 12, Font.BOLD); String choro = "Reporte por fecha de los modulos\n" + "de catalogo" + "\n" + "Systema Administrativo" + "\n" + "\n" + "\n" + "\n"; Image imagen = Image.getInstance(System.getProperty("user.dir") + "/Image/logo.png"); imagen.setAlignment(Image.TEXTWRAP); try {// w ww. j a va 2s.co m Paragraph linea = new Paragraph(encabezado, fuente); Phrase para = new Phrase(choro); Paragraph fecha = new Paragraph(date + "\n" + "\n"); PdfPTable tabla = new PdfPTable(Columnas.length); tabla.setWidthPercentage(100); //Document documento = new Document(PageSize.LETTER); Document documento = new Document(PageSize.A4.rotate(), 50, 50, 100, 72); File Dir = new File(System.getProperty("user.dir") + "/Reportes/"); if (!Dir.exists()) { Dir.mkdirs(); } String file = System.getProperty("user.dir") + "/Reportes/" + metaData.getTableName(1) + " " + date + ".pdf"; PdfWriter.getInstance(documento, new FileOutputStream(file)); documento.open(); documento.add(imagen); documento.add(linea); documento.add(para); documento.add(fecha); for (int x = 0; x < Columnas.length; x++) { PdfPCell Celda = new PdfPCell(new Paragraph(metaData.getColumnName(x + 1), FontFactory.getFont("arial", 9, Font.BOLD, BaseColor.RED))); Celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(Celda); } while (Resultados.next()) { for (int x = 0; x < Columnas.length; x++) { //if(Resultados.getObject(x+1).getClass().getSimpleName().equals("Integer")) PdfPCell Celda = new PdfPCell(new Paragraph(String.valueOf(Resultados.getObject(x + 1)), FontFactory.getFont("arial", 9, BaseColor.BLACK))); Celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(Celda); } } documento.add(tabla); documento.close(); } catch (DocumentException e) { Log.SaveLog(e.toString()); JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (IOException e) { Log.SaveLog(e.toString()); JOptionPane.showMessageDialog(null, e.getMessage(), "error", JOptionPane.ERROR_MESSAGE); } }