List of usage examples for com.lowagie.text.pdf PdfPTable setSpacingBefore
public void setSpacingBefore(float spacing)
From source file:storemanagment.Printing.java
public final void StockTake(String store, String officer, ArrayList<TransactionsPojo> items, String trNo) { Calendar c = Calendar.getInstance(); Date today = c.getTime();/*from w ww .j a v a 2 s . c om*/ java.util.Date d = (today); java.sql.Date DATE = new java.sql.Date(d.getTime()); // String OrgDetails=res[1]+"\n"+DATE.toString(); String orgDetails[] = getRes(); String orgImg = orgDetails[0]; String orgAbout = orgDetails[1]; JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(",")); chooser.setDialogTitle("Save at"); chooser.setApproveButtonText("save"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { try { Document pdfp = new Document(); PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(), store + "st" + DATE + ".pdf"))); // PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),"Group "+jComboBoxGroup.getSelectedItem().toString()+".pdf"))); HeaderFooterPageEvent event = new HeaderFooterPageEvent(officer, trNo, DATE); writer.setPageEvent(event); pdfp.open(); // Document pdfp=new Document(); // PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),transactionReceiptNo+""+DATE+".pdf"))); // pdfp.open(); PdfPTable header1 = new PdfPTable(1); // // tbl.setWidthPercentage(100); // header1.setTotalWidth(575); header1.setLockedWidth(true); header1.addCell(createTextCell("")); header1.addCell(createTextCell("")); header1.addCell(createTextCell("")); header1.addCell(createTextCell("")); PdfPTable header = new PdfPTable(3); // // tbl.setWidthPercentage(100); // header.setTotalWidth(575); header.setLockedWidth(true); header.setWidths(new int[] { 1, 4, 1 }); //THE FIRST ROW //first column ///Logo if (orgImg.equals("image")) { header.addCell("no image "); } else { header.addCell(createImageCell(orgImg)); } //second column ///description header.addCell(createTextCell(orgAbout)); header.addCell(createTextCell("")); PdfPTable RecieptTilte = new PdfPTable(3); // // tbl.setWidthPercentage(100); // RecieptTilte.setTotalWidth(575); RecieptTilte.setLockedWidth(true); // RecieptTilte.setHorizontalAlignment(Align.CENTER); RecieptTilte.setWidths(new int[] { 1, 1, 1 }); RecieptTilte.setSpacingBefore(8); RecieptTilte.setSpacingAfter(6); // RecieptTilte.getDefaultCell().setBorderWidthBottom(2); RecieptTilte.getDefaultCell().setBorderWidthLeft(0); RecieptTilte.getDefaultCell().setBorderWidthRight(0); RecieptTilte.addCell(""); RecieptTilte.addCell(store + " Transactions"); RecieptTilte.setSpacingAfter(8); RecieptTilte.addCell(""); PdfPTable RecieptitemsTitles = new PdfPTable(8); RecieptitemsTitles.setTotalWidth(575); RecieptitemsTitles.setWidths(new int[] { 1, 1, 2, 1, 1, 1, 1, 2 }); RecieptitemsTitles.setLockedWidth(true); RecieptitemsTitles.addCell(creatTextCellTitles("Item-Name")); RecieptitemsTitles.addCell(creatTextCellTitles("Quantiy")); RecieptitemsTitles.addCell(creatTextCellTitles("Type")); RecieptitemsTitles.addCell(creatTextCellTitles("Cash")); RecieptitemsTitles.addCell(creatTextCellTitles("From")); RecieptitemsTitles.addCell(creatTextCellTitles("To")); RecieptitemsTitles.addCell(creatTextCellTitles("R.No")); RecieptitemsTitles.addCell(creatTextCellTitles("Date")); // RecieptitemsTitles.addCell(creatTextCellTitles("Id")); // PdfPTable Recieptitems=new PdfPTable(4); for (int a = 0; a < items.size(); a++) { RecieptitemsTitles .addCell(createTextCellcolor(((TransactionsPojo) items.get(a)).getItem_name(), a)); RecieptitemsTitles.addCell( createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_quantity(), a)); RecieptitemsTitles.addCell( createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_type(), a)); RecieptitemsTitles.addCell( createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_cash(), a)); RecieptitemsTitles.addCell( createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_from(), a)); RecieptitemsTitles .addCell(createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_to(), a)); RecieptitemsTitles.addCell(createTextCellcolor( ((TransactionsPojo) items.get(a)).getTransaction_receipt_no_out(), a)); RecieptitemsTitles.addCell( createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_time_string(), a)); // RecieptitemsTitles.addCell(createTextCellcolor(String.valueOf(((CartPojo)items.get(a)).getItem_id()),a)); } pdfp.add(header1); pdfp.add(header); pdfp.add(RecieptTilte); pdfp.add(RecieptitemsTitles); pdfp.close(); } catch (DocumentException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } // jComboBoxGroup if (Desktop.isDesktopSupported()) { try { File file = new File(chooser.getSelectedFile(), store + "tr" + DATE + ".pdf"); Desktop.getDesktop().open(file); } catch (Exception ex) { ex.printStackTrace(); } } } }
From source file:uk.ac.bbsrc.tgac.miso.core.data.decorator.itext.ITextProjectDecorator.java
License:Open Source License
public void buildReport() throws DocumentException { report = new Document(); PdfWriter writer = PdfWriter.getInstance(report, stream); report.open();/*w w w . jav a2 s . c o m*/ report.add(new Paragraph("Project Summary")); PdfContentByte cb = writer.getDirectContent(); cb.setLineWidth(2.0f); // Make a bit thicker than 1.0 default cb.setGrayStroke(0.9f); // 1 = black, 0 = white float x = 72f; float y = 200f; cb.moveTo(x, y); cb.lineTo(x + 72f * 6, y); cb.stroke(); report.add(new Paragraph(project.getAlias())); report.add(new Paragraph(project.getDescription())); PdfPTable t = new PdfPTable(1); t.setHorizontalAlignment(Element.ALIGN_CENTER); t.setWidthPercentage(100f); // this would be the 100 from setHorizontalLine t.setSpacingAfter(5f); t.setSpacingBefore(0f); t.getDefaultCell().setUseVariableBorders(true); t.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); t.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); t.getDefaultCell().setBorder(Rectangle.BOTTOM); // This generates the line t.getDefaultCell().setBorderWidth(1f); // this would be the 1 from setHorizontalLine t.getDefaultCell().setPadding(0); t.addCell(""); report.add(t); x = 72f; y = 100f; cb.moveTo(x, y); cb.lineTo(x + 72f * 6, y); cb.stroke(); if (project.getSamples().size() > 0) { report.add(new Paragraph("Samples")); for (Sample sample : project.getSamples()) { Paragraph sPara = new Paragraph(sample.getAlias(), FontFactory.getFont("Helvetica", 12, Font.BOLD)); sPara.setIndentationLeft(20); report.add(sPara); report.add(new Paragraph(sample.getDescription())); } } report.close(); }