List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(Image image)
From source file:classroom.newspaper_a.Newspaper07.java
public static void main(String[] args) { try {//w ww . j a v a 2s. co m PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte canvas = stamper.getOverContent(1); canvas.saveState(); canvas.setRGBColorFill(0xFF, 0xFF, 0xFF); canvas.rectangle(LLX1, LLY1, W1, H1); canvas.rectangle(LLX2, LLY2, W2, H2); canvas.fill(); canvas.restoreState(); putImage(canvas, Image.getInstance(IMG1), "http://www.manning.com/affiliate/idevaffiliate.php?id=223_0_3_14", LLX1, LLY1, W1, H1); putImage(canvas, Image.getInstance(IMG2), "http://www.1t3xt.com/docs/book.php", LLX2, LLY2, W2, H2); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_b.Newspaper10.java
public static void main(String[] args) { try {/*w ww. java 2s. c om*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PushbuttonField button; Rectangle rect; rect = new Rectangle(100, 980, 700, 1000); button = new PushbuttonField(stamper.getWriter(), rect, "click"); button.setBackgroundColor(Color.ORANGE); button.setText("Click here to close window"); button.setLayout(PushbuttonField.LAYOUT_LABEL_ONLY); button.setAlignment(Element.ALIGN_RIGHT); PdfFormField menubar = button.getField(); String js = "var f1 = getField('click'); f1.display = display.hidden;" + "var f2 = getField('advertisement'); f2.display = display.hidden;"; menubar.setAction(PdfAction.javaScript(js, stamper.getWriter())); stamper.addAnnotation(menubar, 1); rect = new Rectangle(100, 500, 700, 980); button = new PushbuttonField(stamper.getWriter(), rect, "advertisement"); button.setBackgroundColor(Color.WHITE); button.setBorderColor(Color.ORANGE); button.setImage(Image.getInstance(IMG)); button.setText("Buy the book iText in Action"); button.setLayout(PushbuttonField.LAYOUT_LABEL_TOP_ICON_BOTTOM); PdfFormField advertisement = button.getField(); advertisement.setAction(new PdfAction("http://www.1t3xt.com/docs/book.php")); stamper.addAnnotation(advertisement, 1); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_b.Newspaper12.java
public static void putImage(PdfContentByte canvas, String path, float[] positions) throws DocumentException, IOException { float w = positions[3] - positions[1]; float h = positions[4] - positions[2]; Image img = Image.getInstance(path); img.scaleToFit(w, h);/*w ww . j a va 2s .c o m*/ float offsetX = (w - img.getScaledWidth()) / 2f; float offsetY = (h - img.getScaledHeight()) / 2f; img.setAbsolutePosition(positions[1] + offsetX, positions[2] + offsetY); canvas.addImage(img); canvas.rectangle(positions[1], positions[2], w, h); canvas.stroke(); }
From source file:classroom.newspaper_b.Newspaper13.java
public static void addButton(PdfStamper stamper, Rectangle rect, String path, String name, int pagenumber) throws IOException, DocumentException { PushbuttonField field = new PushbuttonField(stamper.getWriter(), rect, name); if (path.endsWith(".pdf")) { PdfReader reader = new PdfReader(path); field.setTemplate(stamper.getImportedPage(reader, 1)); } else {/*from w w w . j av a 2 s . com*/ field.setImage(Image.getInstance(path)); } field.setBackgroundColor(new Color(0xFF, 0xFF, 0xFF)); field.setBorderColor(new Color(0xC0, 0xC0, 0xC0)); field.setBorderWidth(0.5f); field.setScaleIcon(PushbuttonField.SCALE_ICON_ALWAYS); field.setLayout(PushbuttonField.LAYOUT_ICON_ONLY); stamper.addAnnotation(field.getField(), pagenumber); }
From source file:codes.thischwa.jii.core.iTextImageWrapper.java
License:Apache License
@Override public void set(File file) throws FileNotFoundException, ReadException { if (!file.exists()) throw new FileNotFoundException("File not found: " + file.getAbsolutePath()); try {/*from w ww . j a va 2 s . c om*/ image = Image.getInstance(file.getAbsolutePath()); } catch (Exception e) { throw new ReadException(e); } int type = image.getOriginalType(); switch (type) { case Image.ORIGINAL_BMP: imageType = ImageType.BMP; break; case Image.ORIGINAL_GIF: imageType = ImageType.GIF; break; case Image.ORIGINAL_JPEG: case Image.ORIGINAL_JPEG2000: imageType = ImageType.JPG; break; case Image.ORIGINAL_PNG: imageType = ImageType.PNG; break; default: { logger.warn("Couldn't analyse format from {} or image type isn't supported.", file.getAbsolutePath()); imageType = null; } } }
From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java
License:Open Source License
public static void printCages(List<Container> cages, boolean printGroupsTreatments, boolean printTreatmentDesc, boolean whiteBackground) throws Exception { final int margin = 15; File f = File.createTempFile("cages__", ".pdf"); Document doc = new Document(PageSize.A4.rotate()); Image maleImg, femaleImg, nosexImg; try {/* www.jav a2 s. com*/ maleImg = Image.getInstance(CagePrinterPDF.class.getResource("male.png")); femaleImg = Image.getInstance(CagePrinterPDF.class.getResource("female.png")); nosexImg = Image.getInstance(CagePrinterPDF.class.getResource("nosex.png")); } catch (Exception e) { throw new Exception("Could not find images in the classpath: " + e); } FileOutputStream os = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(doc, os); doc.open(); PdfContentByte canvas = writer.getDirectContentUnder(); float tileW = (doc.getPageSize().getWidth()) / 4; float tileH = (doc.getPageSize().getHeight()) / 2; for (int i = 0; i < cages.size(); i++) { Container cage = cages.get(i); Study study = cage.getStudy(); Set<Group> groups = cage.getGroups(); Group group = cage.getGroup(); Set<Biosample> animals = new TreeSet<>(Biosample.COMPARATOR_NAME); animals.addAll(cage.getBiosamples()); //Find the treatments applied to this group Set<NamedTreatment> allTreatments = new LinkedHashSet<>(); for (Group gr : groups) { allTreatments.addAll(gr.getAllTreatments(-1)); } //Draw if (i % 8 == 0) { if (i > 0) doc.newPage(); drawCageSeparation(doc, canvas); } int col = (i % 8) % 4; int row = (i % 8) / 4; float x = margin + tileW * col; float x2 = x + tileW - margin; float baseY = tileH * row; float y; //Display Sex canvas.moveTo(tileW * col - 50, doc.getPageSize().getHeight() - (tileH * row + 50)); Image img = null; String sex = getMetadata(animals, "Sex"); if (study.isBlindAll()) { img = nosexImg; } else if (sex.equals("M")) { img = maleImg; } else if (sex.equals("F")) { img = femaleImg; } else if (sex.length() > 0) { img = nosexImg; } if (img != null) { img.scaleToFit(20, 20); img.setAbsolutePosition(tileW * (col + 1) - 33, doc.getPageSize().getHeight() - (tileH * row + 12 + margin)); doc.add(img); } if (group != null && group.getColor() != null && (study != null && !study.isBlind()) && !whiteBackground) { Color c = group.getColor(); canvas.saveState(); canvas.setRGBColorFill(c.getRed() / 3 + 170, c.getGreen() / 3 + 170, c.getBlue() / 3 + 170); canvas.rectangle(x - margin + 1, doc.getPageSize().getHeight() - baseY - tileH + 1, tileW - 2, tileH - 2); canvas.fill(); canvas.restoreState(); } Color treatmentColor = Color.BLACK; if (allTreatments.size() > 0 && !study.isBlind() && printGroupsTreatments) { int offset = 0; for (NamedTreatment t : allTreatments) { if (t.getColor() != null) { if (allTreatments.size() == 1) treatmentColor = new Color(t.getColor().getRed() / 2, t.getColor().getGreen() / 2, t.getColor().getBlue() / 2); canvas.saveState(); canvas.setColorStroke(Color.BLACK); canvas.setRGBColorFill(t.getColor().getRed(), t.getColor().getGreen(), t.getColor().getBlue()); y = baseY + 42 + 15 + 86 + 13 + 22 + 14 + 23 + 28; canvas.rectangle(x + 20 + offset * 5, doc.getPageSize().getHeight() - y - (offset % 2) * 4, 22, 22); canvas.fillStroke(); canvas.restoreState(); offset++; } } } canvas.beginText(); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false), 16f); canvas.showTextAligned(Element.ALIGN_LEFT, cage.getContainerId(), x, doc.getPageSize().getHeight() - (baseY + 23), 0); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, "Cp1252", false), 11f); y = 42 + baseY; canvas.showTextAligned(Element.ALIGN_LEFT, "Type: ", x, doc.getPageSize().getHeight() - y, 0); y += 15; canvas.showTextAligned(Element.ALIGN_LEFT, "Animals_ID: ", x, doc.getPageSize().getHeight() - y, 0); y += 86; canvas.showTextAligned(Element.ALIGN_LEFT, "Delivery date: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "PO Number: ", x, doc.getPageSize().getHeight() - y, 0); y += 22; canvas.showTextAligned(Element.ALIGN_LEFT, "Study: ", x, doc.getPageSize().getHeight() - y, 0); y += 14; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Group: ", x, doc.getPageSize().getHeight() - y, 0); y += 23; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Treatment: ", x, doc.getPageSize().getHeight() - y, 0); y += 50; canvas.showTextAligned(Element.ALIGN_LEFT, "License: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "Experimenter: ", x, doc.getPageSize().getHeight() - y, 0); canvas.endText(); y = 42 + baseY; print(canvas, study.isBlindAll() ? "Blinded" : getMetadata(animals, "Type"), x + 65, doc.getPageSize().getHeight() - y, x2, 11, 11, FontFactory.HELVETICA, Color.BLACK, 11f); y += 15; if (animals.size() <= 6) { int n = 0; for (Biosample animal : animals) { print(canvas, animal.getSampleId(), x + 75, doc.getPageSize().getHeight() - y - 12 * n, x2 - 50, 12, 12, FontFactory.HELVETICA, Color.BLACK, 11f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x2 - 60, doc.getPageSize().getHeight() - y - 12 * n, x2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 11f); } n++; } } else { int nPerRow = animals.size() / 2; int n = 0; for (Biosample animal : animals) { int nx = n / nPerRow; int ny = n % nPerRow; print(canvas, animal.getSampleId(), x + nx * (x2 - x) / 2, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA, Color.BLACK, 10f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x + (1 + nx) * (x2 - x) / 2 - 35, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 10f); } n++; } } y += 86; print(canvas, getMetadata(animals, "Delivery Date"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, getMetadata(animals, "PO Number"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 22; print(canvas, study.getStudyIdAndInternalId(), x + 40, doc.getPageSize().getHeight() - y, x2, 0, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 14; if (!study.isBlind() && printGroupsTreatments) print(canvas, getGroups(animals), x + 40, doc.getPageSize().getHeight() - y, x2, 22, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 23; if (!study.isBlind() && printGroupsTreatments) print(canvas, getTreatments(animals, printTreatmentDesc), x + 62, doc.getPageSize().getHeight() - y, x2, 50, printTreatmentDesc ? 9 : 12, FontFactory.HELVETICA, treatmentColor, printTreatmentDesc ? 9f : 10f); y += 50; print(canvas, study.getMetadataMap().get("LICENSENO"), x + 74, doc.getPageSize().getHeight() - y, x2, 15, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, study.getMetadataMap().get("EXPERIMENTER"), x + 74, doc.getPageSize().getHeight() - y, x2, 20, 10, FontFactory.HELVETICA, Color.BLACK, 10f); } doc.close(); os.close(); Desktop.getDesktop().open(f); try { Thread.sleep(500); } catch (Exception e) { } }
From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java
License:Open Source License
public static void convertHSSF2Pdf(Workbook wb, String header, File reportFile) throws Exception { assert wb != null; assert reportFile != null; //Precompute formula FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); for (int i = 0; i < wb.getNumberOfSheets(); i++) { Sheet sheet = wb.getSheetAt(i);/*w w w . ja v a 2 s . c o m*/ for (Row r : sheet) { for (Cell c : r) { if (c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { try { evaluator.evaluateFormulaCell(c); } catch (Exception e) { System.err.println(e); } } } } } File tmp = File.createTempFile("tmp_", ".xlsx"); try (OutputStream out = new BufferedOutputStream(new FileOutputStream(tmp))) { wb.write(out); } //Find page orientation int maxColumnsGlobal = 0; for (int sheetNo = 0; sheetNo < wb.getNumberOfSheets(); sheetNo++) { Sheet sheet = wb.getSheetAt(sheetNo); for (Iterator<Row> rowIterator = sheet.iterator(); rowIterator.hasNext();) { Row row = rowIterator.next(); maxColumnsGlobal = Math.max(maxColumnsGlobal, row.getLastCellNum()); } } Rectangle pageSize = maxColumnsGlobal < 10 ? PageSize.A4 : PageSize.A4.rotate(); Document pdfDocument = new Document(pageSize, 10f, 10f, 20f, 20f); PdfWriter writer = PdfWriter.getInstance(pdfDocument, new FileOutputStream(reportFile)); addHeader(writer, header); pdfDocument.open(); //we have two columns in the Excel sheet, so we create a PDF table with two columns //Note: There are ways to make this dynamic in nature, if you want to. //Loop through sheets for (int sheetNo = 0; sheetNo < wb.getNumberOfSheets(); sheetNo++) { Sheet sheet = wb.getSheetAt(sheetNo); //Loop through rows, to find number of columns int minColumns = 1000; int maxColumns = 0; for (Iterator<Row> rowIterator = sheet.iterator(); rowIterator.hasNext();) { Row row = rowIterator.next(); if (row.getFirstCellNum() >= 0) minColumns = Math.min(minColumns, row.getFirstCellNum()); if (row.getLastCellNum() >= 0) maxColumns = Math.max(maxColumns, row.getLastCellNum()); } if (maxColumns == 0) continue; //Loop through first rows, to find relative width float[] widths = new float[maxColumns]; int totalWidth = 0; for (int c = 0; c < maxColumns; c++) { int w = sheet.getColumnWidth(c); widths[c] = w; totalWidth += w; } for (int c = 0; c < maxColumns; c++) { widths[c] /= totalWidth; } //Create new page and a new chapter with the sheet's name if (sheetNo > 0) pdfDocument.newPage(); Chapter pdfSheet = new Chapter(sheet.getSheetName(), sheetNo + 1); PdfPTable pdfTable = null; PdfPCell pdfCell = null; boolean inTable = false; //Loop through cells, to create the content // boolean leftBorder = true; // boolean[] topBorder = new boolean[maxColumns+1]; for (int r = 0; r <= sheet.getLastRowNum(); r++) { Row row = sheet.getRow(r); //Check if we exited a table (empty line) if (row == null) { if (pdfTable != null) { addTable(pdfDocument, pdfSheet, totalWidth, widths, pdfTable); pdfTable = null; } inTable = false; continue; } //Check if we start a table (>MIN_COL_IN_TABLE columns) if (row.getLastCellNum() >= MIN_COL_IN_TABLE) { inTable = true; } if (!inTable) { //Process the data outside table, just add the text boolean hasData = false; Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); if (cell.getCellType() == Cell.CELL_TYPE_BLANK) continue; Chunk chunk = getChunk(wb, cell); pdfSheet.add(chunk); pdfSheet.add(new Chunk(" ")); hasData = true; } if (hasData) pdfSheet.add(Chunk.NEWLINE); } else { //Process the data in table if (pdfTable == null) { //Create table pdfTable = new PdfPTable(maxColumns); pdfTable.setWidths(widths); // topBorder = new boolean[maxColumns+1]; } int cellNumber = minColumns; // leftBorder = false; Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); for (; cellNumber < cell.getColumnIndex(); cellNumber++) { pdfCell = new PdfPCell(); pdfCell.setBorder(0); pdfTable.addCell(pdfCell); } Chunk phrase = getChunk(wb, cell); pdfCell = new PdfPCell(new Phrase(phrase)); pdfCell.setFixedHeight(row.getHeightInPoints() - 3); pdfCell.setNoWrap(!cell.getCellStyle().getWrapText()); pdfCell.setPaddingLeft(1); pdfCell.setHorizontalAlignment( cell.getCellStyle().getAlignment() == CellStyle.ALIGN_CENTER ? PdfPCell.ALIGN_CENTER : cell.getCellStyle().getAlignment() == CellStyle.ALIGN_RIGHT ? PdfPCell.ALIGN_RIGHT : PdfPCell.ALIGN_LEFT); pdfCell.setUseBorderPadding(false); pdfCell.setUseVariableBorders(false); pdfCell.setBorderWidthRight(cell.getCellStyle().getBorderRight() == 0 ? 0 : .5f); pdfCell.setBorderWidthBottom(cell.getCellStyle().getBorderBottom() == 0 ? 0 : cell.getCellStyle().getBorderBottom() > 1 ? 1 : .5f); pdfCell.setBorderWidthLeft(cell.getCellStyle().getBorderLeft() == 0 ? 0 : cell.getCellStyle().getBorderLeft() > 1 ? 1 : .5f); pdfCell.setBorderWidthTop(cell.getCellStyle().getBorderTop() == 0 ? 0 : cell.getCellStyle().getBorderTop() > 1 ? 1 : .5f); String color = cell.getCellStyle().getFillForegroundColorColor() == null ? null : ((XSSFColor) cell.getCellStyle().getFillForegroundColorColor()).getARGBHex(); if (color != null) pdfCell.setBackgroundColor(new Color(Integer.decode("0x" + color.substring(2)))); pdfTable.addCell(pdfCell); cellNumber++; } for (; cellNumber < maxColumns; cellNumber++) { pdfCell = new PdfPCell(); pdfCell.setBorder(0); pdfTable.addCell(pdfCell); } } //Custom code to add all images on the first sheet (works for reporting) if (sheetNo == 0 && row.getRowNum() == 0) { for (PictureData pd : wb.getAllPictures()) { try { Image pdfImg = Image.getInstance(pd.getData()); pdfImg.scaleToFit( pageSize.getWidth() * .8f - pageSize.getBorderWidthLeft() - pageSize.getBorderWidthRight(), pageSize.getHeight() * .8f - pageSize.getBorderWidthTop() - pageSize.getBorderWidthBottom()); pdfSheet.add(pdfImg); } catch (Exception e) { e.printStackTrace(); } } } } if (pdfTable != null) { addTable(pdfDocument, pdfSheet, totalWidth, widths, pdfTable); } pdfDocument.add(pdfSheet); } pdfDocument.close(); }
From source file:com.afrisoftech.hospinventory.mtrhreports.PurchaseReqInternalMtrhPdf.java
public void generatePdf(java.lang.String memNo) { java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try {/*ww w . j a v a 2 s . c o m*/ java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; // com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4,40,40,40,40); // com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4); com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); try { try { com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); // pdfWriter = com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); // System.out.println("Current Doc size 1 "+ pdfWriter.getCurrentDocumentSize()); String compName = null; String date = null; try { java.sql.Statement st6 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); // com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(new Phrase("Internal Requisition - Page:",pFontHeader ), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue)); // docPdf.setFooter(footer); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.open(); String Username = null; int numColumns = 9; try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); // java.lang.Object listofStaffNos[] = this.getListofStaffNos(); com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(6); // com.lowagie.text.Table table = new com.lowagie.text.Table(7); // table.endHeaders(); int headerwidths[] = { 15, 15, 30, 15, 15, 15 }; table1.setWidths(headerwidths); // if (docPdf.getPageNumber() > 1) { // table1.setHeaderRows(4); // } table1.setWidthPercentage((100)); table1.getDefaultCell().setBorder(Rectangle.BOTTOM); table1.getDefaultCell().setColspan(7); Phrase phrase = new Phrase(); // table.addCell(phrase); table1.getDefaultCell().setColspan(1); // table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()); //Image imgWaterMark = Image.getInstance(System.getProperty("company.watermark")); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table1.getDefaultCell().setFixedHeight(50); table1.addCell(Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo())); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table1.getDefaultCell().setFixedHeight(25); java.sql.Statement st3 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3 .executeQuery("SELECT DISTINCT hospital_name FROM pb_hospitalprofile"); while (rset3.next()) { table1.getDefaultCell().setColspan(6); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11); table1.addCell(phrase); } } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.add(table1); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } try { com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(10); table1.getDefaultCell().setPadding(3); int headerwidths1[] = { 24, 10, 8, 8, 6, 8, 6, 10, 12, 8 }; // table1.setWidths(headerwidths1); table1.setWidthPercentage((100)); table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); Phrase phrase = new Phrase("", pFontHeader); try { // java.sql.Statement st3 = conDB.createStatement(); // java.sql.Connection conDb = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/purchase","postgres","pilsiner"); // java.sql.Statement st3 = conDb.createStatement(); java.sql.Statement st3 = connectDB.createStatement(); //java.sql.Statement st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st11 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.Statement st5 = connectDB.createStatement(); java.sql.Statement st6 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3.executeQuery( "select hospital_name,box_no,main_telno||' '||other_telno,initcap(street),initcap(town),main_faxno,email,initcap(building_name),room_no from pb_hospitalprofile"); //java.sql.ResultSet rset2 = st2.executeQuery("select supplier_name,short_name,postal_address,tel1,initcap(street),initcap(avenue),fax_no,email_address,initcap(building_name) from st_suppliers WHERE supplier_name ilike '"+selectSupp+"'"); java.sql.ResultSet rset4 = st4.executeQuery( "select DISTINCT REQUISITION_no,date_due,cost_center, case when supplier is null then '-' else supplier end as supplier," + " received_requisation,reason,date,store_name FROM st_receive_requisation where REQUISITION_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); java.sql.ResultSet rset5 = st5.executeQuery( "select DISTINCT date_due from st_receive_requisation where requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); java.sql.ResultSet rset11 = st11.executeQuery( "select initcap(user_name) from st_receive_requisation where requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); while (rset11.next()) { Username = rset11.getObject(1).toString(); } table1.getDefaultCell().setBorderColor(java.awt.Color.white); while (rset4.next()) { table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(" ", pFontHeader); //table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("INTERNAL PURCHASE REQUISITION", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("FROM TEAM LEADER LOGISTICS", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("TO SUPPLY CHAIN MANAGER", pFontHeader5); table1.addCell(phrase); // table1.getDefaultCell().setColspan(10); // table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); // phrase = new Phrase("NUMBER KNH/SCM-MTCE STORES/......", pFontHeader5); // table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("PLEASE ORDER THE FOLLOWING MATERIALS/ITEMS", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); //table1.addCell(phrase); table1.getDefaultCell().setColspan(6); phrase = new Phrase("FROM : " + rset4.getObject(8).toString(), pFontHeader); table1.addCell(phrase); table1.getDefaultCell().setColspan(4); phrase = new Phrase("DATE: " + rset4.getObject(7).toString() + "PR NO: " + rset4.getObject(1).toString(), pFontHeader); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("TO : " + rset4.getObject(3).toString(), pFontHeader); table1.addCell(phrase); // table1.getDefaultCell().setColspan(10); // phrase = new Phrase(" " + rset4.getObject(2).toString(), pFontHeader); // table1.addCell(phrase); /* * table1.getDefaultCell().setColspan(5); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase(" ", pFontHeader); * table1.addCell(phrase); phrase = new * Phrase("PROCUREMENT METHOD : ", pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("REQUISITION NO: " + * rset4.getObject(1).toString(), pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("ACCOUNT NO: ", * pFontHeader); table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("REASON FOR PURCHASE " + * rset4.getObject(6).toString(), pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); * * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("", pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase("NAME OF THE SUPPLIER " + * rset4.getObject(4).toString(), pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("CONTRACT NO: ", * pFontHeader); table1.addCell(phrase); * */ } docPdf.add(table1); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } double Total = 0.00; double discount = 0.00; double vat = 0.00; double qty = 0.00; double price = 0.00; double value = 0.00; try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9); table.getDefaultCell().setPadding(3); int headerwidths[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table.setWidths(headerwidths); table.setWidthPercentage((100)); com.lowagie.text.pdf.PdfPTable table3 = new com.lowagie.text.pdf.PdfPTable(9); // table3.getDefaultCell().setPadding(3); int headerwidths3[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table3.setWidths(headerwidths3); table3.setWidthPercentage((100)); //table.getDefaultCell().setBorderColor(java.awt.Color.black); //table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setColspan(9); Phrase phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table3.getDefaultCell() .setBorder(Rectangle.BOTTOM | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP); table3.getDefaultCell().setColspan(1); phrase = new Phrase("NOs ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Item No/Code ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase("Item Description", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Units of Issue. ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Qty Required. ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Monthly Usage ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase("Remarks", pFontHeader); table3.addCell(phrase); // phrase = new Phrase("Est.Cost ", pFontHeader); // table3.addCell(phrase); // // phrase = new Phrase("Actual Cost", pFontHeader); // table3.addCell(phrase); // // phrase = new Phrase("Tender/Qtn Ref.", pFontHeader); // table3.addCell(phrase); phrase = new Phrase("", pFontHeader); //table.addCell(phrase); table3.setHeaderRows(1); // table3.getDefaultCell().setColspan(1); // // table3.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); String coment = ""; try { // java.sql.Statement st6 = connectDB.createStatement(); java.sql.Statement st1 = connectDB.createStatement(); java.sql.ResultSet rset1 = st1 .executeQuery("SELECT initcap(item_description),units,cos_glcode," + " quantity,price,round(quantity*price,2),mainstore_bal,terms,item_code,monthly_usage from st_receive_requisation" + " WHERE requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); table.getDefaultCell().setBorderColor(java.awt.Color.lightGray); while (rset1.next()) { // value = qty * price; cnt = cnt + 1; table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table3.getDefaultCell().setColspan(1); phrase = new Phrase("" + cnt, pFontHeader2); table3.getDefaultCell().setBorderColor(java.awt.Color.black); table3.addCell(phrase); table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(9).toString(), pFontHeader2); table3.getDefaultCell().setBorderColor(java.awt.Color.black); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset1.getObject(1).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(2).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(4).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); // JOptionPane.showMessageDialog(null, "this "+rset1.getObject(10).toString()); phrase = new Phrase(rset1.getObject(10).toString(), pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase(rset1.getObject(8).toString(), pFontHeader2); table3.addCell(phrase); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(4).toString()), pFontHeader2); // // table3.addCell(phrase); // // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(5).toString()), pFontHeader2); // table3.addCell(phrase); // // // System.out.println("Second "+docPdf.top()); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)), pFontHeader2); // // table3.addCell(phrase); // // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(7)), pFontHeader2); // // table3.addCell(phrase); // // // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // value = value + rset1.getDouble(6); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // // phrase = new Phrase(rset1.getObject(8).toString(), pFontHeader2); // // // table.addCell(phrase); // // coment = rset1.getObject(12).toString(); } table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell() .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT); table.getDefaultCell().setFixedHeight(350); table.addCell(table3); table.getDefaultCell().setFixedHeight(20); // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); // phrase = new Phrase("TOTAL COST", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf(value)), pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // table3.addCell(phrase); table.getDefaultCell().setColspan(9); table.getDefaultCell() .setBorder(Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.LEFT); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setBorder(Rectangle.TOP); table.addCell(phrase); //table.getDefaultCell().setBorder(Rectangle.TOP); /* * * * table.getDefaultCell().setColspan(6); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("Prepared By :" * +Username.toUpperCase(), pFontHeader); * * table.addCell(phrase); */ table.getDefaultCell().setColspan(3); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("PREPARED BY.................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("AIE HOLDER/USER.................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("APPROVED BY(TL LOGISTICS).................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); // table.getDefaultCell().setColspan(4); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Amount Voted..................................................", pFontHeader); // table.addCell(phrase); // // table.getDefaultCell().setColspan(5); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Vote Balance.........................................................", pFontHeader); // table.addCell(phrase); // // // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Vote Holder's Authority.................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................", pFontHeader); // // table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("SIGN..........................................................", pFontHeader); //table.addCell(phrase); table.getDefaultCell().setColspan(9); //table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("", pFontHeader); table.addCell(phrase); //phrase = new Phrase("FOR PROCUREMENT USE ONLY", pFontHeader); //table.addCell(phrase); //table.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM); //table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Approved/Not Approved.....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("ACTION:- I/C Supplies & Proc .....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Procurement Section.....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Stock Ctr/: D/Note.............................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Inv No.......................", pFontHeader); // // table.addCell(phrase); // // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign....................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date.......................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Time...........................", pFontHeader); // // table.addCell(phrase); /* * table.getDefaultCell().setColspan(5); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new * Phrase("REMARK___________________________________", * pFontHeader); * * table.addCell(phrase); * table.getDefaultCell().setColspan(4); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("DATE * RECEIVED____________________________", * pFontHeader); table.addCell(phrase); * * table.getDefaultCell().setColspan(5); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase(" ", pFontHeader); * table.addCell(phrase); * * table.getDefaultCell().setColspan(9); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); * phrase = new Phrase(" ", pFontHeader); * * table.addCell(phrase); * table.getDefaultCell().setBorder(Rectangle.TOP); * * table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); * * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("1. Original__________ Use * department", pFontHeader); * * table.addCell(phrase); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("2. Duplicate________ * Procurement office", pFontHeader); * * table.addCell(phrase); * * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("3. Triplicate_________ Book * copy", pFontHeader); * * table.addCell(phrase); */ docPdf.add(table); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } // } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } } catch (java.io.FileNotFoundException fnfExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage()); } } catch (com.lowagie.text.DocumentException lwDocexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage()); } // System.out.println("Current Doc size "+ pdfWriter.getCurrentDocumentSize()); docPdf.close(); com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile); } catch (java.io.IOException IOexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage()); } }
From source file:com.afrisoftech.hospinventory.mtrhreports.PurchaseReqInternalMtrhPdf1_.java
public void generatePdf(java.lang.String memNo) { java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try {// www . j a va2 s. c om java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; // com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4,40,40,40,40); // com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4); com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); try { try { com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); // pdfWriter = com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); // System.out.println("Current Doc size 1 "+ pdfWriter.getCurrentDocumentSize()); String compName = null; String date = null; try { java.sql.Statement st6 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); // com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(new Phrase("Internal Requisition - Page:",pFontHeader ), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue)); // docPdf.setFooter(footer); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.open(); String Username = null; int numColumns = 9; try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); // java.lang.Object listofStaffNos[] = this.getListofStaffNos(); com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(6); // com.lowagie.text.Table table = new com.lowagie.text.Table(7); // table.endHeaders(); int headerwidths[] = { 15, 15, 30, 15, 15, 15 }; table1.setWidths(headerwidths); // if (docPdf.getPageNumber() > 1) { // table1.setHeaderRows(4); // } table1.setWidthPercentage((100)); table1.getDefaultCell().setBorder(Rectangle.BOTTOM); table1.getDefaultCell().setColspan(7); Phrase phrase = new Phrase(); // table.addCell(phrase); table1.getDefaultCell().setColspan(1); // table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()); //Image imgWaterMark = Image.getInstance(System.getProperty("company.watermark")); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table1.getDefaultCell().setFixedHeight(50); table1.addCell(Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo())); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table1.getDefaultCell().setFixedHeight(25); java.sql.Statement st3 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3 .executeQuery("SELECT DISTINCT hospital_name FROM pb_hospitalprofile"); while (rset3.next()) { table1.getDefaultCell().setColspan(6); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11); table1.addCell(phrase); } } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.add(table1); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } try { com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(10); table1.getDefaultCell().setPadding(3); int headerwidths1[] = { 24, 10, 8, 8, 6, 8, 6, 10, 12, 8 }; // table1.setWidths(headerwidths1); table1.setWidthPercentage((100)); table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); Phrase phrase = new Phrase("", pFontHeader); try { // java.sql.Statement st3 = conDB.createStatement(); // java.sql.Connection conDb = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/purchase","postgres","pilsiner"); // java.sql.Statement st3 = conDb.createStatement(); java.sql.Statement st3 = connectDB.createStatement(); //java.sql.Statement st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st11 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.Statement st5 = connectDB.createStatement(); java.sql.Statement st6 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3.executeQuery( "select hospital_name,box_no,main_telno||' '||other_telno,initcap(street),initcap(town),main_faxno,email,initcap(building_name),room_no from pb_hospitalprofile"); //java.sql.ResultSet rset2 = st2.executeQuery("select supplier_name,short_name,postal_address,tel1,initcap(street),initcap(avenue),fax_no,email_address,initcap(building_name) from st_suppliers WHERE supplier_name ilike '"+selectSupp+"'"); java.sql.ResultSet rset4 = st4.executeQuery( "select DISTINCT REQUISITION_no,date_due,cost_center, case when supplier is null then '-' else supplier end as supplier," + " received_requisation,reason,date,store_name,requisation FROM st_receive_requisation where REQUISITION_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); java.sql.ResultSet rset5 = st5.executeQuery( "select DISTINCT date_due from st_receive_requisation where requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); java.sql.ResultSet rset11 = st11.executeQuery( "select initcap(user_name) from st_receive_requisation where requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); while (rset11.next()) { Username = rset11.getObject(1).toString(); } table1.getDefaultCell().setBorderColor(java.awt.Color.white); while (rset4.next()) { table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(" ", pFontHeader); //table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("INTERNAL PURCHASE REQUISITION", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("FROM TEAM LEADER LOGISTICS- " + Department + " ", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("TO SUPPLY CHAIN MANAGER", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("NUMBER KNH/" + Department + "/ " + OrderNo, pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("PLEASE ORDER THE FOLLOWING MATERIALS/ITEMS", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); //table1.addCell(phrase); table1.getDefaultCell().setColspan(6); phrase = new Phrase("Requisitioning Store : " + rset4.getObject(3).toString(), pFontHeader); table1.addCell(phrase); table1.getDefaultCell().setColspan(4); phrase = new Phrase("DATE: " + rset4.getObject(9).toString(), pFontHeader); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Receiving Store : " + rset4.getObject(8).toString(), pFontHeader); table1.addCell(phrase); // table1.getDefaultCell().setColspan(10); // phrase = new Phrase(" " + rset4.getObject(2).toString(), pFontHeader); // table1.addCell(phrase); /* * table1.getDefaultCell().setColspan(5); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase(" ", pFontHeader); * table1.addCell(phrase); phrase = new * Phrase("PROCUREMENT METHOD : ", pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("REQUISITION NO: " + * rset4.getObject(1).toString(), pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("ACCOUNT NO: ", * pFontHeader); table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("REASON FOR PURCHASE " + * rset4.getObject(6).toString(), pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); * * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("", pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase("NAME OF THE SUPPLIER " + * rset4.getObject(4).toString(), pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("CONTRACT NO: ", * pFontHeader); table1.addCell(phrase); * */ } docPdf.add(table1); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } double Total = 0.00; double discount = 0.00; double vat = 0.00; double qty = 0.00; double price = 0.00; double value = 0.00; try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9); table.getDefaultCell().setPadding(3); int headerwidths[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table.setWidths(headerwidths); table.setWidthPercentage((100)); com.lowagie.text.pdf.PdfPTable table3 = new com.lowagie.text.pdf.PdfPTable(9); // table3.getDefaultCell().setPadding(3); int headerwidths3[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table3.setWidths(headerwidths3); table3.setWidthPercentage((100)); //table.getDefaultCell().setBorderColor(java.awt.Color.black); //table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setColspan(9); Phrase phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table3.getDefaultCell() .setBorder(Rectangle.BOTTOM | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP); table3.getDefaultCell().setColspan(1); phrase = new Phrase("NOs ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Item No/Code ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase("Item Description", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Units of Issue. ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Qty Required. ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Store Balance ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase("Monthly Usage", pFontHeader); table3.addCell(phrase); // table3.getDefaultCell().setColspan(1); // phrase = new Phrase(" ", pFontHeader); // table3.addCell(phrase); // phrase = new Phrase("Est.Cost ", pFontHeader); // table3.addCell(phrase); // // phrase = new Phrase("Actual Cost", pFontHeader); // table3.addCell(phrase); // // phrase = new Phrase("Tender/Qtn Ref.", pFontHeader); // table3.addCell(phrase); phrase = new Phrase("", pFontHeader); //table.addCell(phrase); table3.setHeaderRows(1); // table3.getDefaultCell().setColspan(1); // // table3.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); String coment = ""; try { // java.sql.Statement st6 = connectDB.createStatement(); java.sql.Statement st1 = connectDB.createStatement(); java.sql.ResultSet rset1 = st1 .executeQuery("SELECT initcap(item_description),units,cos_glcode," + " quantity,price,round(quantity*price,2),mainstore_bal,terms,item_code,monthly_usage from st_receive_requisation" + " WHERE requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); table.getDefaultCell().setBorderColor(java.awt.Color.lightGray); while (rset1.next()) { // value = qty * price; cnt = cnt + 1; table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table3.getDefaultCell().setColspan(1); phrase = new Phrase("" + cnt, pFontHeader2); table3.getDefaultCell().setBorderColor(java.awt.Color.black); table3.addCell(phrase); table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(9).toString(), pFontHeader2); table3.getDefaultCell().setBorderColor(java.awt.Color.black); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset1.getObject(1).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(2).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(4).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); // JOptionPane.showMessageDialog(null, "this "+rset1.getObject(10).toString()); phrase = new Phrase(rset1.getObject(7).toString(), pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); //change phrase = new Phrase(rset1.getObject(10).toString(), pFontHeader2); table3.addCell(phrase); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(4).toString()), pFontHeader2); // // table3.addCell(phrase); // // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(5).toString()), pFontHeader2); // table3.addCell(phrase); // // // System.out.println("Second "+docPdf.top()); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)), pFontHeader2); // // table3.addCell(phrase); // // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(7)), pFontHeader2); // // table3.addCell(phrase); // // // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // value = value + rset1.getDouble(6); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // // phrase = new Phrase(rset1.getObject(8).toString(), pFontHeader2); // // // table.addCell(phrase); // // coment = rset1.getObject(12).toString(); } // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); // // table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT); // table.getDefaultCell().setFixedHeight(350); // table.addCell(table3); // // table.getDefaultCell().setFixedHeight(20); // //// // // // table.getDefaultCell().setColspan(9); // table.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.LEFT); // phrase = new Phrase(" ", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setBorder(Rectangle.TOP); // // table.addCell(phrase); //table.getDefaultCell().setBorder(Rectangle.TOP); /* * * * table.getDefaultCell().setColspan(6); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("Prepared By :" * +Username.toUpperCase(), pFontHeader); * * table.addCell(phrase); */ // table.getDefaultCell().setColspan(3); // table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("PREPARED BY.................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................\n", pFontHeader); // table.addCell(phrase); // // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("AIE HOLDER/USER.................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................\n", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("APPROVED BY(TL LOGISTICS).................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................\n", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(4); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Amount Voted..................................................", pFontHeader); // table.addCell(phrase); // // table.getDefaultCell().setColspan(5); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Vote Balance.........................................................", pFontHeader); // table.addCell(phrase); // // // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Vote Holder's Authority.................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................", pFontHeader); // // table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("SIGN..........................................................", pFontHeader); //table.addCell(phrase); table.getDefaultCell().setColspan(9); //table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("", pFontHeader); table.addCell(phrase); //phrase = new Phrase("FOR PROCUREMENT USE ONLY", pFontHeader); //table.addCell(phrase); //table.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM); //table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Approved/Not Approved.....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("ACTION:- I/C Supplies & Proc .....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Procurement Section.....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Stock Ctr/: D/Note.............................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Inv No.......................", pFontHeader); // // table.addCell(phrase); // // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign....................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date.......................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Time...........................", pFontHeader); // // table.addCell(phrase); /* * table.getDefaultCell().setColspan(5); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new * Phrase("REMARK___________________________________", * pFontHeader); * * table.addCell(phrase); * table.getDefaultCell().setColspan(4); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("DATE * RECEIVED____________________________", * pFontHeader); table.addCell(phrase); * * table.getDefaultCell().setColspan(5); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase(" ", pFontHeader); * table.addCell(phrase); * * table.getDefaultCell().setColspan(9); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); * phrase = new Phrase(" ", pFontHeader); * * table.addCell(phrase); * table.getDefaultCell().setBorder(Rectangle.TOP); * * table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); * * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("1. Original__________ Use * department", pFontHeader); * * table.addCell(phrase); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("2. Duplicate________ * Procurement office", pFontHeader); * * table.addCell(phrase); * * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("3. Triplicate_________ Book * copy", pFontHeader); * * table.addCell(phrase); */ docPdf.add(table); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } // } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } try { Phrase phrase = new Phrase(); com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9); table.getDefaultCell().setPadding(3); int headerwidths[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table.setWidths(headerwidths); table.setWidthPercentage((100)); table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell() .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT); table.getDefaultCell().setFixedHeight(350); table.addCell(table); table.getDefaultCell().setFixedHeight(20); // table.getDefaultCell().setColspan(9); table.getDefaultCell() .setBorder(Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.LEFT); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setBorder(Rectangle.TOP); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("PREPARED BY.................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("AIE HOLDER/USER.................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("APPROVED BY(TL LOGISTICS).................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); //down docPdf.add(table); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } } catch (java.io.FileNotFoundException fnfExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage()); } } catch (com.lowagie.text.DocumentException lwDocexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage()); } // System.out.println("Current Doc size "+ pdfWriter.getCurrentDocumentSize()); docPdf.close(); com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile); } catch (java.io.IOException IOexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage()); } }
From source file:com.afrisoftech.reports.PatientRegFormPdf.java
public void generatePdf(String patientName, String patientAge, String PatientGender, String patientNationality, String patientIDPassport, String placeofBirth, String patientOccupation, String maritalStatus, String patientReligion, String patientTelephone, String patientEmail, String patientVillage, String patientLocation, String patientHomeCounty, String patientResidenceCounty, String patientNOK, String patientRelation, String patientNOKTelephone, String patientReferFrom, String bookingDate, String specialtyClinic, String statusNHIF, String NHIFNumber, String educationLevel, String employerTelephone, String patientEmployer, String paidAmount, String receiptNumber, String cSheetNo, String invoiceNumber, String interviewerName, String interviewDate, String servicePoint, String unitNumber, String patientNumber, String admissionWard, String admissionDate, String admissionType, String claimNumber, java.util.Date date, String gender, String typeofAccident, String modeofArrival, String nameofPoliceOfficer, String policeForceNO, String policeStationAccident, String dateAccident, String nameofDriver, String accidentVehicleNo, String driverLicenceNo, String driversIDNo, String registrationTimes) { java.util.Date date111 = date; java.lang.String formLabel = null; if (admissionWard.toCharArray().length < 1) { formLabel = "PATIENT REGISTRATION FORM"; } else {// w w w .java 2s.co m formLabel = "PATIENT ADMISSION FORM"; } java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try { java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; //com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); try { try { PdfWriter writer = com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter( new Phrase(formLabel + " : ", pFontHeader2), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue)); docPdf.setFooter(footer); docPdf.open(); java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6); int headerwidths[] = { 16, 16, 16, 16, 16, 16 }; table.setWidths(headerwidths); table.setWidthPercentage((105)); com.lowagie.text.pdf.PdfPTable table2 = new com.lowagie.text.pdf.PdfPTable(2); int headerwidths2[] = { 30, 70 }; table2.setWidths(headerwidths2); table2.setWidthPercentage((100)); table2.getDefaultCell().setFixedHeight(50); //phrase = new Phrase("", pFontHeader1); //table.addCell(phrase); table2.getDefaultCell().setColspan(2); table2.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()); img.scalePercent(50); // img.sc//aleAbsolute(200, 200); table2.addCell(img); String compName = null; String District = null; String Region = null; String date2 = null; try { java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.ResultSet rset2 = st3.executeQuery( "SELECT hospital_name,district_branch,region FROM pb_hospitalprofile"); java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date"); while (rset2.next()) { compName = dbObject.getDBObject(rset2.getObject(1), ""); District = dbObject.getDBObject(rset2.getObject(2), ""); Region = dbObject.getDBObject(rset2.getObject(3), ""); } while (rset4.next()) { date2 = dbObject.getDBObject(rset4.getObject(1), ""); } } catch (java.sql.SQLException ex) { javax.swing.JOptionPane.showMessageDialog(new java.awt.Frame(), ex.getMessage()); ex.printStackTrace(); } table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table.getDefaultCell().set Phrase phrase = new Phrase(compName.toUpperCase(), pFontHeader3); table2.addCell(phrase); table.addCell(table2); // painting the logo table.setWidths(headerwidths); table.setWidthPercentage((105)); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(5); phrase = new Phrase(formLabel, pFontHeader2); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); table.getDefaultCell().setColspan(1); phrase = new Phrase("FORM: 260", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); // table.getDefaultCell().set phrase = new Phrase("1. PATIENT PERSONAL DETAILS", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); dbObject = new com.afrisoftech.lib.DBObject(); phrase = new Phrase("Patient Name: " + patientName, pFontHeader); table.addCell(phrase); phrase = new Phrase("Age: " + dbObject.getDBObject((Object) patientAge, "") + "", pFontHeader); table.addCell(phrase); phrase = new Phrase("Nationality: " + dbObject.getDBObject(patientNationality, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("ID-Passport: " + dbObject.getDBObject(patientIDPassport, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Place of Birth: " + dbObject.getDBObject(placeofBirth, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Occupation: " + dbObject.getDBObject(patientOccupation, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Marital Status: " + dbObject.getDBObject(maritalStatus, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Religion: " + dbObject.getDBObject(patientReligion, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Patient Tel.: " + dbObject.getDBObject(patientTelephone, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Patient Email.: " + dbObject.getDBObject(patientEmail, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Patient Gender.: " + dbObject.getDBObject(gender, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Registration Time : " + dbObject.getDBObject(registrationTimes, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("2. PATIENT RESIDENCE", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Home Village: " + dbObject.getDBObject(patientVillage, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Residence: " + dbObject.getDBObject(patientLocation, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("County of Birth: " + dbObject.getDBObject(patientHomeCounty, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase( "County of Residence: " + dbObject.getDBObject(patientResidenceCounty, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("3. NEXT OF KIN", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Next of Kin: " + dbObject.getDBObject(patientNOK, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Relationship: " + dbObject.getDBObject(patientRelation, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("NOK Telephone: " + dbObject.getDBObject(patientNOKTelephone, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("4. CURRENT ATTENDANCE AT FACILITY", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Referred From: " + dbObject.getDBObject(patientReferFrom, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Appointment Date: " + dbObject.getDBObject(date111, ""), pFontHeadercolor); table.addCell(phrase); phrase = new Phrase("Specialty Clinic: " + dbObject.getDBObject(specialtyClinic, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("5. PATIENT SOCIAL ECONOMIC HISTORY", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("NHIF Registered: " + dbObject.getDBObject(statusNHIF, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("NHIF No.: " + dbObject.getDBObject(NHIFNumber, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Education Level: " + dbObject.getDBObject(educationLevel, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Employer: " + dbObject.getDBObject(patientEmployer, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Telephone: " + dbObject.getDBObject(employerTelephone, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("6. DEPOSITS AND OTHER PAYMENTS", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Amount Paid: " + dbObject.getDBObject(paidAmount, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Receipt No.: " + dbObject.getDBObject(receiptNumber, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("C-Sheet No.: " + dbObject.getDBObject(cSheetNo, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Invoice Number: " + dbObject.getDBObject(invoiceNumber, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(4); phrase = new Phrase("NHIF Claim No.: " + dbObject.getDBObject(claimNumber, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); // table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("7. INTERVIEWERS INFORMATION", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Interviewer: " + dbObject.getDBObject(interviewerName, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Date: " + dbObject.getDBObject(interviewDate, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Service Point: " + dbObject.getDBObject(servicePoint, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("8. ADMISSION INFORMATION", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Admission Ward: " + dbObject.getDBObject(admissionWard, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Admission Date: " + dbObject.getDBObject(admissionDate, ""), pFontHeadercolor); table.addCell(phrase); phrase = new Phrase("Admission Type: " + dbObject.getDBObject(admissionType, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); ///RTA DETAILS if (typeofAccident.length() > 0 || modeofArrival.length() > 0 || nameofPoliceOfficer.length() > 0 || policeForceNO.length() > 0 || policeStationAccident.length() > 0 || dateAccident.length() > 0 || nameofDriver.length() > 0 || accidentVehicleNo.length() > 0 || driverLicenceNo.length() > 0 || driversIDNo.length() > 0) { table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("RTA DETAILS : ", pFontHeader2); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject("Type of Accident:- " + typeofAccident, "") + "" + dbObject.getDBObject(". MODE of ARRIVAL:-" + modeofArrival, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject("Name Of Police Officer :- " + nameofPoliceOfficer, "") + "." + "" + dbObject .getDBObject(" Police Officer Force No:-" + policeForceNO, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject( "Police Station Accident Scene :- " + policeStationAccident, "") + ". " + dbObject.getDBObject("Accident Date:-" + dateAccident, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject("Name of Driver:- " + nameofDriver, "") + dbObject .getDBObject(". Accident Vehicle NO:-" + accidentVehicleNo, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( "Driving Licence No:- " + dbObject.getDBObject(driverLicenceNo, "") + ". Driver's ID No :-" + dbObject.getDBObject(driversIDNo, ""), pFontHeader); table.addCell(phrase); } ///RTA END table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setBorder(PdfCell.RECTANGLE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" Patient Number : ".toUpperCase() + dbObject.getDBObject(patientNumber, "").toUpperCase(), pFontHeader3); table.addCell(phrase); // phrase = new Phrase(" ", pFontHeader); // table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Unit Number : ".toUpperCase() + dbObject.getDBObject(unitNumber, "").toUpperCase(), pFontHeader2); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); //PdfWriter writer = PdfWriter.getInstance(docPdf, new FileOutputStream(tempFile)); PdfContentByte cb = writer.getDirectContent(); Barcode128 code128 = new Barcode128(); code128.setCode(patientNumber.toUpperCase() + " " + patientName.toUpperCase()); code128.setBarHeight(16); code128.setTextAlignment(Element.ALIGN_LEFT); docPdf.add(table); docPdf.add(code128.createImageWithBarcode(cb, null, null)); // docPdf.add(new com.itextpdf.text.Paragraph("Barcode QRCode")); // BarcodeQRCode qrcode = new BarcodeQRCode(patientNumber.toUpperCase() + " " + patientName.toUpperCase(), 1, 1, null); // com.itextpdf.text.Image qrimg = qrcode.getImage(); // docPdf.add(qrimg); // docPdf.add(table); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } } catch (java.io.FileNotFoundException fnfExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage()); } } catch (com.lowagie.text.DocumentException lwDocexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage()); } docPdf.close(); com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile); } catch (java.io.IOException IOexec) { IOexec.printStackTrace(); javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage()); } }