List of usage examples for com.itextpdf.text Element ALIGN_RIGHT
int ALIGN_RIGHT
To view the source code for com.itextpdf.text Element ALIGN_RIGHT.
Click Source Link
From source file:ara.Confirmsec.java
public void myfunction() throws IOException, DocumentException { String a = preres.getText();//from w ww .j a v a2 s . c o m File file = new File(DEST); file.getParentFile().mkdirs(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(DEST)); document.open(); Image image = Image.getInstance("logo.jpg"); document.add(image); Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD); Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); Font small = FontFactory.getFont(FontFactory.HELVETICA, 5, Font.BOLD); String date = new Date().toString(); Paragraph paragraph1 = new Paragraph(date); Paragraph paragraph2 = new Paragraph("To Whom it May Concern", chapterFont); paragraph2.setAlignment(Element.ALIGN_CENTER); paragraph1.setAlignment(Element.ALIGN_RIGHT); paragraph2.setSpacingBefore(20f); paragraph2.setSpacingAfter(10f); Paragraph paragraph3 = new Paragraph(a, paragraphFont); paragraph3.setSpacingAfter(20f); Paragraph paragraph4 = new Paragraph("Registrar"); paragraph4.setAlignment(Element.ALIGN_RIGHT); paragraph4.setSpacingAfter(100f); Paragraph paragraph5 = new Paragraph( "This is a digitally signed document. Use Ref No. " + c + " to verify.", small); document.add(paragraph1); document.add(paragraph2); document.add(paragraph3); document.add(paragraph4); document.add(paragraph5); document.close(); JOptionPane.showMessageDialog(null, "Document Generated."); }
From source file:be.rheynaerde.poolsheets.PufCompletePoolSheet.java
License:Open Source License
@Override protected PdfPTable getScoreTable() throws DocumentException { final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2; //one column for each player, an extra column for the numbers and a column for the team marks PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth((columnCount) * configuration.getSquareCellSize()); table.setLockedWidth(true);// w w w .j av a 2 s . co m float[] widths = new float[columnCount]; for (int i = 0; i < widths.length; i++) { widths[i] = 1f; } table.setWidths(widths); PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2); topCell.setFixedHeight(configuration.getSquareCellSize()); table.addCell(topCell); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1))); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2))); table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1)); { table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1)); for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) { if (i == configuration.getNrOfPlayers(1)) table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(2), 1)); table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); j++) { if (i == j) { PdfPCell blackCell = getSolidCell(); table.addCell(blackCell); } else { table.addCell(configuration.getResult(i, j)); } } } table.setHorizontalAlignment(Element.ALIGN_RIGHT); return table; }
From source file:be.rheynaerde.poolsheets.PufSingleTeamPoolSheet.java
License:Open Source License
@Override protected PdfPTable getScoreTable() throws DocumentException { final int columnCount = configuration.getNrOfPlayers() + 2; PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth((columnCount) * configuration.getSquareCellSize()); table.setLockedWidth(true);//from w w w.j av a2s .c om float[] widths = new float[columnCount]; for (int i = 0; i < widths.length; i++) { widths[i] = 1f; } table.setWidths(widths); PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2); topCell.setFixedHeight(configuration.getSquareCellSize()); table.addCell(topCell); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers())); table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1)); { table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(), 1)); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < configuration.getNrOfPlayers(); j++) { if (i == j) { PdfPCell blackCell = getSolidCell(); table.addCell(blackCell); } else { table.addCell(configuration.getResult(i, j)); } } } table.setHorizontalAlignment(Element.ALIGN_RIGHT); return table; }
From source file:be.rheynaerde.poolsheets.PufTeamPoolSheet.java
License:Open Source License
protected PdfPTable getScoreTable() throws DocumentException { //table for scores final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2; //one column for each player, an extra column for the numbers and a column for the team marks PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); table.setTotalWidth((columnCount) * configuration.getSquareCellSize()); table.setLockedWidth(true);/* w ww.j a v a 2 s . co m*/ float[] widths = new float[columnCount]; for (int i = 0; i < widths.length; i++) { widths[i] = 1f; } table.setWidths(widths); PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2); topCell.setFixedHeight(configuration.getSquareCellSize()); table.addCell(topCell); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1))); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2))); table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1)); { table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1)); for (int i = 0; i < configuration.getNrOfPlayers(1); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); if (i == 0) { PdfPCell blackCell = getSolidCell(); blackCell.setColspan(configuration.getNrOfPlayers(1)); blackCell.setRowspan(configuration.getNrOfPlayers(1)); table.addCell(blackCell); } for (int j = 0; j < configuration.getNrOfPlayers(2); j++) { table.addCell(configuration.getResult(0, i, 1, j)); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(2), 1)); for (int i = 0; i < configuration.getNrOfPlayers(2); i++) { table.addCell(getHeaderCell(Integer.toString(configuration.getNrOfPlayers(1) + i + 1))); for (int j = 0; j < configuration.getNrOfPlayers(1); j++) { table.addCell(configuration.getResult(1, i, 0, j)); } if (i == 0) { PdfPCell blackCell = getSolidCell(); blackCell.setColspan(configuration.getNrOfPlayers(2)); blackCell.setRowspan(configuration.getNrOfPlayers(2)); table.addCell(blackCell); } } table.setHorizontalAlignment(Element.ALIGN_RIGHT); return table; }
From source file:be.rheynaerde.pufmanager.gui.workers.ExportFullPdfWorker.java
License:Open Source License
private void addPdfToDocument(ByteArrayOutputStream baos, PdfCopy copy, String stampText) throws IOException, BadPdfFormatException { PdfReader reader = new PdfReader(new ByteArrayInputStream(baos.toByteArray())); int n = reader.getNumberOfPages(); for (int page = 1; page <= n; page++) { PdfImportedPage importedPage = copy.getImportedPage(reader, page); PdfCopy.PageStamp stamp = copy.createPageStamp(importedPage); Rectangle rectangle = importedPage.getBoundingBox(); ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(stampText), rectangle.getRight() - 20f, rectangle.getTop() - 20f, 0); stamp.alterContents();//from www . j a v a 2 s .c o m copy.addPage(importedPage); } }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private byte[] personalize(byte[] pdf, Contact contact, Toc tableOfContents) throws IOException, DocumentException { try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) { final PdfReader reader = new PdfReader(pdf); final PdfStamper stamper = new PdfStamper(reader, bos); // stamp some text on first page PdfContentByte text = stamper.getOverContent(1); text.beginText();/*from w ww . j a v a2 s .c o m*/ text.setColorFill(iTextUtil.getFontCoverText().getColor()); text.setFontAndSize(iTextUtil.getFontCoverText().getBaseFont(), iTextUtil.getFontCoverText().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle1, text.getPdfDocument().getPageSize().getWidth() - 15, 195, 0); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle2, text.getPdfDocument().getPageSize().getWidth() - 15, 175, 0); text.showTextAligned(Element.ALIGN_RIGHT, contact.getCurrency().getTitlePageDescription(), text.getPdfDocument().getPageSize().getWidth() - 15, 80, 0); text.setColorFill(iTextUtil.getFontCoverPricingguide().getColor()); text.setFontAndSize(iTextUtil.getFontCoverPricingguide().getBaseFont(), iTextUtil.getFontCoverPricingguide().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle3, text.getPdfDocument().getPageSize().getWidth() - 15, 145, 0); text.setColorFill(iTextUtil.getFontCoverYear().getColor()); text.setFontAndSize(iTextUtil.getFontCoverYear().getBaseFont(), iTextUtil.getFontCoverYear().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle4, text.getPdfDocument().getPageSize().getWidth() - 15, 105, 0); text.endText(); // stamp some text on first page of the table of contents page final Image logoImage = iTextUtil.getImageFromByteArray(HttpUtil.readByteArray( pdfTemplate.getLogo().getUrl(), defaultService.getUserName(), defaultService.getPassword())); final PdfContentByte tocContent = stamper.getOverContent(tableOfContents.getFirstPageOfToc()); final float resizeRatio = logoImage.getHeight() / 85; // define the desired height of the log tocContent.addImage(logoImage, logoImage.getWidth() / resizeRatio, 0, 0, logoImage.getHeight() / resizeRatio, 59, 615); text = stamper.getOverContent(tableOfContents.getFirstPageOfToc()); text.beginText(); text.setColorFill(iTextUtil.getFontPersonalization().getColor()); text.setFontAndSize(iTextUtil.getFontPersonalization().getBaseFont(), iTextUtil.getFontPersonalization().getSize()); text.showTextAligned(Element.ALIGN_LEFT, "Prepared for:", 355, 681, 0); text.showTextAligned(Element.ALIGN_LEFT, contact.getFullName(), 355, 662, 0); // set company name if (!StringUtils.isEmpty(contact.getCompany())) { text.showTextAligned(Element.ALIGN_LEFT, contact.getCompany(), 355, 643, 0); text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355, 624, 0); } else { text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355, 643, 0); } text.endText(); final ColumnText ct = new ColumnText(tocContent); ct.setSimpleColumn(new Rectangle(55, 517, iTextUtil.PAGE_SIZE.getWidth() - 45, 575)); final List<Element> elements = HTMLWorker.parseToList(new StringReader(disclaimer), null); final Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); for (Element element : elements) { for (Chunk chunk : element.getChunks()) { chunk.setFont(iTextUtil.getFontDisclaimer()); } p.add(element); } ct.addElement(p); ct.go(); stamper.close(); reader.close(); return bos.toByteArray(); } }
From source file:billerfx.FXMLBillController.java
File generatePDF() { File fi = null;/* ww w . j a v a 2 s .co m*/ try { Stage gg = ((Stage) imv.getParent().getScene().getWindow()); fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf"); fi.deleteOnExit(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(fi)); Rectangle r = new RectangleReadOnly(207, 575); document.setPageSize(r); document.setMargins(15, 15, 0, 0); document.open(); Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL); Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL); String[] ll = Database.getCurrentSettings(); String ss = "-----------------------------------------------------\n"; ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n"; String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM" : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : ""); ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH)) + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at " + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE) + " " + kk + "\n"; ss += "Table No. " + c.getText() + " Bill No. " + a.getText() + "\n"; ss += "-----------------------------------------------------\n"; Paragraph para = new Paragraph(ss, fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); float[] columnWidths = { 3f, 1f }; table.setWidths(columnWidths); PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); ObservableList ob = map.get(Integer.parseInt(gg.getTitle())); for (int i = 0; i < ob.size(); i++) { Item2 ii = (Item2) ob.get(i); String s1 = ii.getQuantity() + " x " + ii.getName(); String s2 = "Rs. " + ii.getTotal(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(columnWidths); defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); String s1 = "Total:"; String s2 = "Rs. " + h.getText(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) { s1 = "Discount:"; s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText())); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[7].equals("1")) { s1 = ll[3]; s2 = "Rs. " + k.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[8].equals("1")) { s1 = ll[4]; s2 = "Rs. " + l.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } s1 = "Grand Total:"; s2 = "Rs. " + m.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); para = new Paragraph( "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n", fontbold2); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); document.close(); } catch (Exception mm) { } return fi; }
From source file:bl.pdf.PDFFile.java
public void createRechnung(Rechnung r) throws DocumentException, DALException { document.open();//from w w w . jav a 2 s . c o m Paragraph preface = new Paragraph(); preface.add(newLine(new Date().toString(), small, Element.ALIGN_RIGHT)); // Lets write a big header preface.add(newLine("Rechnung", catFont, -1)); preface.add(newLine(r.getValues(), small, Element.ALIGN_LEFT)); // Will create: Report generated by: _name, _date String to = ""; if (r instanceof Ausgangsrechnung) { Kunde k = BL.getKunde(((Ausgangsrechnung) r).getKundeID()); to += k.getValues(); } else if (r instanceof Eingangsrechnung) { Kontakt k = BL.getKontakt(((Eingangsrechnung) r).getKontaktID()); to += k.getValues(); } preface.add(newLine(to, smallBold, Element.ALIGN_RIGHT)); // We add one empty line addEmptyLine(preface, 2); // add table preface.add(getRechnungszeileTable(r)); document.add(preface); // Start a new page document.newPage(); document.close(); }
From source file:bl.pdf.PDFFile.java
private PdfPTable getRechnungszeileTable(Rechnung r) throws DALException { String[] headers;/*from w w w. j a v a 2 s . co m*/ if (r instanceof Eingangsrechnung) { String[] h = { "Rechnungszeile", "Kommentar", "Steuersatz", "Betrag", "ohne Steuer" }; headers = h; } else { String[] h = { "Rechnungszeile", "Kommentar", "AngebotID", "Steuersatz", "Betrag", "ohne Steuer" }; headers = h; } PdfPTable table = new PdfPTable(headers.length); table.setHeaderRows(1); table.setWidthPercentage(100); for (String header : headers) { PdfPCell c1 = new PdfPCell(new Phrase(header)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } ArrayList<Rechnungszeile> rechnungszeilen = BL.getRechnungszeileListe(r.getRechnungID()); if (rechnungszeilen.isEmpty()) { PdfPCell c = new PdfPCell(new Phrase("Keine Rechnungszeilen vorhanden")); c.setHorizontalAlignment(Element.ALIGN_CENTER); if (r instanceof Ausgangsrechnung) { c.setColspan(6); } else { c.setColspan(5); } table.addCell(c); return table; } double summe = 0; double summeOhne = 0; for (Rechnungszeile rz : rechnungszeilen) { table.addCell(String.valueOf(rz.getRechnungszeileID())); table.addCell(String.valueOf(rz.getKommentar())); if (r instanceof Ausgangsrechnung) { table.addCell(String.valueOf(rz.getAngebotID())); } table.addCell(String.valueOf(rz.getSteuersatz())); table.addCell(String.valueOf(rz.getBetrag())); double betrag = rz.getBetrag(); double steuersatz = rz.getSteuersatz(); double betragOhne = betrag - (betrag / 100 * steuersatz); table.addCell(String.valueOf(betragOhne)); summe += rz.getBetrag(); summeOhne += betragOhne; } PdfPCell c = new PdfPCell(new Phrase("Summe")); c.setHorizontalAlignment(Element.ALIGN_RIGHT); if (r instanceof Ausgangsrechnung) { c.setColspan(4); } else { c.setColspan(3); } table.addCell(c); table.addCell(String.valueOf(summe)); table.addCell(String.valueOf(summeOhne)); return table; }
From source file:Boss.BOss.java
private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked if (evt.getClickCount() == 2) { try {/*from w w w. jav a 2 s. co m*/ connect = new Connection(); Statement st = connect.con.createStatement(); String SQL = "SELECT * FROM request where idrequest =" + getSelectedrequest1(); ResultSet rq = st.executeQuery(SQL); rq.next(); /*****************************/ String type = ""; if (parseInt(rq.getString("id_type")) == 1) { type = "Instalation"; } if (parseInt(rq.getString("id_type")) == 2) { type = "Transfer"; } if (parseInt(rq.getString("id_type")) == 3) { type = "Maintenamce"; } /**************************/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("report.pdf")); document.open(); Paragraph paragraph = new Paragraph(); paragraph.add(new Paragraph("Request : \n", FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY))); paragraph.add("ID Request :"); paragraph.add(rq.getString("idRequest") + ""); paragraph.add("\nRequest type :"); paragraph.add(type); paragraph.add("\nClient name :"); paragraph.add(rq.getString("clientName")); paragraph.add("\nPhone number :"); paragraph.add(rq.getString("TELCLIENT")); paragraph.add("\nAddress 1 :"); paragraph.add(rq.getString("address1")); paragraph.add("\nAddress 2 :"); paragraph.add(rq.getString("address2")); paragraph.add("\nTeam :"); paragraph.add(rq.getString("IDTEAM") + "\n"); /***********************/ String sql = "Select * from report where IDREQUEST = '" + getSelectedrequest1() + "' "; ResultSet rs = st.executeQuery(sql); rs.next(); /**********************/ paragraph.add(new Paragraph("Report : \n", FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY))); paragraph.add(rs.getString("REPORT") + "\n"); Paragraph date = new Paragraph(rs.getString("REPORTDATE").toString().substring(0, 10)); date.setAlignment(Element.ALIGN_RIGHT); Paragraph title = new Paragraph("Report\n", FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.BLACK)); title.setAlignment(Element.ALIGN_CENTER); document.add(date); document.add(title); document.add(paragraph); document.close(); /* Open Pdf */ Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(new File("report.pdf")); } else { System.out.println("Open is not supported"); } } catch (SQLException | ClassNotFoundException | DocumentException ex) { Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex); } } }