List of usage examples for com.itextpdf.text Paragraph setFont
public void setFont(final Font font)
From source file:Report.RelatorioProfessor.java
/** * Funo para gerar o stream do relatorio de orientaes por professor * * @param lOrientacao//w w w. j av a 2 s . c om * @param dtinicial * @param dtfinal * @param coordenador * @param campus * @return ByteArrayOutputStream */ public ByteArrayOutputStream relatorioProfessorOrientacao(List<Professororientacao> lOrientacao, Date dtinicial, Date dtfinal, Professor coordenador, Campus campus) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); FacesContext faces = FacesContext.getCurrentInstance(); //pega o contexto da aplicacao String realPath = faces.getExternalContext().getRealPath("/"); try { BaseFont fHelvetica = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false); //---------------------------------------------------------------------- //creation of the document with a certain size and certain margins //may want to use PageSize.LETTER instead Document document = new Document(PageSize.A4, 40, 40, 20, 50); document.addAuthor("SisGES"); // optional document.addSubject("Relatrio"); // opcional document.addKeywords("SisGES"); document.addCreator("iText"); //---------------------------------------------------------------------- // creation of the different writers //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("web/resources/report/alunosMatriculados.pdf")); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setBoxSize("header", new Rectangle(36, 54, 559, 788)); //---------------------------------------------------------------------- // ADICIONA HEADER E FOOTER //---------------------------------------------------------------------- HeaderFooter headerFooter = new HeaderFooter(); headerFooter.setY(760f); writer.setPageEvent(headerFooter); //---------------------------------------------------------------------- //ABRE DOCUMENTO PARA ESCRITA //---------------------------------------------------------------------- document.open(); //---------------------------------------------------------------------- //ADICIONAR LOGO NO DOCUMENTO //---------------------------------------------------------------------- Image logoUfu = Image.getInstance(realPath + "/resources/images/logoUFUAta.png"); logoUfu.scaleAbsolute(155, 39);//(largura,altura) logoUfu.isImgTemplate(); //add no template document.add(logoUfu); //---------------------------------------------------------------------- //ADICIONAR CABEALHO //---------------------------------------------------------------------- PdfContentByte univ = writer.getDirectContentUnder(); univ.beginText(); univ.setFontAndSize(fHelvetica, 10); univ.setTextMatrix(349, 816); // x e y univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA"); univ.setTextMatrix(405, 802); // x e y univ.showText("FACULDADE DE COMPUTAO"); univ.setTextMatrix(403, 788); // x e y univ.showText("COORDENADORIA DE ESTGIO "); univ.endText(); String info = "Campus Universitrio - " + campus.getNomecampus() + " - CEP " + campus.getCep() + " - " + campus.getCidade() + " - " + campus.getEstadosigla().toUpperCase(); Chunk txtCampus = new Chunk(info); Paragraph paragraph0 = new Paragraph(); paragraph0.setSpacingBefore(-10); paragraph0.setFont(new Font(fHelvetica, 7)); paragraph0.add(txtCampus); paragraph0.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph0); info = "Telefone: " + coordenador.getTelefone() + " Email: " + coordenador.getEmail(); Chunk txtCoordenador = new Chunk(info); Paragraph paragraph1 = new Paragraph(); paragraph1.setSpacingBefore(-5); paragraph1.setSpacingAfter(10); paragraph1.setFont(new Font(fHelvetica, 7)); paragraph1.add(txtCoordenador); paragraph1.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph1); // PdfContentByte univ = writer.getDirectContentUnder(); // univ.beginText(); // univ.setFontAndSize(fHelvetica, 12); // univ.setTextMatrix(200, 815); // x e y // univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA"); // univ.setTextMatrix(235, 800); // x e y // univ.showText("FACULDADE DE COMPUTAO"); // univ.endText(); // // PdfContentByte univEnd = writer.getDirectContentUnder(); // univEnd.beginText(); // univEnd.setFontAndSize(fHelvetica, 7); // univEnd.setTextMatrix(210, 785); // x e y // univEnd.showText("Campus Universitrio - Santa Mnica - CEP 38408-100 - Uberlndia - MG"); // univEnd.setTextMatrix(260, 775); // x e y // univEnd.showText("Telefone: (34)3239-4144 ou 3239-4393"); // univEnd.endText(); //---------------------------------------------------------------------- //ADICIONAR TITULO //---------------------------------------------------------------------- PdfContentByte t1 = writer.getDirectContentUnder(); t1.beginText(); t1.setFontAndSize(fHelvetica, 14); t1.setTextMatrix(180, 730); // x e y t1.showText("Participao dos professores FACOM"); t1.endText(); PdfContentByte t2 = writer.getDirectContentUnder(); t2.beginText(); t2.setFontAndSize(fHelvetica, 12); t2.setTextMatrix(195, 705); // x e y String periodo = CalendarFormat.getDataBRtoDate(dtinicial) + " at " + CalendarFormat.getDataBRtoDate(dtfinal); t2.showText("Perodo: " + periodo); t2.endText(); //---------------------------------------------------------------------- //TABELA PdfPTable table = new PdfPTable(4); //espao do inicio da pagina table.setSpacingBefore(100f); table.setTotalWidth(100f); table.setWidthPercentage(100); float[] widths = { 20, 30, 35, 15 };//largura das colunas table.setWidths(widths); table.setHeaderRows(1); //CABEALHO DA TABELA Paragraph cabecalho = new Paragraph("Siape"); PdfPCell cell1 = new PdfPCell(cabecalho); // celula cabecalho.getFont().setStyle(Font.BOLD); cabecalho.getFont().setSize(8); cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell1); cabecalho = new Paragraph("Professor"); cabecalho.getFont().setStyle(Font.BOLD); cabecalho.getFont().setSize(8); PdfPCell cell2 = new PdfPCell(cabecalho); // celula cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); cell2.setBorderColor(BaseColor.LIGHT_GRAY); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell2); cabecalho = new Paragraph("Email do Professor"); cabecalho.getFont().setStyle(Font.BOLD); cabecalho.getFont().setSize(8); PdfPCell cell4 = new PdfPCell(cabecalho); // celula cell4.setBackgroundColor(BaseColor.LIGHT_GRAY); cell4.setBorderColor(BaseColor.LIGHT_GRAY); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell4); cabecalho = new Paragraph("Orientaes"); cabecalho.getFont().setStyle(Font.BOLD); cabecalho.getFont().setSize(8); PdfPCell cell3 = new PdfPCell(cabecalho); // celula cell3.setBackgroundColor(BaseColor.LIGHT_GRAY); cell3.setBorderColor(BaseColor.LIGHT_GRAY); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell3); for (int i = 0; i < lOrientacao.size(); i++) { Professororientacao po = lOrientacao.get(i); Paragraph texto = new Paragraph(String.valueOf(po.getSiape())); texto.getFont().setSize(8); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell1); texto = new Paragraph(po.getNome()); texto.getFont().setSize(8); cell2 = new PdfPCell(texto); // celula cell2.setBorderColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); texto = new Paragraph(po.getEmail()); texto.getFont().setSize(8); cell4 = new PdfPCell(texto); // celula cell4.setBorderColor(BaseColor.LIGHT_GRAY); table.addCell(cell4); texto = new Paragraph(String.valueOf(po.getOrientacoes())); texto.getFont().setSize(8); cell3 = new PdfPCell(texto); // celula cell3.setBorderColor(BaseColor.LIGHT_GRAY); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell3); switch (i % 2) { case 0: cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); break; case 1: break; } } //add a tabela document.add(table); //----------------------------------------------------- // distancia do fim da pagina float y = 70f; float x = 160f; //----------------------------------------------------- //linha PdfContentByte linha = writer.getDirectContentUnder(); linha.setLineWidth(1f); // mostrar linha linha.setGrayStroke(0.5f); // 0 = preto, 1 = branco linha.moveTo(x, y); linha.lineTo(450f, y); // ate onde a linha vai linha.stroke(); //------------------------------------------------------ //assinatura PdfContentByte a1 = writer.getDirectContentUnder(); a1.beginText(); a1.setFontAndSize(fHelvetica, 10); a1.setTextMatrix(x + 50, y - 15); // x e y a1.showText("Coordenao de Estgio Supervisionado"); a1.endText(); //------------------------------------------------------ //assinatura PdfContentByte a2 = writer.getDirectContentUnder(); a2.beginText(); a2.setFontAndSize(fHelvetica, 10); a2.setTextMatrix(x + 50, y - 27); // x e y a2.showText("FACOM/UFU"); a2.endText(); //------------------------------------------------------ //add nova pagina document.newPage(); //close document document.close(); } catch (DocumentException | IOException ex) { Logger.getLogger(RelatorioProfessor.class.getName()).log(Level.SEVERE, null, ex); } //return stream com dados return baos; }
From source file:reportes.ServletIntegral.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); ServletConfig config = getServletConfig(); ServletContext context = config.getServletContext(); String path = context.getContextPath(); String realPath = context.getRealPath("/"); response.setContentType("application/pdf"); //Para descargar el PDF response.setHeader("Content-Disposition", "attachment; filename=\"ResultadoIntegral.pdf\""); // step 1: creation of a document-object try {//from w w w .j a v a2 s . c o m Document document = new Document(PageSize.LETTER); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a temporary buffer ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PdfWriter.getInstance(document, buffer); // step 3: we open the document document.open(); // step 4: we add content to the document Paragraph title = new Paragraph( (session.getAttribute("nEmpresa") != null) ? session.getAttribute("nEmpresa").toString() : "Empresa"); title.setAlignment(Element.ALIGN_CENTER); title.setFont(NORMAL); document.add(title); title = new Paragraph("Estado de resultado integral del 01 de Enero al 31 de Diciembre del " + (new Date().getYear() + 1900)); title.setAlignment(Element.ALIGN_CENTER); title.setFont(NORMAL); document.add(title); title = new Paragraph("Cifras en miles de pesos"); title.setAlignment(Element.ALIGN_CENTER); title.setFont(NORMAL); document.add(title); for (int i = 0; i < 2; i++) { document.add(new Paragraph(" ")); } PdfPTable table = new PdfPTable(2); //Obtenemos los datos de la clase ResultadoIntegral ResultadoIntegral r = new ResultadoIntegral(); r.calculaResultado(Integer.parseInt(session.getAttribute("Empresa").toString())); for (int i = 0; i < r.getSaldos().size(); i++) { PdfPCell dato = new PdfPCell(); if (i == 2 || i == 7 || i == 12 || i == 14 || i == 16 || i == 18 || i == 19 || i == 17) { Chunk ch = new Chunk(descripciones[i]); ch.setFont(BOLD_Tot); Phrase ph = new Phrase(ch); dato.setPhrase(ph); } else { Phrase ph = new Phrase(descripciones[i]); dato.setPhrase(ph); } dato.setBorder(Rectangle.NO_BORDER); dato.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(dato); if (r.getValores().size() > 0) { Chunk ch = new Chunk(); if (r.getSaldos().get(i) < 0) { String valor = "(" + (r.getSaldos().get(i) * (-1)) + ")"; ch.append(valor); ch.setFont(NORMAL_Negative); } else { dato.setPhrase(new Phrase("" + r.getSaldos().get(i))); } } else { dato.setPhrase(new Phrase("0.0")); } if (i == 1 || i == 6 || i == 11 || i == 13 || i == 15 || i == 17 || i == 18) { dato.setBorder(Rectangle.BOTTOM); } else { dato.setBorder(Rectangle.NO_BORDER); } dato.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(dato); } document.add(table); document.add(new Paragraph("")); // step 5: we close the document document.close(); // step 6: we output the writer as bytes to the response output DataOutputStream output = new DataOutputStream(response.getOutputStream()); byte[] bytes = buffer.toByteArray(); response.setContentLength(bytes.length); for (int i = 0; i < bytes.length; i++) { output.writeByte(bytes[i]); } output.close(); response.getOutputStream(); //session.removeAttribute("bean"); //session.removeAttribute("producto"); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:utils.PrintInvoice.java
public void getDocument() { try {/* w w w . j a va 2 s. c om*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SaleBill#" + salebill.getId() + ".pdf")); document.open(); //////////////////////////////////////////////////////////////////////////////////// ///////////////////Start Document Here///////////////////////////////// PdfContentByte directContent = writer.getDirectContent(); Paragraph p1 = new Paragraph("SALE BILL"); p1.setFont(FONT[4]); p1.setAlignment(Element.ALIGN_CENTER); document.add(p1); //show the company details here. Phrase company = new Phrase(new Chunk("BIO PHARMA\nAKOT 444101(M.S)", FONT[3])); document.add(company); document.add(new Phrase( "\nLicense No : 20B : AK-88888\n 21B : AK-88889\n Mobile : " + SessionClass.getInstance().getMobileNumber(), FONT[2])); // Phrase mobNum = new Phrase(" Mobile : "+SessionClass.getInstance().getMobileNumber() ); // mobNum.setFont(FONT[2]); // ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, mobNum, 35, 710, 0); System.out.println(dateFormatter.format(salebill.getBillDate())); //show the invoice details // String txt = "Bill No. : " + salebill.getId()+"\nBill Date : " + dateFormatter.format(salebill.getBillDate()) +; Phrase invoiceDetails = new Phrase("Bill No. : " + salebill.getId()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 693, 0); invoiceDetails = new Phrase("Bill Date : " + dateFormatter2.format(salebill.getBillDate())); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 681, 0); invoiceDetails = new Phrase("Mode of Payment : " + salebill.getMode()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 668, 0); //show the customer details Customer c = salebill.getCustomerId(); Phrase custDetails = new Phrase("SOLD TO", FONT[3]); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 693, 0); custDetails = new Phrase(c.getCompanyName()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 681, 0); custDetails = new Phrase(c.getSiteAddress()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 668, 0); custDetails = new Phrase("Licence : " + c.getLicenceNo()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 655, 0); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); //Item Particulars are shown here PdfPTable table = new PdfPTable(7); table.setTotalWidth(new float[] { 175, 80, 80, 50, 50, 50, 75 }); table.setHeaderRows(1); //headers table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell("Particulars"); table.addCell("Batch"); table.addCell("Expiry"); table.addCell("MRP"); table.addCell("Rate"); table.addCell("Qnty"); table.addCell("SubTotal"); table.getDefaultCell().setBackgroundColor(null); table.setSpacingAfter(5.0f); List<SaleBillPharmaItem> items = salebill.getSaleBillPharmaItemList(); for (int i = 0; i < items.size(); i++) { PdfPCell desc = new PdfPCell(new Phrase(items.get(i).getItemName())); table.addCell(desc); PdfPCell batch = new PdfPCell(new Phrase(items.get(i).getBatch())); table.addCell(batch); PdfPCell expiry = null; Date tDate = null; try { tDate = dateFormatter2.parse(items.get(i).getExpDate()); } catch (ParseException ex) { Logger.getLogger(PrintInvoice.class.getName()).log(Level.SEVERE, null, ex); } expiry = new PdfPCell(new Phrase(dateFormatter.format(tDate))); table.addCell(expiry); PdfPCell mrp = new PdfPCell(new Phrase(items.get(i).getMrp() + "")); // //mrp.setBorderColor(BaseColor.WHITE); // mrp.setBorderColorLeft(BaseColor.BLACK); // mrp.setBorderColorRight(BaseColor.WHITE); table.addCell(mrp); PdfPCell rate = new PdfPCell(new Phrase(items.get(i).getItemRate() + "")); // //rate.setBorderColor(BaseColor.WHITE); // rate.setBorderColorLeft(BaseColor.BLACK); // rate.setBorderColorRight(BaseColor.WHITE); table.addCell(rate); PdfPCell quantity = new PdfPCell(new Phrase(items.get(i).getQnty() + "")); // //quantity.setBorderColor(BaseColor.WHITE); // quantity.setBorderColorLeft(BaseColor.BLACK); // quantity.setBorderColorRight(BaseColor.WHITE); table.addCell(quantity); PdfPCell subtotal = new PdfPCell(new Phrase(items.get(i).getAmt() + "")); // //subtotal.setBorderColor(BaseColor.WHITE); // subtotal.setBorderColorLeft(BaseColor.BLACK); // subtotal.setBorderColorRight(BaseColor.WHITE); table.addCell(subtotal); } //now show the sub details //PdfPCell finalCell = new PdfPCell(new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + " Total Amount : Rs ")); //Todo change code here to show vat amount when there is vat number PdfPCell finalCell = new PdfPCell( new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + " Total Amount : Rs ")); finalCell.setHorizontalAlignment(Element.ALIGN_RIGHT); finalCell.setColspan(6); table.addCell(finalCell); table.addCell("" + salebill.getTotalAmt()); PdfPCell cdCell = new PdfPCell(new Phrase("Cash Discount (2 %) : (-) Rs")); cdCell.setColspan(6); cdCell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cdCell); table.addCell("" + salebill.getDiscount()); PdfPCell finalAmtCell = new PdfPCell(new Phrase("Final Amount : Rs")); finalAmtCell.setColspan(6); finalAmtCell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(finalAmtCell); table.addCell("" + salebill.getFinalAmt()); document.add(table); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); Paragraph sign = new Paragraph(new Chunk("Authorized signatory\n(BIO PHARMA)")); sign.setAlignment(Element.ALIGN_RIGHT); document.add(sign); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); Paragraph p = new Paragraph("THANK YOU FOR YOUR BUSINESS"); p.setFont(FONT[4]); p.setAlignment(Element.ALIGN_CENTER); document.add(p); ///////////////////End Documnet here////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// document.close(); // no need to close PDFwriter? } catch (DocumentException | FileNotFoundException e) { //LOGGER e.printStackTrace(); Stage dialogStage = new Stage(); dialogStage.setTitle("Printing Error"); dialogStage.initModality(Modality.WINDOW_MODAL); dialogStage.setScene(new Scene(VBoxBuilder.create() .children(new Text( "The file to be printed is already open \n. Please close the file and Print Again")) .alignment(Pos.CENTER).padding(new Insets(50)).build())); dialogStage.show(); } }
From source file:validator.Invoice.java
public static boolean printInvoice(HttpServletResponse response) throws DocumentException, FileNotFoundException { Document document = new Document(); java.net.URL path = LogData.class.getResource("/"); String destinationDir;/* w ww . j a v a 2 s . co m*/ destinationDir = path.toString(); destinationDir = destinationDir.substring(destinationDir.lastIndexOf(":") + 1, destinationDir.indexOf("WEB-INF")); String filePath = destinationDir + "invoice" + "/"; ; File fileName = new File(filePath); if (!fileName.exists()) { fileName.mkdir(); } filePath = filePath + "invoice" + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(filePath)); document.open(); Paragraph paragraph1 = new Paragraph("Invoice"); paragraph1.setAlignment(Element.ALIGN_CENTER); paragraph1.setFont(FontFactory.getFont(FontFactory.COURIER, 18, Font.BOLD, new CMYKColor(0, 255, 0, 0))); Paragraph datePara = new Paragraph("Date :" + new Date()); datePara.setAlignment(Element.ALIGN_RIGHT); File file = new File(filePath); PdfPTable table = new PdfPTable(2); table.setSpacingBefore(25); table.setWidthPercentage(100); table.setSpacingAfter(25); PdfPCell c1 = new PdfPCell(new Phrase("Description")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(" Amount ")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); table.addCell(" " + " "); table.addCell(" " + " "); table.addCell(" Total Balance amount :"); table.addCell(" " + " "); Paragraph amountPara = new Paragraph("\nPaid Amount: "); Paragraph forCom = new Paragraph("\n For Company: "); document.open(); document.add(paragraph1); document.add(datePara); document.add(table); document.add(amountPara); document.add(forCom); document.close(); streamImageFile(file, response); return true; }
From source file:windows.wzListWindow.java
private void printDocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printDocActionPerformed Document document = new Document(); Footer ft = new Footer(); companyAdress comp = new companyAdress(); try {//from ww w.j a v a 2 s . c om BaseFont ft1 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); Font ffont = new Font(ft1, 12); BaseFont ft3 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); Font bold = new Font(ft1, 12, Font.BOLD); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test.pdf")); document.open(); Paragraph pr = new Paragraph(); pr.setFont(ffont); writer.setPageEvent(ft); ContractorEntity contractor = wz .getContractor(Integer.valueOf(WZTable.getValueAt(WZTable.getSelectedRow(), 2).toString())); pr.add(WZTable.getValueAt(WZTable.getSelectedRow(), 4).toString()); pr.setAlignment(Element.ALIGN_RIGHT); document.add(pr); pr.clear(); if ("SPRZT WYDANY".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 11).toString())) { Paragraph nr = new Paragraph("WYADNIE SPRZTU NR ", ffont); String yearSlashnr = WZTable.getValueAt(WZTable.getSelectedRow(), 1).toString(); nr.add(new Chunk(yearSlashnr, bold)); nr.setAlignment(Element.ALIGN_LEFT); document.add(nr); if ("WS".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 12).toString())) { pr.setAlignment(Element.ALIGN_LEFT); DocEntity docPS = wz.getDocument(wz.getPSForWs( Integer.valueOf(WZTable.getValueAt(WZTable.getSelectedRow(), 0).toString()))); pr.add("DOTYCZY: PS NR " + docPS.getDocNumber()); document.add(pr); pr.clear(); pr.setAlignment(Element.ALIGN_RIGHT); } } if ("SPRZT PRZYJTY".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 11).toString())) { int rok = Timestamp.valueOf(WZTable.getValueAt(WZTable.getSelectedRow(), 4).toString()).getYear() + 1900; Paragraph nr = new Paragraph("PRZYJCIE SPRZTU NR ", ffont); String yearSlashnr = rok + "/" + WZTable.getValueAt(WZTable.getSelectedRow(), 1).toString(); nr.add(new Chunk(yearSlashnr, bold)); nr.setAlignment(Element.ALIGN_LEFT); document.add(nr); } pr.clear(); pr.add(Chunk.NEWLINE); pr.add(Chunk.NEWLINE); document.add(pr); pr.clear(); pr.setAlignment(Element.ALIGN_LEFT); pr.add(comp.getName()); pr.add(Chunk.NEWLINE); pr.add("ul. " + comp.getStreet()); pr.add(Chunk.NEWLINE); pr.add(comp.getPostal() + " " + comp.getCity()); pr.add(Chunk.NEWLINE); pr.add("NIP: " + comp.getNip()); pr.add(Chunk.NEWLINE); pr.add("Tel: " + comp.getPhone()); pr.add(Chunk.NEWLINE); pr.add("Fax: " + comp.getFax()); pr.add(Chunk.NEWLINE); pr.add("E-mail: " + comp.getEmail()); pr.add(Chunk.NEWLINE); pr.add(Chunk.NEWLINE); pr.add("KLIENT:"); pr.add(Chunk.NEWLINE); pr.add(contractor.getName()); pr.add(Chunk.NEWLINE); pr.add("ul. " + contractor.getStreet()); pr.add(Chunk.NEWLINE); pr.add(contractor.getPostalCode() + " " + contractor.getCity()); pr.add(Chunk.NEWLINE); pr.add("NIP: " + contractor.getNip()); pr.add(Chunk.NEWLINE); pr.add("Tel: " + contractor.getPhone()); pr.add(Chunk.NEWLINE); pr.add("E-mail: " + contractor.getEmail()); document.add(pr); pr.clear(); pr.add(Chunk.NEWLINE); pr.add(Chunk.NEWLINE); pr.add("PRZYJTE URZDZENIA:"); document.add(pr); //PUT IMAGE FROM DRIVE java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("C:/GIT/support/logo.jpg"); Image img = com.itextpdf.text.Image.getInstance(awtImage, null); int indentation = 0; float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin() - indentation) / img.getWidth()) * 20; img.scalePercent(scaler); img.setAbsolutePosition(document.right() - 90, document.top() - 150); document.add(new Paragraph()); document.add(img); //ADD TABLE PdfPTable table = new PdfPTable(7); // 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, 4f, 3f, 2f, 2f, 6f, 6f }; table.setWidths(columnWidths); BaseFont ft2 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); Font headerFont = new Font(ft2, 9); Paragraph pos1 = new Paragraph("", headerFont); Paragraph pos2 = new Paragraph("", headerFont); Paragraph pos3 = new Paragraph("", headerFont); Paragraph pos4 = new Paragraph("", headerFont); Paragraph pos5 = new Paragraph("", headerFont); Paragraph pos6 = new Paragraph("", headerFont); Paragraph pos7 = new Paragraph("", headerFont); //FORMATING TABLE pos1.clear(); pos1.add("LP"); PdfPCell cell1 = new PdfPCell(pos1); cell1.setBorderColor(BaseColor.BLACK); cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell1); pos2.clear(); pos2.add("NAZWA"); PdfPCell cell2 = new PdfPCell(pos2); cell2.setBorderColor(BaseColor.BLACK); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell2); pos3.clear(); pos3.add("NR SERYJNY"); PdfPCell cell3 = new PdfPCell(pos3); cell3.setBorderColor(BaseColor.BLACK); cell3.setBackgroundColor(BaseColor.LIGHT_GRAY); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell3); pos4.clear(); pos4.add("CENA NETTO"); PdfPCell cell4 = new PdfPCell(pos4); cell4.setBorderColor(BaseColor.BLACK); cell4.setBackgroundColor(BaseColor.LIGHT_GRAY); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell4); pos5.clear(); pos5.add("CENA BRUTTO"); PdfPCell cell5 = new PdfPCell(pos5); cell5.setBorderColor(BaseColor.BLACK); cell5.setBackgroundColor(BaseColor.LIGHT_GRAY); cell5.setHorizontalAlignment(Element.ALIGN_CENTER); cell5.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell5); pos6.clear(); pos6.add("PROBLEM"); PdfPCell cell6 = new PdfPCell(pos6); cell6.setBorderColor(BaseColor.BLACK); cell6.setBackgroundColor(BaseColor.LIGHT_GRAY); cell6.setHorizontalAlignment(Element.ALIGN_CENTER); cell6.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell6); pos7.clear(); pos7.add("NAPRAWA"); PdfPCell cell7 = new PdfPCell(pos7); cell7.setBorderColor(BaseColor.BLACK); cell7.setBackgroundColor(BaseColor.LIGHT_GRAY); cell7.setHorizontalAlignment(Element.ALIGN_CENTER); cell7.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell7); cell2.setHorizontalAlignment(Element.ALIGN_LEFT); cell3.setHorizontalAlignment(Element.ALIGN_LEFT); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell5.setHorizontalAlignment(Element.ALIGN_RIGHT); cell6.setHorizontalAlignment(Element.ALIGN_LEFT); cell7.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setBackgroundColor(BaseColor.WHITE); cell2.setBackgroundColor(BaseColor.WHITE); cell3.setBackgroundColor(BaseColor.WHITE); cell4.setBackgroundColor(BaseColor.WHITE); cell5.setBackgroundColor(BaseColor.WHITE); cell6.setBackgroundColor(BaseColor.WHITE); cell7.setBackgroundColor(BaseColor.WHITE); int counter = 1; for (DocProductEntity prod : productToShow) { //col 1 (LP) table.addCell(createCell("" + counter, Element.ALIGN_CENTER)); counter++; //col 2 (NAME) table.addCell(createCell(prod.getName(), Element.ALIGN_LEFT)); //col 3 (NR SER) table.addCell(createCell(prod.getSerial(), Element.ALIGN_CENTER)); //col 4 (NETTO) table.addCell(createCell(String.valueOf(prod.getPrice()), Element.ALIGN_RIGHT)); //col 5 (BRUTTO) table.addCell(createCell(String.valueOf(prod.getPrice() + (prod.getPrice() * 0.23)), Element.ALIGN_RIGHT)); //col 6 (PROBLEM) table.addCell(createCell(prod.getProblem(), Element.ALIGN_LEFT)); //col 7 (REPAIRS) table.addCell(createCell(prod.getRepair(), Element.ALIGN_LEFT)); } document.add(table); pr.setAlignment(Element.ALIGN_RIGHT); pr.clear(); pr.add("PRZEWIDYWANIY KOSZT NAPRAWY:"); document.add(pr); pr.clear(); pr.add("Razem netto: " + nettoLabel.getText() + " Razem brutto: " + bruttoLabel.getText()); document.add(pr); pr.clear(); pr.add("Sownie: " + amountInWords(Float.valueOf(bruttoLabel.getText().replace(",", ".")))); document.add(pr); pr.clear(); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); pr.add("................................................."); document.add(pr); pr.clear(); pr.add("Podpis i piecztka pracownika"); document.add(pr); if ("SPRZT WYDANY".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 11).toString())) { pr.clear(); pr.add(Chunk.NEWLINE); pr.add(Chunk.NEWLINE); pr.add("................................................."); document.add(pr); pr.clear(); pr.add("Sprzt odebraem (Podpis klienta)"); document.add(pr); } //CLOSING DOCUMENT document.close(); writer.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { StampPageXofY numeration = new StampPageXofY(); tempName = nowTimestamp(); numeration.manipulatePdf("test.pdf", tempName + ".pdf"); } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } //OPEN READY DOCUMENT try { Desktop.getDesktop().open(new File(tempName + ".pdf")); } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } }