List of usage examples for com.itextpdf.text.pdf PdfPTable setSpacingBefore
public void setSpacingBefore(final float spacing)
From source file:org.spinsuite.view.report.ReportPrintData.java
License:Open Source License
/** * Create a PDF File//w ww . ja v a 2s .c o m * @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 02/04/2014, 22:52:09 * @param outFile * @throws FileNotFoundException * @throws DocumentException * @return void */ private void createPDF(File outFile) throws FileNotFoundException, DocumentException { Document document = new Document(PageSize.LETTER); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outFile)); PDFHeaderAndFooter event = new PDFHeaderAndFooter(); writer.setPageEvent(event); document.open(); // document.addAuthor(ctx.getResources().getString(R.string.app_name)); document.addCreationDate(); // Paragraph title = new Paragraph(m_reportQuery.getInfoReport().getName()); // Set Font title.getFont().setStyle(Font.BOLD); // Set Alignment title.setAlignment(Paragraph.ALIGN_CENTER); // Add Title document.add(title); // Add New Line document.add(Chunk.NEWLINE); // Parameters ProcessInfoParameter[] param = m_pi.getParameter(); // Get Parameter if (param != null) { // boolean isFirst = true; // Iterate for (ProcessInfoParameter para : param) { // Get SQL Name String name = para.getInfo(); StringBuffer textParameter = new StringBuffer(); if (para.getParameter() == null && para.getParameter_To() == null) continue; else { // Add Parameters Title if (isFirst) { Paragraph titleParam = new Paragraph( ctx.getResources().getString(R.string.msg_ReportParameters)); // Set Font titleParam.getFont().setStyle(Font.BOLDITALIC); // Add to Document document.add(titleParam); isFirst = false; } // Add Parameters Name if (para.getParameter() != null && para.getParameter_To() != null) { // From and To is filled // textParameter.append(name).append(" => ").append(para.getDisplayValue()).append(" <= ") .append(para.getDisplayValue_To()); } else if (para.getParameter() != null) { // Only From // textParameter.append(name).append(" = ").append(para.getDisplayValue()); } else if (para.getParameter_To() != null) { // Only To // textParameter.append(name).append(" <= ").append(para.getDisplayValue_To()); } } // Add to Document Paragraph viewParam = new Paragraph(textParameter.toString()); document.add(viewParam); } } document.add(Chunk.NEWLINE); // InfoReportField[] columns = m_reportQuery.getColumns(); // Add Table PdfPTable table = new PdfPTable(columns.length); table.setSpacingBefore(4); // Add Header PdfPCell headerCell = new PdfPCell(new Phrase(m_reportQuery.getInfoReport().getName())); headerCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerCell.setColspan(columns.length); // Add to Table table.addCell(headerCell); // Add Header // Decimal and Date Format DecimalFormat[] cDecimalFormat = new DecimalFormat[columns.length]; SimpleDateFormat[] cDateFormat = new SimpleDateFormat[columns.length]; for (int i = 0; i < columns.length; i++) { InfoReportField column = columns[i]; // Only Numeric if (DisplayType.isNumeric(column.DisplayType)) cDecimalFormat[i] = DisplayType.getNumberFormat(ctx, column.DisplayType, column.FormatPattern); // Only Date else if (DisplayType.isDate(column.DisplayType)) cDateFormat[i] = DisplayType.getDateFormat(ctx, column.DisplayType, column.FormatPattern); // Phrase phrase = new Phrase(column.PrintName); PdfPCell cell = new PdfPCell(phrase); if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT)) cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER)) cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); else cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED); // table.addCell(cell); } // Add Detail for (int row = 0; row < m_data.size(); row++) { // Get Row RowPrintData rPrintData = m_data.get(row); // Iterate for (int col = 0; col < columns.length; col++) { InfoReportField column = columns[col]; ColumnPrintData cPrintData = rPrintData.get(col); Phrase phrase = null; PdfPCell cell = new PdfPCell(); // String value = cPrintData.getValue(); if (DisplayType.isNumeric(column.DisplayType)) { // Number // Format DecimalFormat decimalFormat = cDecimalFormat[col]; // Format if (decimalFormat != null) value = decimalFormat.format(DisplayType.getNumber(value)); // Set Value cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } else if (DisplayType.isDate(column.DisplayType)) { // Is Date SimpleDateFormat dateFormat = cDateFormat[col]; if (dateFormat != null) { long date = Long.getLong(value, 0); value = dateFormat.format(new Date(date)); } } // Set Value phrase = new Phrase(value); // if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT)) cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER)) cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); else cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED); // Set Font if (rPrintData.isFunctionRow()) { // Set Function Value if (cPrintData.getFunctionValue() != null && cPrintData.getFunctionValue().length() > 0) phrase = new Phrase(cPrintData.getFunctionValue()); // Set Font phrase.getFont().setStyle(Font.BOLDITALIC); } // Add to Table cell.setPhrase(phrase); table.addCell(cell); } } // Add Table to Document document.add(table); // New Line document.add(Chunk.NEWLINE); // Add Footer StringBuffer footerText = new StringBuffer(Env.getContext(ctx, "#SUser")); footerText.append("("); footerText.append(Env.getContext(ctx, "#AD_Role_Name")); footerText.append("@"); footerText.append(Env.getContext(ctx, "#AD_Client_Name")); footerText.append("."); footerText.append(Env.getContext(ctx, "#AD_Org_Name")); footerText.append("{").append(Build.MANUFACTURER).append(".").append(Build.MODEL).append("}) "); // Date SimpleDateFormat pattern = DisplayType.getDateFormat(ctx, DisplayType.DATE_TIME); footerText.append(" ").append(ctx.getResources().getString(R.string.Date)).append(" = "); footerText.append(pattern.format(new Date())); // Paragraph footer = new Paragraph(footerText.toString()); footer.setAlignment(Paragraph.ALIGN_CENTER); // Set Font footer.getFont().setSize(8); // Add Footer document.add(footer); // Close Document document.close(); }
From source file:org.totschnig.myexpenses.model.Account.java
License:Open Source License
private void addTransactionList(Document document, Cursor transactionCursor, PdfHelper helper, WhereFilter filter) throws DocumentException, IOException { String selection;// w w w .j a v a 2 s. co m String[] selectionArgs; if (!filter.isEmpty()) { selection = filter.getSelectionForParts(DatabaseConstants.VIEW_EXTENDED);//GROUP query uses extended view selectionArgs = filter.getSelectionArgs(true); } else { selection = null; selectionArgs = null; } Builder builder = Transaction.CONTENT_URI.buildUpon(); builder.appendPath(TransactionProvider.URI_SEGMENT_GROUPS).appendPath(grouping.name()); if (getId() < 0) { builder.appendQueryParameter(KEY_CURRENCY, currency.getCurrencyCode()); } else { builder.appendQueryParameter(KEY_ACCOUNTID, String.valueOf(getId())); } Cursor groupCursor = cr().query(builder.build(), null, selection, selectionArgs, KEY_YEAR + " ASC," + KEY_SECOND_GROUP + " ASC"); MyApplication ctx = MyApplication.getInstance(); int columnIndexGroupSumIncome = groupCursor.getColumnIndex(KEY_SUM_INCOME); int columnIndexGroupSumExpense = groupCursor.getColumnIndex(KEY_SUM_EXPENSES); int columnIndexGroupSumTransfer = groupCursor.getColumnIndex(KEY_SUM_TRANSFERS); int columIndexGroupSumInterim = groupCursor.getColumnIndex(KEY_INTERIM_BALANCE); int columnIndexRowId = transactionCursor.getColumnIndex(KEY_ROWID); int columnIndexYear = transactionCursor.getColumnIndex(KEY_YEAR); int columnIndexYearOfWeekStart = transactionCursor.getColumnIndex(KEY_YEAR_OF_WEEK_START); int columnIndexMonth = transactionCursor.getColumnIndex(KEY_MONTH); int columnIndexWeek = transactionCursor.getColumnIndex(KEY_WEEK); int columnIndexDay = transactionCursor.getColumnIndex(KEY_DAY); int columnIndexAmount = transactionCursor.getColumnIndex(KEY_AMOUNT); int columnIndexLabelSub = transactionCursor.getColumnIndex(KEY_LABEL_SUB); int columnIndexLabelMain = transactionCursor.getColumnIndex(KEY_LABEL_MAIN); int columnIndexComment = transactionCursor.getColumnIndex(KEY_COMMENT); int columnIndexReferenceNumber = transactionCursor.getColumnIndex(KEY_REFERENCE_NUMBER); int columnIndexPayee = transactionCursor.getColumnIndex(KEY_PAYEE_NAME); int columnIndexTransferPeer = transactionCursor.getColumnIndex(KEY_TRANSFER_PEER); int columnIndexDate = transactionCursor.getColumnIndex(KEY_DATE); DateFormat itemDateFormat; switch (grouping) { case DAY: itemDateFormat = android.text.format.DateFormat.getTimeFormat(ctx); break; case MONTH: itemDateFormat = new SimpleDateFormat("dd"); break; case WEEK: itemDateFormat = new SimpleDateFormat("EEE"); break; default: itemDateFormat = Utils.localizedYearlessDateFormat(); } PdfPTable table = null; int prevHeaderId = 0, currentHeaderId; transactionCursor.moveToFirst(); groupCursor.moveToFirst(); while (transactionCursor.getPosition() < transactionCursor.getCount()) { int year = transactionCursor .getInt(grouping.equals(Grouping.WEEK) ? columnIndexYearOfWeekStart : columnIndexYear); int month = transactionCursor.getInt(columnIndexMonth); int week = transactionCursor.getInt(columnIndexWeek); int day = transactionCursor.getInt(columnIndexDay); int second = -1; switch (grouping) { case DAY: currentHeaderId = year * 1000 + day; break; case WEEK: currentHeaderId = year * 1000 + week; break; case MONTH: currentHeaderId = year * 1000 + month; break; case YEAR: currentHeaderId = year * 1000; break; default: currentHeaderId = 1; } if (currentHeaderId != prevHeaderId) { if (table != null) { document.add(table); } switch (grouping) { case DAY: second = transactionCursor.getInt(columnIndexDay); break; case MONTH: second = transactionCursor.getInt(columnIndexMonth); break; case WEEK: second = transactionCursor.getInt(columnIndexWeek); break; } table = helper.newTable(2); table.setWidthPercentage(100f); PdfPCell cell = helper.printToCell(grouping.getDisplayTitle(ctx, year, second, transactionCursor), FontType.HEADER); table.addCell(cell); Long sumExpense = DbUtils.getLongOr0L(groupCursor, columnIndexGroupSumExpense); Long sumIncome = DbUtils.getLongOr0L(groupCursor, columnIndexGroupSumIncome); Long sumTransfer = DbUtils.getLongOr0L(groupCursor, columnIndexGroupSumTransfer); Long delta = sumIncome - sumExpense + sumTransfer; Long interimBalance = DbUtils.getLongOr0L(groupCursor, columIndexGroupSumInterim); Long previousBalance = interimBalance - delta; cell = helper.printToCell(String.format("%s %s %s = %s", Utils.convAmount(previousBalance, currency), Long.signum(delta) > -1 ? "+" : "-", Utils.convAmount(Math.abs(delta), currency), Utils.convAmount(interimBalance, currency)), FontType.HEADER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); document.add(table); table = helper.newTable(3); table.setWidthPercentage(100f); cell = helper.printToCell("+ " + Utils.convAmount(sumIncome, currency), FontType.NORMAL); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = helper.printToCell("- " + Utils.convAmount(sumExpense, currency), FontType.NORMAL); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = helper.printToCell("<-> " + Utils.convAmount(DbUtils.getLongOr0L(groupCursor, columnIndexGroupSumTransfer), currency), FontType.NORMAL); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.setSpacingAfter(2f); document.add(table); LineSeparator sep = new LineSeparator(); document.add(sep); table = helper.newTable(4); table.setWidths(new int[] { 1, 5, 3, 2 }); table.setSpacingBefore(2f); table.setSpacingAfter(2f); table.setWidthPercentage(100f); prevHeaderId = currentHeaderId; groupCursor.moveToNext(); } long amount = transactionCursor.getLong(columnIndexAmount); String catText = transactionCursor.getString(columnIndexLabelMain); PdfPCell cell = helper.printToCell( Utils.convDateTime(transactionCursor.getString(columnIndexDate), itemDateFormat), FontType.NORMAL); table.addCell(cell); if (DbUtils.getLongOrNull(transactionCursor, columnIndexTransferPeer) != null) { catText = ((amount < 0) ? "=> " : "<= ") + catText; } else { Long catId = DbUtils.getLongOrNull(transactionCursor, KEY_CATID); if (SPLIT_CATID.equals(catId)) { Cursor splits = cr().query(Transaction.CONTENT_URI, null, KEY_PARENTID + " = " + transactionCursor.getLong(columnIndexRowId), null, null); splits.moveToFirst(); catText = ""; while (splits.getPosition() < splits.getCount()) { String splitText = DbUtils.getString(splits, KEY_LABEL_MAIN); if (splitText.length() > 0) { if (DbUtils.getLongOrNull(splits, KEY_TRANSFER_PEER) != null) { splitText = "[" + splitText + "]"; } else { String label_sub = DbUtils.getString(splits, KEY_LABEL_SUB); if (label_sub.length() > 0) splitText += TransactionList.CATEGORY_SEPARATOR + label_sub; } } else { splitText = ctx.getString(R.string.no_category_assigned); } splitText += " " + Utils .convAmount(splits.getLong(splits.getColumnIndexOrThrow(KEY_AMOUNT)), currency); String splitComment = DbUtils.getString(splits, KEY_COMMENT); if (splitComment != null && splitComment.length() > 0) { splitText += " (" + splitComment + ")"; } catText += splitText; if (splits.getPosition() != splits.getCount() - 1) { catText += "; "; } splits.moveToNext(); } splits.close(); } else if (catId == null) { catText = ctx.getString(R.string.no_category_assigned); } else { String label_sub = transactionCursor.getString(columnIndexLabelSub); if (label_sub != null && label_sub.length() > 0) { catText = catText + TransactionList.CATEGORY_SEPARATOR + label_sub; } } } String referenceNumber = transactionCursor.getString(columnIndexReferenceNumber); if (referenceNumber != null && referenceNumber.length() > 0) catText = "(" + referenceNumber + ") " + catText; cell = helper.printToCell(catText, FontType.NORMAL); String payee = transactionCursor.getString(columnIndexPayee); if (payee == null || payee.length() == 0) { cell.setColspan(2); } table.addCell(cell); if (payee != null && payee.length() > 0) { table.addCell(helper.printToCell(payee, FontType.UNDERLINE)); } FontType t = amount < 0 ? FontType.EXPENSE : FontType.INCOME; cell = helper.printToCell(Utils.convAmount(amount, currency), t); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); String comment = transactionCursor.getString(columnIndexComment); if (comment != null && comment.length() > 0) { cell = helper.printToCell(comment, FontType.ITALIC); cell.setColspan(2); table.addCell(helper.emptyCell()); table.addCell(cell); table.addCell(helper.emptyCell()); } transactionCursor.moveToNext(); } // now add all this to the document document.add(table); groupCursor.close(); }
From source file:pdf.PdfUtility.java
private Paragraph addTableEntry(Achievement a) { PdfPTable mainTable = new PdfPTable(new float[] { 1f, 5f }); mainTable.setWidthPercentage(100f);/*from w w w . j a v a 2s . co m*/ mainTable.setSpacingBefore(0f); mainTable.setSpacingAfter(0f); PdfPCell datesCell = getDateCell(a); PdfPCell summaryCell = getSummaryCell(a); mainTable.addCell(datesCell); mainTable.addCell(summaryCell); Paragraph current = new Paragraph(); current.setAlignment(Paragraph.ALIGN_LEFT); //current.setSpacingBefore(10f); current.add(mainTable); return current; }
From source file:pdfreporter.PDFGenTable.java
public static void pdfgentable() { Document document = new Document(); try {//from w w w .j a va2s . c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddTableExample.pdf")); document.open(); PdfPTable table = new PdfPTable(4); // 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 }; table.setWidths(columnWidths); PdfPCell cell1 = new PdfPCell(new Paragraph("Nemam Pojma")); cell1.setBorderColor(BaseColor.BLACK); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell2 = new PdfPCell(new Paragraph("Nemam pojma 2")); cell2.setBorderColor(BaseColor.BLACK); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell3 = new PdfPCell(new Paragraph("Nemam pojma 3")); cell3.setBorderColor(BaseColor.BLACK); cell3.setPaddingLeft(10); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell4 = new PdfPCell(new Paragraph("Nemam pojma 4")); cell4.setBorderColor(BaseColor.BLACK); cell4.setPaddingLeft(10); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); //To avoid having the cell border and the content overlap, if you are having thick cell borders //cell1.setUserBorderPadding(true); //cell2.setUserBorderPadding(true); //cell3.setUserBorderPadding(true); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); document.add(table); document.close(); writer.close(); } catch (FileNotFoundException | DocumentException e) { } }
From source file:pidevhany.Controllers.GeneratePDF.java
public GeneratePDF(String ReponsesCorretes, String ReponsesFausses) throws FileNotFoundException, IOException { Document document = new Document(); OutputStream outputStream = new FileOutputStream( new File("D:\\Esprit\\Atelier Java\\piweb\\pidevHany\\src\\pidevhany\\TestFile.pdf")); try {//ww w. j a v a 2 s .com PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); document.add(new Paragraph("Resultat du test :")); PdfPTable table = new PdfPTable(2); // 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 }; table.setWidths(columnWidths); PdfPCell cell1 = new PdfPCell(new Paragraph(ReponsesCorretes)); cell1.setBorderColor(BaseColor.BLUE); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell2 = new PdfPCell(new Paragraph(ReponsesFausses)); cell2.setBorderColor(BaseColor.GREEN); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell1); table.addCell(cell2); document.add(table); document.close(); outputStream.close(); writer.close(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:platnosci.WyszukPlatnosciController.java
public void akcjaDrukuj() { Drukowanie drukPanel = new Drukowanie(null, true); drukPanel.setLocationRelativeTo(null); drukPanel.setVisible(true);/* w ww . j a v a 2 s .c om*/ if (!drukPanel.isDruk()) { return; } FileOutputStream file = null; File druk = null; try { Document document = new Document(); String userPath = System.getProperty("user.home"); druk = new File(userPath + "/Baks wydruki"); if (!druk.exists()) { druk.mkdirs(); } SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); String strdate = ""; Date calendardate = new Date(); strdate = sdf.format(calendardate.getTime()); File wydruk = new File(druk + "/Platnosci - " + strdate + ".pdf"); if (!wydruk.exists()) { try { wydruk.createNewFile(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } file = new FileOutputStream(wydruk); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(wydruk)); document.open(); PdfPTable table = new PdfPTable(4); // 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 }; table.setWidths(columnWidths); BaseFont bf = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); PdfPCell cell1 = new PdfPCell(new Paragraph("Lp", new com.itextpdf.text.Font(bf, 16))); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(new Paragraph("Firma", new com.itextpdf.text.Font(bf, 16))); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_LEFT); PdfPCell cell3 = new PdfPCell( new Paragraph("Data patnoci", new com.itextpdf.text.Font(bf, 16))); cell3.setPaddingLeft(10); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_LEFT); PdfPCell cell4 = new PdfPCell(new Paragraph("Kwota", new com.itextpdf.text.Font(bf, 16))); cell4.setPaddingLeft(10); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setVerticalAlignment(Element.ALIGN_LEFT); //To avoid having the cell border and the content overlap, if you are having thick cell borders cell1.setBorder(PdfPCell.NO_BORDER); cell2.setBorder(PdfPCell.NO_BORDER); cell3.setBorder(PdfPCell.NO_BORDER); cell4.setBorder(PdfPCell.NO_BORDER); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); TO_Invoice kryt = new TO_Invoice(); kryt.setDataDo(drukPanel.getDateDo()); kryt.setDataOd(drukPanel.getDateOd()); kryt.setStatus(TO_InvoiceStatus.ZAPLACONA); List<TO_Invoice> listaFaktur = getDaoFactory().getDaoInvoice().getListaInvoiceDruk(getConnection(), kryt); Integer i = 1; for (TO_Invoice item : listaFaktur) { table.addCell(getNewCell(i.toString() + ".")); table.addCell(getNewCell(item.getPaymentCompany().getName())); table.addCell(getNewCell(item.getDataZaplacenia().toString())); table.addCell(getNewCell(TO_Invoice.getWynikSumaKoszt(item.getKoszt()) + " z")); i++; } document.add(table); document.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } catch (FileNotFoundException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); BaksSessionBean.getInstance().fireMessage(widok, "Wydruk", "Pdf do ktrego chcesz zapisa wynik jest otwarty!\n Zamknij i sprbuj jeszcze raz."); } finally { try { file.close(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.open(druk); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } BaksSessionBean.getInstance().fireMessage(widok, "Zapis", "Wydruk zapisany w folderze: " + System.getProperty("user.home") + "/Baks wydruki"); }
From source file:printers.HojaDeFirmaPrinter.java
License:Open Source License
private void creaCuerpo(Document doc, GregorianCalendar dia, ArrayList<HorarioItem> data) { Collections.sort(data, new ComparatorHorarioItems()); PdfPTable t = new PdfPTable(3); t.setSpacingBefore(15f); t.setSpacingAfter(10f);/*from w ww . ja v a 2s. com*/ t.setWidthPercentage(100); Font fontbold = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); PdfPCell c = new PdfPCell(new Paragraph("Asignatura", fontbold)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setPadding(5); t.addCell(c); c = new PdfPCell(new Paragraph("Firma", fontbold)); c.setPadding(5); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setPadding(5); t.addCell(c); c = new PdfPCell(new Paragraph("Incidencias", fontbold)); c.setPadding(5); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); t.addCell(c); for (HorarioItem h : data) { creaFilaFirma(t, h); } try { doc.add(t); } catch (DocumentException ex) { Logger.getLogger(HojaDeFirmaPrinter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:report.pdfs.Basics_PDF_Report.java
private void createTable(Section catPart) throws BadElementException { PdfPTable table = new PdfPTable(4); table.setSpacingBefore(25); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Type")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//from w ww . j a v a 2 s .c o m c1 = new PdfPCell(new Phrase("Expense")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Month")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Year")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); selectAll(); calcFExpense(table); calcGExpense(table); calcLExpense(table); calcLiExpense(table); calcMaExpense(table); calcMExpense(table); calcRExpense(table); calcSExpense(table); calcWExpense(table); catPart.add(table); }
From source file:report.pdfs.Feed_PDF_Report.java
private void createTable(Section catPart) throws BadElementException { PdfPTable table = new PdfPTable(8); table.setSpacingBefore(25); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Type")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/* w ww . j a va 2s . co m*/ c1 = new PdfPCell(new Phrase("Herd ID")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Hay Cost")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nuts Cost")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Silage Cost")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Month")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Year")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Total")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); selectAll(); getExpenses(table); catPart.add(table); }
From source file:report.pdfs.Fertilizer_PDF_Report.java
private void createTable(Section catPart) throws BadElementException { PdfPTable table = new PdfPTable(4); table.setSpacingBefore(25); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Type")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from w ww . j av a2 s . c o m*/ c1 = new PdfPCell(new Phrase("Expense")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Month")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Year")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); selectAll(); calcFExpense(table); catPart.add(table); }