List of usage examples for com.itextpdf.text.pdf PdfWriter getInstance
public static PdfWriter getInstance(final Document document, final OutputStream os) throws DocumentException
PdfWriter
. From source file:com.netsteadfast.greenstep.bsc.command.PersonalReportPdfCommand.java
License:Apache License
private String createPdf(Context context) throws Exception { BscReportPropertyUtils.loadData();//from w w w. j av a2s . co m String visionOid = (String) context.get("visionOid"); VisionVO vision = null; BscStructTreeObj treeObj = (BscStructTreeObj) this.getResult(context); for (VisionVO visionObj : treeObj.getVisions()) { if (visionObj.getOid().equals(visionOid)) { vision = visionObj; } } FontFactory.register(BscConstants.PDF_ITEXT_FONT); String fileName = UUID.randomUUID().toString() + ".pdf"; String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName; OutputStream os = new FileOutputStream(fileFullPath); Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); document.left(100f); document.top(150f); PdfWriter writer = PdfWriter.getInstance(document, os); document.open(); PdfPTable table = new PdfPTable(MAX_COLSPAN); table.setWidthPercentage(100f); PdfPTable signTable = new PdfPTable(1); signTable.setWidthPercentage(100f); this.createHead(table, vision, context); this.createBody(table, vision); this.createFoot(table, context); this.putSignature(signTable, context); document.add(table); document.add(signTable); document.close(); writer.close(); os.flush(); os.close(); os = null; File file = new File(fileFullPath); String oid = UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, file, "personal-report.pdf"); file = null; return oid; }
From source file:com.nlbhub.nlb.domain.export.hypertext.document.PDFDocument.java
License:Open Source License
@Override public void initWriter(File targetFile) throws FileNotFoundException, HTDocumentException { try {//from w w w. jav a 2 s.co m PdfWriter.getInstance(m_document, new FileOutputStream(targetFile)); } catch (DocumentException e) { throw new HTDocumentException("Error during PDFWriter initialization", e); } }
From source file:com.norbsoft.pdfconverter.helpers.PDFHelper.java
License:Open Source License
public int generate(String saveUrl, SerializableBitmap sign, Form form, ArrayList<String> photos, ArrayList<String> workers) { try {/*from w w w . ja va2 s.c o m*/ Document document = new Document(); url = saveUrl; PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(url)); document.setMargins(20, 20, 20, 20); document.open(); Bitmap inputLogo = BitmapFactory.decodeStream(context.getAssets().open("logo.jpg")); ByteArrayOutputStream outstream = new ByteArrayOutputStream(); inputLogo.compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image logo = Image.getInstance(outstream.toByteArray()); Bitmap inputQR = BitmapFactory.decodeStream(context.getAssets().open("qr.jpg")); outstream = new ByteArrayOutputStream(); inputQR.compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image qr = Image.getInstance(outstream.toByteArray()); outstream = new ByteArrayOutputStream(); sign.getImage().compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image sgn = Image.getInstance(outstream.toByteArray()); qr.scaleAbsolute(90f, 90f); qr.setAbsolutePosition(340f, 705f); logo.scaleAbsolute(150f, 50f); logo.setAbsolutePosition(50f, 750f); sgn.scaleAbsolute(130f, 30f); sgn.setAbsolutePosition(25f, 75f); Paragraph p = new Paragraph("\r\n\r\n\r\nMPWiK S.A.\r\n50-421 Wrocaw\r\nul.Na Grobli 14-16", normal); p.setIndentationLeft(420f); document.add(p); p = new Paragraph("RAPORT WYMIANY WODOMIERZA", bold); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingBefore(60f); document.add(p); document.add(table(form)); p = new Paragraph(form.getInformations(), normal); p.setAlignment(Element.ALIGN_LEFT); p.setIndentationLeft(50f); p.setSpacingBefore(20f); document.add(p); document.add(signTable(form, sgn, workers)); document.add(logo); document.add(qr); if (photos != null && photos.size() > 0) { document.newPage(); for (int i = 0; i < photos.size(); i++) { try { if (photos.get(i) != null && !photos.get(i).equals("")) { Log.d(TAG, photos.get(i)); Bitmap temp = PictureHelper.bitmapFromUrl(photos.get(i)); outstream = new ByteArrayOutputStream(); temp.compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image photo = Image.getInstance(outstream.toByteArray()); photo.scaleToFit(document.getPageSize().getWidth() - 50, document.getPageSize().getHeight()); document.add(photo); } } catch (Exception e) { } } } document.close(); writer.close(); return 1; } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); return 0; } catch (DocumentException e) { Log.e(TAG, e.getMessage()); return 0; } catch (IOException e) { Log.e(TAG, e.getMessage()); return 0; } catch (Exception e) { Log.e(TAG, e.getMessage()); return 0; } }
From source file:com.northcoders.controller.BookingReportsController.java
@FXML private void generatePdf() throws Exception { BaseFont bf;//from w w w . j av a2s. co m Font font; try { conditions = "Filtered by: Start Date:2017-03-15 End Date:2017-03-28"; /* Step-2: Initialize PDF documents - logical objects */ Document my_pdf_report = new Document(PageSize.LETTER.rotate()); PdfWriter.getInstance(my_pdf_report, new FileOutputStream("pdf_booking_report.pdf")); my_pdf_report.open(); //we have four columns in our table PdfPTable my_report_table = new PdfPTable(6); //create a cell object PdfPCell table_cell; bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); font = new Font(bf, 16); my_pdf_report.add(new Paragraph("Administration Report", font)); font = new Font(bf, 12); my_pdf_report.add(new Paragraph("Filter applied:" + conditions, font)); my_pdf_report.add(new Paragraph(" ")); table_cell = new PdfPCell(new Phrase("Customer")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Start Date")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("End Date")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Room")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Amount")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Transactions")); my_report_table.addCell(table_cell); for (Booking item : bookings) { String customer_b = item.getCustomerId().getId() + " " + item.getCustomerId().getFirstName() + " " + item.getCustomerId().getLastName(); table_cell = new PdfPCell(new Phrase(customer_b)); my_report_table.addCell(table_cell); String date_start_b = dateToStr(item.getStartDate()); table_cell = new PdfPCell(new Phrase(date_start_b)); my_report_table.addCell(table_cell); String date_end_b = dateToStr(item.getEndDate()); table_cell = new PdfPCell(new Phrase(date_end_b)); my_report_table.addCell(table_cell); String room_b = String.valueOf(item.getRoomId().getRoomNumber()); table_cell = new PdfPCell(new Phrase(room_b)); my_report_table.addCell(table_cell); String price_b = String.format("%1$,.2f", item.getTotalPrice()); table_cell = new PdfPCell(new Phrase(price_b)); my_report_table.addCell(table_cell); String transaction_b = ""; for (PaymentTransaction trans : item.getPaymentTransactionList()) { transaction_b += String.format("%1$,.2f", trans.getAmount()) + " " + trans.getPaymentTypeId().getDescription() + "\n"; } table_cell = new PdfPCell(new Phrase(transaction_b)); my_report_table.addCell(table_cell); } /* Attach report table to PDF */ my_pdf_report.add(my_report_table); my_pdf_report.add(new Paragraph(" ")); font = new Font(bf, 6); my_pdf_report.add(new Paragraph("Report Time:" + dateTimeToStr(new Date()))); my_pdf_report.close(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.ostrichemulators.semtool.util.ExportUtility.java
License:Open Source License
public static void exportAsPdf(BufferedImage img, File pdf) throws IOException, DocumentException { final double MAX_DIM = 14400; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(img, "PNG", baos); Image image1 = Image.getInstance(baos.toByteArray(), true); Rectangle r;/* w w w . jav a 2 s . c o m*/ if (image1.getHeight() > MAX_DIM) { r = new Rectangle((int) image1.getWidth(), (int) MAX_DIM); } else if (image1.getWidth() > MAX_DIM) { r = new Rectangle((int) MAX_DIM, (int) image1.getHeight()); } else { r = new Rectangle((int) image1.getWidth() + 20, (int) image1.getHeight() + 20); } Document document = new Document(r, 15, 25, 15, 25); PdfWriter.getInstance(document, new FileOutputStream(pdf)); document.open(); int pages = (int) Math.ceil((double) img.getHeight() / MAX_DIM); if (pages == 0) { pages = 1; } for (int i = 0; i < pages; i++) { BufferedImage temp; if (i < pages - 1) { temp = img.getSubimage(0, i * (int) MAX_DIM, img.getWidth(), (int) MAX_DIM); } else { temp = img.getSubimage(0, i * (int) MAX_DIM, img.getWidth(), img.getHeight() % (int) MAX_DIM); } File tempFile = new File(i + Constants.PNG); ImageIO.write(temp, Constants.PNG, tempFile); Image croppedImage = Image.getInstance(i + Constants.PNG); document.add(croppedImage); tempFile.delete(); if (i < pages - 1) { document.newPage(); } } document.close(); }
From source file:com.pablog178.pdfcreator.android.PdfcreatorModule.java
License:Open Source License
private void generateiTextPDFfunction(HashMap args) { if (args.containsKey("fileName")) { Object fileName = args.get("fileName"); if (fileName instanceof String) { this.fileName = (String) fileName; Log.i(PROXY_NAME, "fileName: " + this.fileName); }/*www .j av a 2 s . c o m*/ } else return; if (args.containsKey("view")) { Object viewObject = args.get("view"); if (viewObject instanceof TiViewProxy) { TiViewProxy viewProxy = (TiViewProxy) viewObject; this.view = viewProxy.getOrCreateView(); if (this.view == null) { Log.e(PROXY_NAME, "NO VIEW was created!!"); return; } Log.i(PROXY_NAME, "view: " + this.view.toString()); } } else return; if (args.containsKey("quality")) { this.quality = TiConvert.toInt(args.get("quality")); } if (args.containsKey("pageSize")) { Object pageSize = args.get("pageSize"); if (pageSize instanceof String) { if (pageSize.equals("letter")) { this.pageSize = PageSize.LETTER; } else if (pageSize.equals("A4")) { this.pageSize = PageSize.A4; } else { this.pageSize = PageSize.LETTER; } } } TiBaseFile file = TiFileFactory.createTitaniumFile(this.fileName, true); Log.i(PROXY_NAME, "file full path: " + file.nativePath()); try { Resources appResources = app.getResources(); OutputStream outputStream = file.getOutputStream(); final int MARGIN = 0; final float PDF_WIDTH = this.pageSize.getWidth() - MARGIN * 2; // A4: 595 //Letter: 612 final float PDF_HEIGHT = this.pageSize.getHeight() - MARGIN * 2; // A4: 842 //Letter: 792 final int DEFAULT_VIEW_WIDTH = 980; final int DEFAULT_VIEW_HEIGHT = 1384; int viewWidth = DEFAULT_VIEW_WIDTH; int viewHeight = DEFAULT_VIEW_HEIGHT; Document pdfDocument = new Document(this.pageSize, MARGIN, MARGIN, MARGIN, MARGIN); PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream); Log.i(PROXY_NAME, "PDF_WIDTH: " + PDF_WIDTH); Log.i(PROXY_NAME, "PDF_HEIGHT: " + PDF_HEIGHT); WebView view = (WebView) this.view.getNativeView(); if (TiApplication.isUIThread()) { viewWidth = view.capturePicture().getWidth(); viewHeight = view.capturePicture().getHeight(); if (viewWidth <= 0) { viewWidth = DEFAULT_VIEW_WIDTH; } if (viewHeight <= 0) { viewHeight = DEFAULT_VIEW_HEIGHT; } } else { Log.e(PROXY_NAME, "NO UI THREAD"); viewWidth = DEFAULT_VIEW_WIDTH; viewHeight = DEFAULT_VIEW_HEIGHT; } view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); Log.i(PROXY_NAME, "viewWidth: " + viewWidth); Log.i(PROXY_NAME, "viewHeight: " + viewHeight); float scaleFactorWidth = 1 / ((float) viewWidth / PDF_WIDTH); float scaleFactorHeight = 1 / ((float) viewHeight / PDF_HEIGHT); Log.i(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth); Log.i(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight); Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888); Canvas viewCanvas = new Canvas(viewBitmap); // Paint paintAntialias = new Paint(); // paintAntialias.setAntiAlias(true); // paintAntialias.setFilterBitmap(true); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(viewCanvas); } else { viewCanvas.drawColor(Color.WHITE); } view.draw(viewCanvas); TiBaseFile pdfImg = createTempFile(); // ByteArrayOutputStream stream = new ByteArrayOutputStream(32); // viewBitmap.compress(Bitmap.CompressFormat.JPEG, this.quality, stream); viewBitmap.compress(Bitmap.CompressFormat.JPEG, this.quality, pdfImg.getOutputStream()); FileInputStream pdfImgInputStream = new FileInputStream(pdfImg.getNativeFile()); byte[] pdfImgBytes = IOUtils.toByteArray(pdfImgInputStream); pdfImgInputStream.close(); // ByteBuffer buffer = ByteBuffer.allocate(viewBitmap.getByteCount()); // viewBitmap.copyPixelsToBuffer(buffer); pdfDocument.open(); float yFactor = viewHeight * scaleFactorWidth; int pageNumber = 1; do { if (pageNumber > 1) { pdfDocument.newPage(); } pageNumber++; yFactor -= PDF_HEIGHT; Image pageImage = Image.getInstance(pdfImgBytes, true); // Image pageImage = Image.getInstance(buffer.array()); pageImage.scalePercent(scaleFactorWidth * 100); pageImage.setAbsolutePosition(0f, -yFactor); pdfDocument.add(pageImage); Log.i(PROXY_NAME, "yFactor: " + yFactor); } while (yFactor > 0); pdfDocument.close(); sendCompleteEvent(); } catch (Exception exception) { Log.e(PROXY_NAME, "Error: " + exception.toString()); sendErrorEvent(exception.toString()); } }
From source file:com.pdf.GetPdf.java
private void convertToPdf(String url, ServletOutputStream out) { try {//from w w w . ja va2 s. c o m String contentType = new URL(url).openConnection().getContentType(); Document document = new Document(); PdfWriter.getInstance(document, out); document.open(); if (contentType.equalsIgnoreCase("application/vnd.ms-excel")) { addXls(document, url, "xls"); } else if (contentType .equalsIgnoreCase("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { addXls(document, url, "xlsx"); } else if (contentType.equalsIgnoreCase("application/msword")) { docConvert(document, url, "doc"); } else if (contentType .equalsIgnoreCase("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) { docConvert(document, url, "docx"); } else if (contentType.equalsIgnoreCase("image/tiff")) { addTif(document, url); } else if (contentType.equalsIgnoreCase("image/gif")) { addGif(document, url); } else { Image image = Image.getInstance(url); image.scaleToFit(550, 800); document.add(image); } document.close(); } catch (MalformedURLException ex) { Logger.getLogger(GetPdf.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GetPdf.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(GetPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.pdfs.generadorDevolucionReport.java
public boolean generarReporteDev(List<Devolucion> listaDevo, String nombre) { try {/* w w w . jav a 2s .c o m*/ FileOutputStream archivoPdf = null; System.out.println("nombre documento: " + nombre); File archivo = new File(nombre); System.out.println("Se creo el archivo"); archivoPdf = new FileOutputStream(archivo); // Se asocia el documento al OutputStream y se indica que el espaciado entre // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento PdfWriter pw = PdfWriter.getInstance(documento, archivoPdf); pw.setInitialLeading(20); // abrir el documento documento.open(); System.out.println("Se abrio el documento"); Paragraph p = new Paragraph("RELACION DE DEVOLUCIONES DE CUENTAS", tituloN1); p.setAlignment(Chunk.ALIGN_CENTER); documento.add(p); documento.close(); return true; } catch (FileNotFoundException ex) { Logger.getLogger(generadorDevolucionReport.class.getName()).log(Level.SEVERE, null, ex); return false; } catch (DocumentException ex) { Logger.getLogger(generadorDevolucionReport.class.getName()).log(Level.SEVERE, null, ex); return false; } }
From source file:com.pdfs.GeneradorVisitas.java
public boolean generarVisitas(List<DatosVisitaDomiciliaria> creditos, String nombre) { FileOutputStream ficheroPdf = null; //rutaimg = rutafirma; try {//from w w w. j ava 2s. c o m System.out.println("nombre " + nombre); System.out.println("ruta " + rutaimg); File nombrearchivo = new File(nombre); LogSistema.guardarlog("ruta " + nombrearchivo.getAbsolutePath()); ficheroPdf = new FileOutputStream(nombrearchivo); LogSistema.guardarlog("descriptor " + ficheroPdf.getFD().valid()); // Se asocia el documento al OutputStream y se indica que el espaciado entre // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento PdfWriter pw = PdfWriter.getInstance(documento, ficheroPdf); pw.setInitialLeading(20); // Se abre el documento. documento.open(); System.out.println("ABRIO EL DOCUMENTO"); String prod; int cont = 0; LogSistema.guardarlog("al generar " + creditos.size()); for (DatosVisitaDomiciliaria ct : creditos) { prod = ct.getProducto().toUpperCase(); if (prod.contains("EXPRESS")) { System.out.println("ENTRO A CT EXPRESS"); if (cont == 0) { addCreditosExpress(ct); cont++; } else { documento.newPage(); addCreditosExpress(ct); } //sofom } else if (prod.compareTo("A_LINEA CREDITO TELMEX PF 50") == 0 || prod.compareTo("A_LINEA CREDITO TELMEX PM 50") == 0 || prod.compareTo("EX LINEA CREDITO TELMEX PF") == 0 || prod.compareTo("EX LINEA CREDITO TELMEX PM") == 0 || prod.compareTo("A_LINEA CREDITO TELMEX PERSONAL 38") == 0 || prod.compareTo("EX LINEA CREDITO TELMEX PERSONAL 38") == 0 || prod.compareTo("A_LINEA CREDITO TELNOR PERSONAL 38") == 0) { if (cont == 0) { addCreditosTelmexSOFOM(ct); cont++; } else { documento.newPage(); addCreditosTelmexSOFOM(ct); } //linea telmex } else if (prod.compareTo("LINEA CREDITO TELMEX PF") == 0 || prod.compareTo("LINEA CREDITO TELMEX PM") == 0 || prod.compareTo("EXLINEA CREDITO TELMEX PF") == 0 || prod.compareTo("EXLINEA CREDITO TELMEX PM") == 0 || prod.compareTo("LINEA CREDITO TELNOR PF") == 0 || prod.compareTo("EX LINEA CREDITO TELNOR PF") == 0 || prod.compareTo("EXLINEA CREDITO TELNOR PM") == 0 || prod.compareTo("A_LINEA CREDITO TELNOR PF 50") == 0 || prod.compareTo("A_LINEA CREDITO TELNOR PM 50") == 0 || prod.compareTo("LINEA CREDITO TELNOR PM") == 0 || prod.compareTo("A_EX LINEA CREDITO TELNOR PF 50") == 0 || prod.compareTo("A_EXLINEA CREDITO TELNOR PM 50") == 0) { if (cont == 0) { addCreditosTelmex(ct); cont++; } else { documento.newPage(); addCreditosTelmex(ct); } } } documento.close(); return true; } catch (FileNotFoundException ex) { LogSistema.guardarlog(ex.getMessage() + " " + new Date()); return false; } catch (DocumentException ex) { LogSistema.guardarlog(ex.getMessage() + " " + new Date()); return false; } catch (IOException ex) { LogSistema.guardarlog(ex.getMessage() + " " + new Date()); return false; } finally { try { ficheroPdf.close(); } catch (IOException ex) { LogSistema.guardarlog(ex.getMessage() + " " + new Date()); return false; } } }
From source file:com.pdfwriter.PrintInventoryReport.java
public void create(ObservableList list, String totalSales) { try {//from ww w.j a va 2 s . co m Document document = new Document(PageSize.LETTER); document.setMargins(1, 1, 1, 1); PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); Font font2 = new Font(Font.FontFamily.UNDEFINED, 10, Font.BOLD); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(95); table.setWidths(new int[] { 40, 40, 40, 40, 40 }); PdfPCell cell; cell = new PdfPCell(new Phrase("", font2)); cell.setBorder(0); cell.setColspan(8); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthTop(0); cell.setBorderWidthBottom(0); table.addCell(cell); cell = new PdfPCell( new Phrase("KELNOVI SHOPPING BOTIQUE", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell( new Phrase("Pondol,Loon, Bohol", new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell( new Phrase("Phone/Fax#:000-000-000", new Font(Font.FontFamily.UNDEFINED, 9, Font.UNDERLINE))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setRowspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("SALES REPORT", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("NO.")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase("PRODUCT NAME")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase("PRICE")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase("QUANTITY")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase("AMOUNT PAYABLE")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); for (int i = 0; i < list.size(); i++) { it = (ProductClass) list.get(i); cell = new PdfPCell(new Phrase("" + it.idProperty().get())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); cell = new PdfPCell(new Phrase("" + it.productDescriptionProperty().get())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); cell = new PdfPCell(new Phrase("" + it.productPriceProperty().get())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); cell = new PdfPCell(new Phrase("" + it.productQtyProperty().get())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); //totalSales.setText(String.format("%,.2f",globalSales)); cell = new PdfPCell(new Phrase( String.format("%,.2f", Double.parseDouble(it.productTotalSalesProperty().get())))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); } cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("TOTAL AMOUNT PAYABLE:")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell( new Phrase("Php " + totalSales, new Font(Font.FontFamily.UNDEFINED, 14, Font.UNDERLINE))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("Approved by:")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("MICHAEL NOVI MALUENDA II", new Font(Font.FontFamily.UNDEFINED, 14, Font.UNDERLINE))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("General Manager")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); document.add(table); document.close(); openFile(); } catch (Exception e) { e.printStackTrace(); } }