List of usage examples for com.itextpdf.text Element ALIGN_MIDDLE
int ALIGN_MIDDLE
To view the source code for com.itextpdf.text Element ALIGN_MIDDLE.
Click Source Link
From source file:presentation.frmReportForm.java
private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateActionPerformed Date dateNow = new Date(); SimpleDateFormat df = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss"); System.out.println(dtcMonthChooser.getMonth()); System.out.println(dtcYearChooser.getYear()); if (radInMonth.isSelected()) { List<Transfer> transferList = new ArrayList<>(); transferList = empObj.searchRecordByMonth(dtcMonthChooser.getMonth() + 1, dtcYearChooser.getYear()); Document document = new Document(); try {/*www. ja v a 2 s . c o m*/ Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph( "Transfer records at " + (dtcMonthChooser.getMonth() + 1) + "/" + dtcYearChooser.getYear(), FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radInDateRange.isSelected()) { try { List<Transfer> transferList = new ArrayList<>(); java.sql.Date fromDateSql = formatDateForSearching(dtcFromDate.getDate()); java.sql.Date toDateSql = formatDateForSearching(dtcToDate.getDate()); transferList = empObj.searchRecordByDate(fromDateSql, toDateSql); Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy"); String fromDate = df2.format(dtcFromDate.getDate()); String toDate = df2.format(dtcToDate.getDate()); Paragraph slashPara = new Paragraph("Transfer records from " + fromDate + " to " + toDate, FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } catch (ParseException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radInProject.isSelected()) { String fromProjectId = (String) cbxFromProject.getSelectedItem(); String toProjectId = (String) cbxToProject.getSelectedItem(); List<Transfer> transferList = new ArrayList<>(); String andOr = ""; if (cbxAndOr.getSelectedItem().equals("And")) { andOr = "and"; transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr); } else { andOr = "or"; transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr); } Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph( "Transfer records from Project ID " + fromProjectId + " " + andOr + " " + toProjectId, FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radAllRecord.isSelected()) { List<Transfer> transferList = new ArrayList<>(); transferList = empObj.searchAllRecord(); Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph("All transfer records", FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:psManage.StructSheet.java
public void createPdf(String mainTitle, String subTitle, String url, String userName, //String scanType, String comment,//from w w w . j a v a2s .com //String thisPassCode, String passCodeA, String passCodeB, String fileDir, Boolean noBarCodePrint) throws IOException, DocumentException, RuntimeException { Document document = null; try { // step 1 document = new Document(PageSize.A4, 60, 50, 50, 35); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileDir)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); /* Properties props = new Properties(); String jarPath = System.getProperty("java.class.path"); String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator)+1); FontFactory.registerDirectory("/res"); FontFactory.register("ipag.ttf"); Font ipaGothic = FontFactory.getFont("ipag", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); //10 is the size InputStream is = getClass().getResourceAsStream("/res/ipag.ttf"); */ Properties props = new Properties(); String jarPath = System.getProperty("java.class.path"); String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator) + 1); System.out.println(jarPath); System.out.println(dirPath); System.out.println(System.getProperty("user.dir")); Font ipaGothic = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 11); Font ipaGothic14 = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 14); //?(2) PdfPTable pdfPTable = new PdfPTable(2); pdfPTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); pdfPTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.getDefaultCell().setFixedHeight(150); pdfPTable.setWidthPercentage(100f); int pdfPTableWidth[] = { 10, 90 }; pdfPTable.setWidths(pdfPTableWidth); PdfPCell cell_1_1 = new PdfPCell(new Paragraph("??", ipaGothic)); cell_1_1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_1_1.setHorizontalAlignment(Element.ALIGN_CENTER); cell_1_1.setFixedHeight(50); PdfPCell cell_1_2 = new PdfPCell(new Paragraph(mainTitle, ipaGothic)); cell_1_2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_1_2.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell_2_1 = new PdfPCell(new Paragraph("", ipaGothic)); cell_2_1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_2_1.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell_2_2 = new PdfPCell(new Paragraph(subTitle, ipaGothic)); cell_2_2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_2_2.setHorizontalAlignment(Element.ALIGN_CENTER); cell_2_2.setFixedHeight(50); pdfPTable.addCell(cell_1_1); pdfPTable.addCell(cell_1_2); pdfPTable.addCell(cell_2_1); pdfPTable.addCell(cell_2_2); PdfPCell cellUrlKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellUrlKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlKey.setRowspan(2); pdfPTable.addCell(cellUrlKey); PdfPCell cellUrlValue = new PdfPCell(new Paragraph(url, ipaGothic)); Chunk chunk = new Chunk(url, ipaGothic); // ?????????????? System.out.println("??" + chunk.getWidthPoint()); cellUrlValue.setVerticalAlignment(Element.ALIGN_MIDDLE); if (chunk.getWidthPoint() > 410) { // ?????????? cellUrlValue.setHorizontalAlignment(Element.ALIGN_LEFT); } else { // ????????? cellUrlValue.setHorizontalAlignment(Element.ALIGN_CENTER); } cellUrlValue.setFixedHeight(50); pdfPTable.addCell(cellUrlValue); if (url.length() != 0 && !noBarCodePrint) { /* ? BarcodeQRCode qr = new BarcodeQRCode(url, 50, 50, null); PdfPCell cellUrlValueQr = new PdfPCell(qr.getImage()); cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValueQr.setFixedHeight(80); pdfPTable.addCell(cellUrlValueQr); */ Image image = ZxingUti.getQRCode(url); // SHIFT_JIS com.itextpdf.text.Image iTextImage = com.itextpdf.text.Image.getInstance(image, null); PdfPCell cell = new PdfPCell(iTextImage); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setFixedHeight(100); pdfPTable.addCell(cell); // SIFT_JIS } else { PdfPCell cellUrlValueQr = new PdfPCell(new Paragraph("", ipaGothic)); cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValueQr.setFixedHeight(80); pdfPTable.addCell(cellUrlValueQr); } PdfPCell cellUserNameKey = new PdfPCell(new Paragraph("", ipaGothic)); cellUserNameKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameKey.setRowspan(2); pdfPTable.addCell(cellUserNameKey); PdfPCell cellUserNameValue = new PdfPCell(new Paragraph(userName, ipaGothic14)); cellUserNameValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValue.setFixedHeight(30); pdfPTable.addCell(cellUserNameValue); if (userName.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(userName); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellUserNameValueBc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValueBc.setFixedHeight(80); pdfPTable.addCell(cellUserNameValueBc); } else { PdfPCell cellUserNameValueBc = new PdfPCell(new Paragraph("---", ipaGothic)); cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValueBc.setFixedHeight(80); pdfPTable.addCell(cellUserNameValueBc); } PdfPCell cellPassCodeKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellPassCodeKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeKey.setRowspan(3); pdfPTable.addCell(cellPassCodeKey); PdfPCell cellPassCodeValue = new PdfPCell(new Paragraph(passCodeA + passCodeB, ipaGothic14)); cellPassCodeValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeValue.setFixedHeight(30); pdfPTable.addCell(cellPassCodeValue); if (passCodeA.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(passCodeA); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellPassCodeA_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeA_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeA_Bc); } else { PdfPCell cellPassCodeA_Bc = new PdfPCell(new Paragraph("---", ipaGothic)); cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeA_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeA_Bc); } if (passCodeB.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(passCodeB); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellPassCodeB_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeB_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeB_Bc); } else { PdfPCell cellPassCodeB_Bc = new PdfPCell(new Paragraph("---", ipaGothic)); cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeB_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeB_Bc); } PdfPCell cellCommentKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellCommentKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellCommentKey.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cellCommentKey); PdfPCell cellCommentValue = new PdfPCell(new Paragraph(comment, ipaGothic)); cellCommentValue.setVerticalAlignment(Element.ALIGN_TOP); cellCommentValue.setHorizontalAlignment(Element.ALIGN_LEFT); cellCommentValue.setFixedHeight(150); pdfPTable.addCell(cellCommentValue); PdfPCell cellIssueKey = new PdfPCell(new Paragraph("", ipaGothic)); cellIssueKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellIssueKey.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cellIssueKey); Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm"); String strDate = sdf.format(cal.getTime()); PdfPCell cellIssueValue = new PdfPCell(new Paragraph(strDate, ipaGothic)); cellIssueValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellIssueValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellIssueValue.setFixedHeight(20); pdfPTable.addCell(cellIssueValue); //?? document.add(pdfPTable); /* // CODE 128 document.add(new Paragraph("?? : " + mainTitle, ipaGothic)); document.add(new Paragraph(" : " + subTitle, ipaGothic)); document.add(new Paragraph("-------------------------------------------------------")); document.add(new Paragraph(" " + strDate)); document.add(new Paragraph("-------------------------------------------------------")); BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.EMBEDDED); Font font = new Font(bf, 12); document.add(new Paragraph("", ipaGothic)); document.add(new Paragraph(url, ipaGothic)); code128.setCode(url); code128.setFont(bf); code128.setX(1); //document.add(code128.createImageWithBarcode(cb, null, null)); document.add(new Paragraph("USER", ipaGothic)); if (userName.length() != 0) { document.add(new Paragraph(userName, ipaGothic)); code128.setCode(userName); code128.setFont(bf); code128.setBarHeight(40f); document.add(code128.createImageWithBarcode(cb, null, null)); } document.add(new Paragraph("CODE", ipaGothic)); if (passCode.length() != 0) { document.add(new Paragraph(passCode, ipaGothic)); code128.setCode(passCode); code128.setFont(bf); document.add(code128.createImageWithBarcode(cb, null, null)); } document.add(new Paragraph("?", ipaGothic)); document.add(new Paragraph(comment, ipaGothic)); */ // step 5 document.close(); } catch (RuntimeException ex) { document.close(); throw ex; } }
From source file:ro.nextreports.engine.exporter.PdfExporter.java
License:Apache License
private PdfPCell renderPdfCell(BandElement bandElement, Object value, int gridRow, int rowSpan, int colSpan, boolean image, int column) { Map<String, Object> style = buildCellStyleMap(bandElement, value, gridRow, column, colSpan); FontFactoryImp fact = new FontFactoryImp(); com.itextpdf.text.Font fnt;//from w w w. j a v a 2s. c o m if (bandElement != null) { fontName = (String) style.get(StyleFormatConstants.FONT_NAME_KEY); int size = ((Float) style.get(StyleFormatConstants.FONT_SIZE)).intValue(); fnt = getFont(size); } else { fnt = getFont(10); } PdfPCell cell; if (image) { if (value == null) { cell = new PdfPCell(new Phrase(IMAGE_NOT_FOUND)); } else { ImageBandElement ibe = (ImageBandElement) bandElement; try { byte[] imageBytes = getImage((String) value); cell = getImageCell(ibe, imageBytes, column, colSpan); } catch (Exception e) { cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED)); } } } else if (bandElement instanceof HyperlinkBandElement) { Hyperlink hyperlink = ((HyperlinkBandElement) bandElement).getHyperlink(); Anchor anchor = new Anchor(hyperlink.getText(), fnt); anchor.setReference(hyperlink.getUrl()); Phrase ph = new Phrase(); ph.add(anchor); cell = new PdfPCell(ph); } else if (bandElement instanceof ReportBandElement) { Report report = ((ReportBandElement) bandElement).getReport(); ExporterBean eb = null; try { eb = getSubreportExporterBean(report); PdfExporter subExporter = new PdfExporter(eb); subExporter.export(); PdfPTable innerTable = subExporter.getTable(); cell = new PdfPCell(innerTable); } catch (Exception e) { cell = new PdfPCell(); e.printStackTrace(); } finally { if ((eb != null) && (eb.getResult() != null)) { eb.getResult().close(); } } } else if ((bandElement instanceof VariableBandElement) && (VariableFactory .getVariable(((VariableBandElement) bandElement).getVariable()) instanceof TotalPageNoVariable)) { try { cell = new PdfPCell(Image.getInstance(total)); } catch (BadElementException e) { cell = new PdfPCell(new Phrase("NA")); } } else if (bandElement instanceof ImageColumnBandElement) { try { String v = StringUtil.getValueAsString(value, null); if (StringUtil.BLOB.equals(v)) { cell = new PdfPCell(new Phrase(StringUtil.BLOB)); } else { byte[] bytes = StringUtil.decodeImage(v); cell = getImageCell(bandElement, bytes, column, colSpan); } } catch (Exception e) { e.printStackTrace(); cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED)); } } else { String stringValue; if (style.containsKey(StyleFormatConstants.PATTERN)) { stringValue = StringUtil.getValueAsString(value, (String) style.get(StyleFormatConstants.PATTERN), getReportLanguage()); } else { stringValue = StringUtil.getValueAsString(value, null, getReportLanguage()); } if (stringValue == null) { stringValue = ""; } if (stringValue.startsWith("<html>")) { StringReader reader = new StringReader(stringValue); List<Element> elems = new ArrayList<Element>(); try { elems = HTMLWorker.parseToList(reader, new StyleSheet()); Phrase ph = new Phrase(); for (int i = 0; i < elems.size(); i++) { Element elem = (Element) elems.get(i); ph.add(elem); } cell = new PdfPCell(ph); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Phrase ph = new Phrase(stringValue, fnt); cell = new PdfPCell(ph); } } else { Phrase ph = new Phrase(stringValue, fnt); cell = new PdfPCell(ph); } } cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setUseDescender(true); // needed for a cell without padding cell.setMinimumHeight(MINIMUM_HEIGHT); // needed if there is a row in which all cells are empty if (bandElement != null) { cell.setRotation(bandElement.getTextRotation()); } if (colSpan > 1) { cell.setColspan(colSpan); } if (rowSpan > 1) { cell.setRowspan(rowSpan); } if (style != null) { updateFont(style, fnt); if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) { Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR); cell.setBackgroundColor(new BaseColor(val)); } if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) { if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); } } if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) { if (StyleFormatConstants.VERTICAL_ALIGN_TOP .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_TOP); } if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_MIDDLE); } if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } } if (style.containsKey(StyleFormatConstants.PADDING_LEFT)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_LEFT); cell.setPaddingLeft(val); } if (style.containsKey(StyleFormatConstants.PADDING_RIGHT)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_RIGHT); cell.setPaddingRight(val); } if (style.containsKey(StyleFormatConstants.PADDING_TOP)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_TOP); cell.setPaddingTop(val); } if (style.containsKey(StyleFormatConstants.PADDING_BOTTOM)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_BOTTOM); cell.setPaddingBottom(val); } cell.setBorderWidth(0); if (style.containsKey(StyleFormatConstants.BORDER_LEFT)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_LEFT); cell.setBorderWidthLeft(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR); cell.setBorderColorLeft(new BaseColor(color)); } if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_RIGHT); cell.setBorderWidthRight(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR); cell.setBorderColorRight(new BaseColor(color)); } if (style.containsKey(StyleFormatConstants.BORDER_TOP)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_TOP); cell.setBorderWidthTop(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR); cell.setBorderColorTop(new BaseColor(color)); } if (style.containsKey(StyleFormatConstants.BORDER_BOTTOM)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_BOTTOM); cell.setBorderWidthBottom(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR); cell.setBorderColorBottom(new BaseColor(color)); } // for subreports we use default no wrap if (cell.getTable() == null) { cell.setNoWrap(true); if (bandElement != null) { if (bandElement.isWrapText()) { cell.setNoWrap(false); } } } // to see a background image all cells must not have any background! if (bean.getReportLayout().getBackgroundImage() != null) { cell.setBackgroundColor(null); } } return cell; }
From source file:rs.marko.helper.Kreiranje.java
public static File createPdfStatistika(List<Stavkadnevneberbe> stavke, Date pocetak, Date kraj) { Document document = new Document(); File yourFile = null;/*from w w w . ja v a 2 s .c o m*/ try { yourFile = new File(System.getProperty("user.home") + "/Desktop/" + pocetak + "_" + kraj + ".pdf"); if (!yourFile.exists()) { yourFile.createNewFile(); } FileOutputStream oFile = new FileOutputStream(yourFile, false); document.setPageSize(PageSize.A4.rotate()); PdfWriter.getInstance(document, oFile); document.open(); // String text = ""; // for (int i = 0; i < 10000; i++) { // text += "test"; // , } // String jmbg = stavke.get(0).getDobavljac().getJmbg(); PdfPTable table = new PdfPTable( new float[] { 300f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f }); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); Paragraph p = new Paragraph("Od: " + pocetak + " do: " + kraj); p.add(new Paragraph(" ")); document.add(p); PdfPCell c = new PdfPCell(new Phrase("")); // PdfPCell c1 = new PdfPCell(new Phrase("Sifra")); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // c1.setRowspan(2); // c1.setColspan(2); // table.addCell(c1); PdfPCell c1 = new PdfPCell(new Phrase("Dobavljac")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setVerticalAlignment(Element.ALIGN_MIDDLE); c1.setRowspan(2); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("Tacne")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("I Klasa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("II Klasa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("III Klasa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("Svega")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(3); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cena")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); Font font = new Font(BaseFont.createFont(), 10, Font.NORMAL); // table.setHeaderRows(3); List<String> jmbgovi = new ArrayList<>(); Map<Double, Double> kt = new HashMap<>(); Map<Double, Double> k1 = new HashMap<>(); Map<Double, Double> k2 = new HashMap<>(); Map<Double, Double> k3 = new HashMap<>(); Map<Double, Double> ukupnoTacneVrednost = new HashMap<>(); Map<Double, Double> ukupnoPrvaKlasaVrednost = new HashMap<>(); Map<Double, Double> ukupnoDrugaKlasaVrednost = new HashMap<>(); Map<Double, Double> ukupnoTrecaKlasaVrednost = new HashMap<>(); for (Stavkadnevneberbe stavkaDnevneBerbe : stavke) { if (!jmbgovi.contains(stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getJmbg())) { jmbgovi.add(stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getJmbg()); } } Double ukupnoKolicinaTacne = 0.0; Double ukupnoKolicinaPrvaKlasa = 0.0; Double ukupnoKolicinaDrugaKlasa = 0.0; Double ukupnoKolicinaTrecaKlasa = 0.0; Double ukupnoCenaTacne = 0.0; Double ukupnoCenaPrvaKlasa = 0.0; Double ukupnoCenaDrugaKlasa = 0.0; Double ukupnoCenaTrecaKlasa = 0.0; Double ukupanIznosSvih = 0.0; for (String j : jmbgovi) { String imeDobavljaca = null; for (Stavkadnevneberbe stavkaDnevneBerbe : stavke) { if (stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getJmbg().equals(j)) { if (imeDobavljaca == null) { imeDobavljaca = stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getIme() + " " + stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getPrezime(); } if (!kt.containsKey(stavkaDnevneBerbe.getCenatacne()) && stavkaDnevneBerbe.getTacne() != 0) { kt.put(stavkaDnevneBerbe.getCenatacne(), new Double(0)); } if (!k1.containsKey(stavkaDnevneBerbe.getCenaprvaklasa()) && stavkaDnevneBerbe.getCenaprvaklasa() != 0) { k1.put(stavkaDnevneBerbe.getCenaprvaklasa(), new Double(0)); } if (!k2.containsKey(stavkaDnevneBerbe.getCenadrugaklasa()) && stavkaDnevneBerbe.getCenadrugaklasa() != 0) { k2.put(stavkaDnevneBerbe.getCenadrugaklasa(), new Double(0)); } if (!k3.containsKey(stavkaDnevneBerbe.getCenatrecaklasa()) && stavkaDnevneBerbe.getCenatrecaklasa() != 0) { k3.put(stavkaDnevneBerbe.getCenatrecaklasa(), new Double(0)); } } } for (Stavkadnevneberbe s : stavke) { if (s.getDnevnaberba().getDobavljac().getJmbg().equals(j)) { if (kt.containsKey(s.getCenatacne())) { kt.put(s.getCenatacne(), kt.get(s.getCenatacne()) + s.getTacne()); } if (k1.containsKey(s.getCenaprvaklasa())) { k1.put(s.getCenaprvaklasa(), k1.get(s.getCenaprvaklasa()) + s.getPrvaklasa()); } if (k2.containsKey(s.getCenadrugaklasa())) { k2.put(s.getCenadrugaklasa(), k2.get(s.getCenadrugaklasa()) + s.getDrugaklasa()); } if (k3.containsKey(s.getCenatrecaklasa())) { k3.put(s.getCenatrecaklasa(), k3.get(s.getCenatrecaklasa()) + s.getTrecaklasa()); } } } c1 = new PdfPCell(new Phrase(imeDobavljaca)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); Iterator it = kt.entrySet().iterator(); Double ukupnoKolicinaT = 0.0; Double ukupnoCenaT = 0.0; Double ukupanIznos = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoKolicinaT += (Double) pair.getValue(); ukupnoCenaT += (Double) pair.getKey(); ukupanIznos += ((Double) pair.getValue() * (Double) pair.getKey()); //ukupno vrednost if (ukupnoTacneVrednost.containsKey((Double) pair.getKey())) { ukupnoTacneVrednost.put((Double) pair.getKey(), ukupnoTacneVrednost.get((Double) pair.getKey()) + ((Double) pair.getKey() * (Double) pair.getValue())); } else { ukupnoTacneVrednost.put((Double) pair.getKey(), (Double) pair.getKey() * (Double) pair.getValue()); } } c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaT, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznos, 2) + "", font)); table.addCell(c1); it = k1.entrySet().iterator(); Double ukupnoKolicinaP = 0.0; Double ukupnoCenaP = 0.0; Double ukupanIznosP = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoKolicinaP += (Double) pair.getValue(); ukupnoCenaP += (Double) pair.getKey(); ukupanIznosP += ((Double) pair.getValue() * (Double) pair.getKey()); if (ukupnoPrvaKlasaVrednost.containsKey((Double) pair.getKey())) { ukupnoPrvaKlasaVrednost.put((Double) pair.getKey(), ukupnoPrvaKlasaVrednost.get((Double) pair.getKey()) + ((Double) pair.getKey() * (Double) pair.getValue())); } else { ukupnoPrvaKlasaVrednost.put((Double) pair.getKey(), (Double) pair.getKey() * (Double) pair.getValue()); } } c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaP, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznosP, 2) + "", font)); table.addCell(c1); it = k2.entrySet().iterator(); Double ukupnoKolicinaD = 0.0; Double ukupnoCenaD = 0.0; Double ukupanIznosD = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoKolicinaD += (Double) pair.getValue(); ukupnoCenaD += (Double) pair.getKey(); ukupanIznosD += ((Double) pair.getValue() * (Double) pair.getKey()); if (ukupnoDrugaKlasaVrednost.containsKey((Double) pair.getKey())) { ukupnoDrugaKlasaVrednost.put((Double) pair.getKey(), ukupnoDrugaKlasaVrednost.get((Double) pair.getKey()) + ((Double) pair.getKey() * (Double) pair.getValue())); } else { ukupnoDrugaKlasaVrednost.put((Double) pair.getKey(), (Double) pair.getKey() * (Double) pair.getValue()); } } c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaD, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznosD, 2) + "", font)); table.addCell(c1); it = k3.entrySet().iterator(); Double ukupnoKolicinaTr = 0.0; Double ukupnoCenaTr = 0.0; Double ukupanIznosT = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoKolicinaTr += (Double) pair.getValue(); ukupnoCenaTr += (Double) pair.getKey(); ukupanIznosT += ((Double) pair.getValue() * (Double) pair.getKey()); if (ukupnoTrecaKlasaVrednost.containsKey((Double) pair.getKey())) { ukupnoTrecaKlasaVrednost.put((Double) pair.getKey(), ukupnoTrecaKlasaVrednost.get((Double) pair.getKey()) + ((Double) pair.getKey() * (Double) pair.getValue())); } else { ukupnoTrecaKlasaVrednost.put((Double) pair.getKey(), (Double) pair.getKey() * (Double) pair.getValue()); } } c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaTr, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznosT, 2) + "", font)); table.addCell(c1); Double ukupnoKolicina = ukupnoKolicinaT + ukupnoKolicinaP + ukupnoKolicinaD + ukupnoKolicinaTr; Double ukupnoVrednost = ukupanIznos + ukupanIznosP + ukupanIznosD + ukupanIznosT; Double ukupnoCena = ukupnoVrednost / ukupnoKolicina; c1 = new PdfPCell(new Phrase(round(ukupnoKolicina, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupnoCena, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupnoVrednost, 2) + "", font)); table.addCell(c1); ukupanIznosSvih += ukupnoVrednost; ukupnoKolicinaTacne += ukupnoKolicinaT; ukupnoKolicinaPrvaKlasa += ukupnoKolicinaP; ukupnoKolicinaDrugaKlasa += ukupnoKolicinaD; ukupnoKolicinaTrecaKlasa += ukupnoKolicinaTr; ukupnoCenaTacne += ukupanIznos; ukupnoCenaPrvaKlasa += ukupanIznosP; ukupnoCenaDrugaKlasa += ukupanIznosD; ukupnoCenaTrecaKlasa += ukupanIznosT; kt.clear(); k1.clear(); k2.clear(); k3.clear(); } c1 = new PdfPCell(new Phrase("UKUPNO")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoKolicinaTacne + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoCenaTacne + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoKolicinaPrvaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoCenaPrvaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoKolicinaDrugaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoCenaDrugaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoKolicinaTrecaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoCenaTrecaKlasa + "", font)); table.addCell(c1); Double ukupnoKolicinaSve = ukupnoKolicinaTacne + ukupnoKolicinaPrvaKlasa + ukupnoKolicinaDrugaKlasa + ukupnoKolicinaTrecaKlasa; Double prosecnaCena = ukupanIznosSvih / ukupnoKolicinaSve; c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaSve, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(prosecnaCena, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznosSvih, 2) + "", font)); table.addCell(c1); //PDV c1 = new PdfPCell(new Phrase("PDV")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); table.addCell(c); Iterator it = ukupnoTacneVrednost.entrySet().iterator(); Double ukupnoTacnePdv = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); if ((Double) pair.getKey() == 110) { ukupnoTacnePdv += (((Double) pair.getValue() / (Double) pair.getKey()) * 106); } else { ukupnoTacnePdv += (Double) pair.getValue(); } } c1 = new PdfPCell(new Phrase(round(ukupnoTacnePdv * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); table.addCell(c); it = ukupnoPrvaKlasaVrednost.entrySet().iterator(); Double ukupnoPrvaKlasaPdv = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoPrvaKlasaPdv += (Double) pair.getValue(); } c1 = new PdfPCell(new Phrase(round(ukupnoPrvaKlasaPdv * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); table.addCell(c); it = ukupnoDrugaKlasaVrednost.entrySet().iterator(); Double ukupnoDrugaKlasaPdv = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoDrugaKlasaPdv += (Double) pair.getValue(); } c1 = new PdfPCell(new Phrase(round(ukupnoDrugaKlasaPdv * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); table.addCell(c); it = ukupnoTrecaKlasaVrednost.entrySet().iterator(); Double ukupnoTrecaKlasaPdv = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoTrecaKlasaPdv += (Double) pair.getValue(); } c1 = new PdfPCell(new Phrase(round(ukupnoTrecaKlasaPdv * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); c = new PdfPCell(new Phrase("")); c.setColspan(2); table.addCell(c); Double ukupnoSvePDV = ukupnoTacnePdv + ukupnoPrvaKlasaPdv + ukupnoDrugaKlasaPdv + ukupnoTrecaKlasaPdv; c1 = new PdfPCell(new Phrase(round(ukupnoSvePDV * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); c = new PdfPCell(new Phrase("")); c.setColspan(10); table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); c1 = new PdfPCell(new Phrase("DOBITAK")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell( new Phrase(round((ukupnoSvePDV * (110.0f / 100.0f)) - ukupanIznosSvih, 2) + "", font)); table.addCell(c1); document.add(table); document.add(new Paragraph(" ")); } catch (DocumentException ex) { Logger.getLogger(Kreiranje.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Kreiranje.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Kreiranje.class.getName()).log(Level.SEVERE, null, ex); } document.close(); return yourFile; }
From source file:Servlet.FacturaCompraServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w .ja va 2s .co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { HttpSession session = request.getSession(true); boolean sw1 = false; LinkedList<ProductoCompraClass> lista = (LinkedList) session.getAttribute("productoscompra"); Calendar fecha = new GregorianCalendar(); FacturaCompraProductoDAO fvpd = new FacturaCompraProductoDAO(); FacturaCompraDAO fvd = new FacturaCompraDAO(); ProductoDAO pd = new ProductoDAO(); TransaccionDAO td = new TransaccionDAO(); ProveedorClass cc = new ProveedorClass(); AsientoDAO ad = new AsientoDAO(); AsientoClass ac1 = new AsientoClass(); cc = (ProveedorClass) session.getAttribute("proveedorcompra"); String a = session.getAttribute("idFacturacompra").toString(); String b = session.getAttribute("fechaFacturacompra").toString(); ac1 = ad.consultarfecha(b); AsientoClass ac2 = new AsientoClass(); Calendar cal = Calendar.getInstance(); if (ac1.getIdAsiento() == null) { ac2 = new AsientoClass("1", Integer.toString(cal.get(Calendar.YEAR)), b, "1", "", "0", "0"); ad.insertar(ac2); ac2 = ad.consultarfecha(b); } else { int xvr = Integer.parseInt(ac1.getNumeroAsiento()) + 1; ac2 = new AsientoClass(ac1.getNumeroDiario(), ac1.getPeriodoAsiento(), b, String.valueOf(xvr), "", "0", "0"); ad.insertar(ac2); ac2 = ad.consultarfecha(b); } String c = request.getParameter("descuentoFacturacompra").toString(); String d = cc.getIdProveedor(); String e = request.getParameter("ivaFacturacompra"); int hora = fecha.get(Calendar.HOUR_OF_DAY); String hr; if (hora < 10) { hr = "0" + String.valueOf(hora); } else { hr = String.valueOf(hora); } int minuto = fecha.get(Calendar.MINUTE); String mnt; if (minuto < 10) { mnt = "0" + String.valueOf(minuto); } else { mnt = String.valueOf(minuto); } int segundo = fecha.get(Calendar.SECOND); String sgd; if (segundo < 10) { sgd = "0" + String.valueOf(segundo); } else { sgd = String.valueOf(segundo); } String horaactual = hr + ":" + mnt + ":" + sgd; FacturaCompraClass fvc = new FacturaCompraClass(a, horaactual, b, "986789456734", "PARQUE INDUSTRIAL", "001", c, d, e); boolean sw0 = fvd.insertar(fvc); if (sw0) { for (int i = 0; i < lista.size(); i++) { try { String idFactura = session.getAttribute("idFacturacompra").toString(); String idProducto = lista.get(i).getIdProducto().toUpperCase(); String cantidadProducto = lista.get(i).getCantidadProducto().toUpperCase(); FacturaCompraProductoClass u = new FacturaCompraProductoClass(idFactura, idProducto, cantidadProducto); boolean sw = fvpd.insertar(u); if (sw) { int val1 = request.getParameter("formaspagoFacturacompra").toString().indexOf("-"); int val2 = request.getParameter("formaspagoFacturacompra").toString().length(); String cuenta1 = request.getParameter("formaspagoFacturacompra").toString() .substring(val1 + 1, val2); String cuenta2 = "21"; String concepto = "Compra de productos. Factura Compra " + a; String debe = request.getParameter("cedldatotalcompra"); String haber = request.getParameter("cedldatotalcompra"); String referencia = "Factura Compra " + a; String documento = session.getAttribute("idFacturacompra").toString(); String idAsiento = ac2.getIdAsiento(); String numeroDiario = String.valueOf(Integer.parseInt(ac2.getNumeroDiario())); String periodoAsiento = ac2.getPeriodoAsiento(); String fechaAsiento = ac2.getFechaAsiento(); String numeroAsiento = ac2.getNumeroAsiento(); String conceptoAsiento = concepto; String debeAsiento = String.valueOf(Float.parseFloat(debe)); String haberAsiento = String.valueOf(Float.parseFloat(haber)); AsientoClass ac3; ac3 = new AsientoClass(idAsiento, numeroDiario, periodoAsiento, fechaAsiento, numeroAsiento, conceptoAsiento, debeAsiento, haberAsiento); boolean sw5 = ad.modificar(ac3); if (sw5) { TransaccionClass u1 = new TransaccionClass(debe, "0", referencia, documento, cuenta2, ac2.getIdAsiento()); TransaccionClass u2 = new TransaccionClass("0", haber, referencia, documento, cuenta1, ac2.getIdAsiento()); boolean sw3 = td.insertar(u1); boolean sw4 = td.insertar(u2); if (sw3 && sw4) { try { sw1 = sw; boolean sw2 = pd.modificarcantidadcompra( (String) lista.get(i).getIdProducto().toString(), (String) lista.get(i).getCostoProducto().toString(), (String) lista.get(i).getCantidadProducto().toString()); if (sw2) { } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } catch (SQLException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } catch (SQLException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } } ///////////////////////////////////// Document document = new Document(); response.setContentType("application/pdf"); PdfWriter.getInstance(document, response.getOutputStream()); LinkedList<ProductoCompraClass> listaxvr = (LinkedList) session.getAttribute("productoscompra"); PdfPCell cell; int i = 0; float to = 0; document.open(); /* new paragraph instance initialized and add function write in pdf file*/ PdfPTable mitablafactura = new PdfPTable(2); cell = new PdfPCell(new Phrase("Factura")); cell.setBorder(Rectangle.NO_BORDER); mitablafactura.addCell(cell); cell = new PdfPCell(new Phrase("Fecha")); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablafactura.addCell(cell); cell = new PdfPCell(new Phrase(a)); cell.setBorder(Rectangle.NO_BORDER); mitablafactura.addCell(cell); cell = new PdfPCell(new Phrase(b)); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablafactura.addCell(cell); document.add(mitablafactura); document.add(new Phrase("\n")); PdfPTable mitablaproveedor = new PdfPTable(2); cell = new PdfPCell(new Phrase("RUC Proveedor")); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase(cc.getIdentificacionProveedor())); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase("Nombre Proveedor")); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase(cc.getNombreProveedor())); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase("Direccion Proveedor")); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase(cc.getDireccionProveedor())); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase("Telefono Proveedor")); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase(cc.getTelefonoProveedor())); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); document.add(mitablaproveedor); document.add(new Phrase("\n")); PdfPTable mitablasimple = new PdfPTable(4); mitablasimple.addCell("ID"); mitablasimple.addCell("Cantidad"); mitablasimple.addCell("Costo"); mitablasimple.addCell("Total"); for (Iterator iter = listaxvr.iterator(); iter.hasNext();) { ProductoCompraClass customerBean = (ProductoCompraClass) iter.next(); String id = customerBean.getIdProducto(); String cantidad = customerBean.getCantidadProducto(); String costo = customerBean.getCostoProducto(); String total = String.valueOf(Float.valueOf(cantidad) * Float.valueOf(costo)); mitablasimple.addCell(id); mitablasimple.addCell(cantidad); mitablasimple.addCell(costo); mitablasimple.addCell(total); listaxvr.remove(i); i++; to = to + Float.valueOf(total); session.setAttribute("productoscompra", listaxvr); } float descuento = to * (Float.valueOf(c)); IVAClass i1 = new IVAClass(); IVADAO i2 = new IVADAO(); i1 = i2.consultariva(e); float iva = (to - descuento) * Float.valueOf(i1.getValorIva()); float x = to - descuento + iva; mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("SubTotal"); mitablasimple.addCell(String.valueOf(to)); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("Descuento"); mitablasimple.addCell(c); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("SubTotal Descuento"); mitablasimple.addCell(String.valueOf(descuento)); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("IVA"); mitablasimple.addCell(i1.getValorIva()); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("SubTotal IVA"); mitablasimple.addCell(String.valueOf(iva)); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("Total"); mitablasimple.addCell(String.valueOf(x)); document.add(mitablasimple); document.close(); //document instance closed //////////////////////////////////// } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } catch (SQLException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(FacturaCompraServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Servlet.FacturaVentaServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//w w w . j a v a 2 s . com * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { HttpSession session = request.getSession(true); boolean sw1 = false; LinkedList<ProductoVentaClass> lista = (LinkedList) session.getAttribute("productos"); Calendar fecha = new GregorianCalendar(); FacturaVentaProductoDAO fvpd = new FacturaVentaProductoDAO(); FacturaVentaDAO fvd = new FacturaVentaDAO(); ProductoDAO pd = new ProductoDAO(); TransaccionDAO td = new TransaccionDAO(); ClienteClass cc = new ClienteClass(); AsientoDAO ad = new AsientoDAO(); AsientoClass ac1 = new AsientoClass(); cc = (ClienteClass) session.getAttribute("cliente"); String a = session.getAttribute("idFactura").toString(); String b = session.getAttribute("fechaFactura").toString(); ac1 = ad.consultarfecha(b); AsientoClass ac2 = new AsientoClass(); Calendar cal = Calendar.getInstance(); if (ac1.getIdAsiento() == null) { ac2 = new AsientoClass("1", Integer.toString(cal.get(Calendar.YEAR)), b, "1", "", "0", "0"); ad.insertar(ac2); ac2 = ad.consultarfecha(b); } else { int xvr = Integer.parseInt(ac1.getNumeroAsiento()) + 1; ac2 = new AsientoClass(ac1.getNumeroDiario(), ac1.getPeriodoAsiento(), b, String.valueOf(xvr), "", "0", "0"); ad.insertar(ac2); ac2 = ad.consultarfecha(b); } String c = request.getParameter("descuentoFactura").toString(); String d = cc.getIdCliente(); String e = request.getParameter("ivaFactura"); int hora = fecha.get(Calendar.HOUR_OF_DAY); String hr; if (hora < 10) { hr = "0" + String.valueOf(hora); } else { hr = String.valueOf(hora); } int minuto = fecha.get(Calendar.MINUTE); String mnt; if (minuto < 10) { mnt = "0" + String.valueOf(minuto); } else { mnt = String.valueOf(minuto); } int segundo = fecha.get(Calendar.SECOND); String sgd; if (segundo < 10) { sgd = "0" + String.valueOf(segundo); } else { sgd = String.valueOf(segundo); } String horaactual = hr + ":" + mnt + ":" + sgd; FacturaVentaClass fvc = new FacturaVentaClass(a, horaactual, b, "986789456734", "PARQUE INDUSTRIAL", "001", c, d, e); boolean sw0 = fvd.insertar(fvc); if (sw0) { for (int i = 0; i < lista.size(); i++) { try { String idFactura = session.getAttribute("idFactura").toString(); String idProducto = lista.get(i).getIdProducto().toUpperCase(); String cantidadProducto = lista.get(i).getCantidadProducto().toUpperCase(); FacturaVentaProductoClass u = new FacturaVentaProductoClass(idFactura, idProducto, cantidadProducto); boolean sw = fvpd.insertar(u); if (sw) { int val1 = request.getParameter("formaspagoFactura").toString().indexOf("-"); int val2 = request.getParameter("formaspagoFactura").toString().length(); String cuenta1 = request.getParameter("formaspagoFactura").toString() .substring(val1 + 1, val2); String cuenta2 = "21"; String concepto = "Venta de productos. Factura Venta " + a; String debe = request.getParameter("cedldatotal"); String haber = request.getParameter("cedldatotal"); String referencia = "Factura Venta " + a; String documento = session.getAttribute("idFactura").toString(); String idAsiento = ac2.getIdAsiento(); String numeroDiario = String.valueOf(Integer.parseInt(ac2.getNumeroDiario())); String periodoAsiento = ac2.getPeriodoAsiento(); String fechaAsiento = ac2.getFechaAsiento(); String numeroAsiento = ac2.getNumeroAsiento(); String conceptoAsiento = concepto; String debeAsiento = String.valueOf(Float.parseFloat(debe)); String haberAsiento = String.valueOf(Float.parseFloat(haber)); AsientoClass ac3; ac3 = new AsientoClass(idAsiento, numeroDiario, periodoAsiento, fechaAsiento, numeroAsiento, conceptoAsiento, debeAsiento, haberAsiento); boolean sw5 = ad.modificar(ac3); if (sw5) { TransaccionClass u1 = new TransaccionClass(debe, "0", referencia, documento, cuenta1, ac2.getIdAsiento()); TransaccionClass u2 = new TransaccionClass("0", haber, referencia, documento, cuenta2, ac2.getIdAsiento()); boolean sw3 = td.insertar(u1); boolean sw4 = td.insertar(u2); if (sw3 && sw4) { try { sw1 = sw; boolean sw2 = pd.modificarcantidadventa( (String) lista.get(i).getIdProducto().toString(), (String) lista.get(i).getCantidadProducto().toString()); if (sw2) { } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } catch (SQLException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } catch (SQLException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } } ///////////////////////////////////// Document document = new Document(); response.setContentType("application/pdf"); PdfWriter.getInstance(document, response.getOutputStream()); LinkedList<ProductoVentaClass> listaxvr = (LinkedList) session.getAttribute("productos"); PdfPCell cell; int i = 0; float to = 0; document.open(); /* new paragraph instance initialized and add function write in pdf file*/ PdfPTable mitablafactura = new PdfPTable(2); cell = new PdfPCell(new Phrase("Factura")); cell.setBorder(Rectangle.NO_BORDER); mitablafactura.addCell(cell); cell = new PdfPCell(new Phrase("Fecha")); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablafactura.addCell(cell); cell = new PdfPCell(new Phrase(a)); cell.setBorder(Rectangle.NO_BORDER); mitablafactura.addCell(cell); cell = new PdfPCell(new Phrase(b)); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablafactura.addCell(cell); document.add(mitablafactura); document.add(new Phrase("\n")); PdfPTable mitablaproveedor = new PdfPTable(2); cell = new PdfPCell(new Phrase("Cedula/RUC Cliente")); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase(cc.getCedula())); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase("Nombre Cliente")); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase(cc.getNombre() + " " + cc.getApellido())); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase("Direccion Cliente")); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase(cc.getDireccion())); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase("Telefono Cliente")); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); cell = new PdfPCell(new Phrase(cc.getTelefono())); cell.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); mitablaproveedor.addCell(cell); document.add(mitablaproveedor); document.add(new Phrase("\n")); PdfPTable mitablasimple = new PdfPTable(4); mitablasimple.addCell("ID"); mitablasimple.addCell("Cantidad"); mitablasimple.addCell("Costo"); mitablasimple.addCell("Total"); for (Iterator iter = listaxvr.iterator(); iter.hasNext();) { ProductoVentaClass customerBean = (ProductoVentaClass) iter.next(); String id = customerBean.getIdProducto(); String cantidad = customerBean.getCantidadProducto(); String costo = customerBean.getPrecioProducto(); String total = String.valueOf(Float.valueOf(cantidad) * Float.valueOf(costo)); mitablasimple.addCell(id); mitablasimple.addCell(cantidad); mitablasimple.addCell(costo); mitablasimple.addCell(total); listaxvr.remove(i); i++; to = to + Float.valueOf(total); session.setAttribute("productos", listaxvr); } float descuento = to * (Float.valueOf(c)); IVAClass i1 = new IVAClass(); IVADAO i2 = new IVADAO(); i1 = i2.consultariva(e); float iva = (to - descuento) * Float.valueOf(i1.getValorIva()); float x = to - descuento + iva; mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("SubTotal"); mitablasimple.addCell(String.valueOf(to)); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("Descuento"); mitablasimple.addCell(c); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("SubTotal Descuento"); mitablasimple.addCell(String.valueOf(descuento)); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("IVA"); mitablasimple.addCell(i1.getValorIva()); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("SubTotal IVA"); mitablasimple.addCell(String.valueOf(iva)); mitablasimple.addCell(""); mitablasimple.addCell(""); mitablasimple.addCell("Total"); mitablasimple.addCell(String.valueOf(x)); document.add(mitablasimple); document.close(); //document instance closed //////////////////////////////////// } else { PrintWriter out = response.getWriter(); out.println("Fail registration."); } } catch (SQLException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(FacturaVentaServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:servlet.GenerarPDF.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w .j a v a 2s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); Document document = new Document(); try { ConexionDB sqlite = new ConexionDB(); java.sql.Connection cn = sqlite.Conectar(); Statement st = cn.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM mascotas;"); response.setContentType("APPLICATION/download"); response.setHeader("Content-Disposition", "filename=Mascotas.pdf"); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); Image image = Image.getInstance( "C:/Users/Cristian/Documents/NetBeansProjects/adopc-mascotas/web/imagenes/logo9.png"); image.scaleAbsolute(100, 100); document.add(image); Paragraph preface = new Paragraph("LOVE MY PET"); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); PdfPTable table = new PdfPTable(5); // 3 columns. table.setWidthPercentage(100); //Width 100% table.setSpacingBefore(10f); //Space before table table.setSpacingAfter(10f); //Space after table //Set Column widths float[] columnWidths = { 1f, 1f, 1f, 1f, 1f }; table.setWidths(columnWidths); PdfPCell cellusuario = new PdfPCell(new Paragraph("usario")); cellusuario.setBorderColor(BaseColor.BLUE); cellusuario.setPaddingLeft(10); cellusuario.setHorizontalAlignment(Element.ALIGN_CENTER); cellusuario.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell celltipo = new PdfPCell(new Paragraph("tipo")); celltipo.setBorderColor(BaseColor.BLUE); celltipo.setPaddingLeft(10); celltipo.setHorizontalAlignment(Element.ALIGN_CENTER); celltipo.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cellnombre = new PdfPCell(new Paragraph("nombre")); cellnombre.setBorderColor(BaseColor.BLUE); cellnombre.setPaddingLeft(10); cellnombre.setHorizontalAlignment(Element.ALIGN_CENTER); cellnombre.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cellraza = new PdfPCell(new Paragraph("raza")); cellraza.setBorderColor(BaseColor.BLUE); cellraza.setPaddingLeft(10); cellraza.setHorizontalAlignment(Element.ALIGN_CENTER); cellraza.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell celledad = new PdfPCell(new Paragraph("edad")); celledad.setBorderColor(BaseColor.BLUE); celledad.setPaddingLeft(10); celledad.setHorizontalAlignment(Element.ALIGN_CENTER); celledad.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cellusuario); table.addCell(celltipo); table.addCell(cellnombre); table.addCell(cellraza); table.addCell(celledad); while (rs.next()) { PdfPCell cell1 = new PdfPCell(new Paragraph(rs.getString(1))); cell1.setPaddingLeft(1); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell1); PdfPCell cell2 = new PdfPCell(new Paragraph(rs.getString(2))); cell2.setPaddingLeft(2); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph(rs.getString(3))); cell3.setPaddingLeft(3); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setBackgroundColor(BaseColor.LIGHT_GRAY); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell3); PdfPCell cell4 = new PdfPCell(new Paragraph(rs.getString(4))); cell4.setPaddingLeft(4); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setBackgroundColor(BaseColor.LIGHT_GRAY); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell4); PdfPCell cell5 = new PdfPCell(new Paragraph(rs.getString(5))); cell5.setPaddingLeft(5); cell5.setHorizontalAlignment(Element.ALIGN_CENTER); cell5.setBackgroundColor(BaseColor.LIGHT_GRAY); cell5.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell5); } document.add(table); //Add more content here cn.close(); } catch (Exception e) { e.printStackTrace(); } document.close(); }
From source file:Servlets.GenerarPinesGrupo.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] idEstudiante = req.getParameterValues("imprimir"); resp.setContentType("application/pdf"); OutputStream out = resp.getOutputStream(); String foto = getServletContext().getRealPath("/recursos/img/logoColegio.png"); req.setCharacterEncoding("UTF-8"); try {//from w w w. j ava 2 s . c om try { Document documento = new Document(); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fontit = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.GRAY); par1.add(new Phrase("Pin de Acceso HeartsTics", fontit)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); // Image image = Image.getInstance("E:\\ArchivosVarios\\logoColegio.png"); // image.scalePercent(50); Image image = Image.getInstance(foto); image.scalePercent(60); Font fuentetabla = FontFactory.getFont("Arial", 8, Font.BOLD, BaseColor.BLACK); Font fuentetablaPin = FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK); Font fuentetablaHeader = FontFactory.getFont("Arial", 9, Font.BOLD, BaseColor.BLACK); Servicio controlador = new Servicio(); for (int i = 0; i < idEstudiante.length; i++) { int idEst = Integer.parseInt(idEstudiante[i]); Pin estudiante = controlador.pinEstudiante(idEst); PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(60); PdfPCell celdaHeader = new PdfPCell( new Paragraph("COLEGIO SAGRADOS CORAZONES", fuentetablaHeader)); celdaHeader.setVerticalAlignment(Element.ALIGN_MIDDLE); celdaHeader.setHorizontalAlignment(Element.ALIGN_CENTER); celdaHeader.setColspan(3); tabla.addCell(celdaHeader); PdfPCell celda01 = new PdfPCell(image); //PdfPCell celda01 = new PdfPCell(new Paragraph("imagen")); celda01.setHorizontalAlignment(Element.ALIGN_CENTER); celda01.setVerticalAlignment(Element.ALIGN_MIDDLE); celda01.setRowspan(2); celda01.setBorder(Rectangle.NO_BORDER); celda01.setBorder(Rectangle.LEFT); tabla.addCell(celda01); PdfPCell celda1 = new PdfPCell(new Paragraph( "Estudiante: " + estudiante.getNombres() + " " + estudiante.getApellidos(), fuentetabla)); PdfPCell celda2 = new PdfPCell(new Paragraph("Pin: " + estudiante.getIdPin(), fuentetablaPin)); PdfPCell celda3 = new PdfPCell( new Paragraph("Fecha creacion: " + estudiante.getInicio(), fuentetabla)); PdfPCell celda4 = new PdfPCell( new Paragraph("Fecha vencimiento: " + estudiante.getFin(), fuentetabla)); celda1.setHorizontalAlignment(Element.ALIGN_CENTER); celda1.setVerticalAlignment(Element.ALIGN_MIDDLE); celda1.setColspan(2); celda1.setBorder(Rectangle.NO_BORDER); celda1.setBorder(Rectangle.RIGHT); celda2.setHorizontalAlignment(Element.ALIGN_CENTER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); celda2.setColspan(2); celda2.setBorder(Rectangle.NO_BORDER); celda2.setBorder(Rectangle.RIGHT); PdfPTable tableFecha = new PdfPTable(2); tableFecha.setWidthPercentage(60); celda3.setHorizontalAlignment(Element.ALIGN_CENTER); celda4.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda1); tabla.addCell(celda2); tableFecha.addCell(celda3); tableFecha.addCell(celda4); Paragraph par2 = new Paragraph(); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); documento.add(tabla); documento.add(tableFecha); } documento.close(); } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:Servlets.GenerarPinEstudiante.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { int idEstudiante = Integer.parseInt(req.getParameter("idEst")); resp.setContentType("application/pdf"); OutputStream out = resp.getOutputStream(); String foto = getServletContext().getRealPath("/recursos/img/logoColegio.png"); req.setCharacterEncoding("UTF-8"); try {/* ww w.j a v a 2 s . c o m*/ try { Document documento = new Document(); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fontit = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.GRAY); par1.add(new Phrase("Pin de Acceso HeartsTics", fontit)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); // Image image = Image.getInstance("E:\\ArchivosVarios\\logoColegio.png"); // image.scalePercent(50); Image image = Image.getInstance(foto); image.scalePercent(60); Font fuentetabla = FontFactory.getFont("Arial", 8, Font.BOLD, BaseColor.BLACK); Font fuentetablaPin = FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK); Font fuentetablaHeader = FontFactory.getFont("Arial", 9, Font.BOLD, BaseColor.BLACK); Servicio controlador = new Servicio(); Pin estudiante = controlador.pinEstudiante(idEstudiante); PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(60); PdfPCell celdaHeader = new PdfPCell(new Paragraph("COLEGIO SAGRADOS CORAZONES", fuentetablaHeader)); celdaHeader.setVerticalAlignment(Element.ALIGN_MIDDLE); celdaHeader.setHorizontalAlignment(Element.ALIGN_CENTER); celdaHeader.setColspan(3); tabla.addCell(celdaHeader); PdfPCell celda01 = new PdfPCell(image); //PdfPCell celda01 = new PdfPCell(new Paragraph("imagen")); celda01.setHorizontalAlignment(Element.ALIGN_CENTER); celda01.setVerticalAlignment(Element.ALIGN_MIDDLE); celda01.setRowspan(2); celda01.setBorder(Rectangle.NO_BORDER); celda01.setBorder(Rectangle.LEFT); tabla.addCell(celda01); PdfPCell celda1 = new PdfPCell(new Paragraph( "Estudiante: " + estudiante.getNombres() + " " + estudiante.getApellidos(), fuentetabla)); PdfPCell celda2 = new PdfPCell(new Paragraph("Pin: " + estudiante.getIdPin(), fuentetablaPin)); PdfPCell celda3 = new PdfPCell( new Paragraph("Fecha creacion: " + estudiante.getInicio(), fuentetabla)); PdfPCell celda4 = new PdfPCell( new Paragraph("Fecha vencimiento: " + estudiante.getFin(), fuentetabla)); celda1.setHorizontalAlignment(Element.ALIGN_CENTER); celda1.setVerticalAlignment(Element.ALIGN_MIDDLE); celda1.setColspan(2); celda1.setBorder(Rectangle.NO_BORDER); celda1.setBorder(Rectangle.RIGHT); celda2.setHorizontalAlignment(Element.ALIGN_CENTER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); celda2.setColspan(2); celda2.setBorder(Rectangle.NO_BORDER); celda2.setBorder(Rectangle.RIGHT); PdfPTable tableFecha = new PdfPTable(2); tableFecha.setWidthPercentage(60); celda3.setHorizontalAlignment(Element.ALIGN_CENTER); celda4.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda1); tabla.addCell(celda2); tableFecha.addCell(celda3); tableFecha.addCell(celda4); Paragraph par2 = new Paragraph(); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); documento.add(tabla); documento.add(tableFecha); documento.close(); } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:superlaskuttaja.logiikka.PdfExtractor.java
private void muodostaDokumentti(Document document, String laskunNumero, PdfWriter writer) throws DocumentException, SQLException, ParseException { document.open();/*from w w w . j ava 2 s .co m*/ //---------------------------------------------------------------------- PdfPTable table1 = new PdfPTable(7); Font f1 = new Font(Font.FontFamily.HELVETICA, 10); Font f2 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); Font f3 = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); Font f4 = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); ResultSet rs = lataaja.getDbc() .executeQuery("select distinct Laskuttaja.yrityksenNimi, Laskuttaja.katuosoite,\n" + "Laskuttaja.postinumero, Laskuttaja.kaupunki, Lasku.paivays, Laskuttaja.alvTunniste,\n" + "Pankkiviivakoodi.erapaiva, Lasku.viivastyskorko, Pankkiviivakoodi.viiteTarkisteella,\n" + "T.nimi, Lasku.maksuehto, T.katuosoite, Laskuttaja.tilinumeronPankki,\n" + "T.postinumero, T.kaupunki, Laskuttaja.tilinumero, T.email, Laskuttaja.tilinumeronSwiftBic,\n" + "V.nimi, V.katuosoite, V.postinumero, V.kaupunki, V.email, Lasku.lisatiedot,\n" + "T.asiakasnumero, V.asiakasnumero, Laskuttaja.nimi, Laskuttaja.puhelinnumero,\n" + "Laskuttaja.sahkopostiOsoite, Pankkiviivakoodi.pankkiviivakoodi\n" + "from Lasku, Pankkiviivakoodi, Laskuttaja, Suorite, Asiakas T, Asiakas V\n" + "where Lasku.laskunNumero = " + laskunNumero + "\n" + "and Lasku.laskuttaja = Laskuttaja.yrityksenNimi\n" + "and Lasku.laskuttajanVersio = Laskuttaja.versio\n" + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n" + "and Lasku.laskunnumero = Suorite.lasku\n" + "and Suorite.tilaaja = T.asiakasnumero\n" + "and Suorite.tilaajanVersio = T.versio\n" + "and Suorite.vastaanottaja = V.asiakasnumero\n" + "and Suorite.vastaanottajanVersio = V.versio\n" + ""); rs.first(); table1.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin())); table1.setLockedWidth(true); table1.setWidths(new int[] { 370, 100, 73, 100, 73, 100, 179 }); PdfPCell cell; Paragraph p; cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(1), f4); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("LASKU", f4); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(2), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(3) + " " + rs.getString(4), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Pivys", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(pvmFormaatti1.format(pvmFormaatti3.parse(rs.getTimestamp(5).toString())), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Laskun numero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(laskunNumero, f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Alv-tunniste: " + rs.getString(6), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Erpiv", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(pvmFormaatti1.format(pvmFormaatti4.parse(rs.getDate(7).toString())), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Viivstyskorko", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(Integer.toString(rs.getInt(8)) + ".0%", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); //Jos vastaanottaja on sama kuin tilaaja ei laiteta erikseen vastaanottajan tietoja nkyville. if (rs.getInt(25) == rs.getInt(26)) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(10), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Viitenumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(9), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(12), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Maksuehto", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(11), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(14) + " " + rs.getString(15), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Pankki", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(13), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(17), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Tilinumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(16), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Swift/BIC", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(18), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph("Listiedot", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(24), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); document.add(table1); } else { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Palvelun tilaaja", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Viitenumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(9), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(10), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Maksuehto", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(11), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(12), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Pankki", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(13), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(14) + " " + rs.getString(15), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Tilinumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(16), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(17), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Swift/BIC", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(18), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph("Palvelun vastaanottaja", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(19), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(20), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(21) + " " + rs.getString(22), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(23), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph("Listiedot", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(24), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); document.add(table1); } // Otetaan alemmas tulevia tietoja talteen. String[] alasTulevatTiedot = new String[] { rs.getString(9), rs.getString(1), rs.getString(27), rs.getString(13), rs.getString(2), rs.getString(28), rs.getString(16), rs.getString(3) + " " + rs.getString(4), rs.getString(29), rs.getString(18), rs.getString(30), }; //Muodostetaan suoritteiden taulukko. PdfPTable table2 = new PdfPTable(7); table2.setWidths(new int[] { 370, 100, 73, 100, 73, 100, 179 }); table2.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin())); table2.setLockedWidth(true); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Kuvaus", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Mr", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Yks.", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(" hinta", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Alv %", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Alv ", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Yhteens", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); table2.completeRow(); rs = lataaja.getDbc().executeQuery( "select distinct kuvaus, maara, maaranYksikot, aHintaVeroton, alvProsentti, ((alvProsentti / 100.0) * aHintaVeroton * maara) as alvEuroa,\n" + "((1.0 + alvProsentti / 100.0) * aHintaVeroton * maara) as yht, alkuaika\n" + "from Suorite\n" + "where lasku = " + laskunNumero + "\n" + ""); while (rs.next()) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getString(1) + " " + pvmFormaatti1.format(pvmFormaatti3.parse(rs.getTimestamp(8).toString())), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(2, 2).toString(), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getString(3), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(4, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getString(5) + "%", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(6, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(7, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); table2.completeRow(); } cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); table2.completeRow(); rs = lataaja.getDbc().executeQuery( "select distinct sum(aHintaVeroton * maara), sum((alvProsentti / 100.0) * aHintaVeroton * maara)\n" + "from Suorite\n" + "where lasku = " + laskunNumero + "\n" + ""); rs.first(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Veroton hinta yhteens", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(1, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Arvonlisvero yhteens", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(2, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(4); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Yhteens", f3); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); rs = lataaja.getDbc() .executeQuery("select laskunSumma\n" + "from Lasku, Pankkiviivakoodi\n" + "where laskunNumero = " + laskunNumero + "\n" + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n" + ""); rs.first(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(1, 2).toString() + "", f3); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); document.add(table2); PdfPTable table3 = new PdfPTable(3); table3.setWidths(new int[] { 1, 1, 1 }); table3.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin())); table3.setLockedWidth(true); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Pyydmme kyttmn maksaessanne viitenumeroa: " + alasTulevatTiedot[0], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(BOTTOM); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[1], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[2], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[3], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[4], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[5], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[6], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[7], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[8], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[9], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Virtuaaliviivakoodi: " + alasTulevatTiedot[10], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); table3.writeSelectedRows(0, -1, document.left(document.leftMargin()), table3.getTotalHeight() + document.bottom(document.bottomMargin()), writer.getDirectContent()); //---------------------------------------------------------------------- document.close(); }