List of usage examples for com.itextpdf.text.pdf PdfWriter getDirectContent
public PdfContentByte getDirectContent()
From source file:eeebees.BarCode128.java
public static void main(String[] args) throws FileNotFoundException, DocumentException { Document document = new Document(new Rectangle(PageSize.A4)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:/Java4s_BarCode_128.pdf")); document.open();//from w ww. j a v a 2 s . com document.add(new Paragraph("Code_128 Format_Java4s.com")); Barcode128 code128 = new Barcode128(); code128.setGenerateChecksum(true); code128.setCode("1234554321"); document.add(code128.createImageWithBarcode(writer.getDirectContent(), null, null)); document.close(); System.out.println("Document Generated...!!!!!!"); }
From source file:engine.Pdf.java
public static void drawLines(Vector<HoughLine> vectors, PdfWriter writer) { PdfContentByte canvas = writer.getDirectContent(); canvas.setColorStroke(BaseColor.RED); canvas.setLineWidth(1);//from ww w . j av a 2 s . c o m for (int i = 0; i < vectors.size(); i++) { HoughLine line = vectors.elementAt(i); canvas.moveTo(line.x1, line.y1); canvas.lineTo(line.x2, line.y2); canvas.closePathStroke(); } // canvas.closePathStroke(); canvas.setColorFill(BaseColor.BLUE); canvas.fill(); }
From source file:engine.Pdf.java
public static void drawLines(PdfWriter writer) { PdfContentByte canvas = writer.getDirectContent(); canvas.setColorStroke(BaseColor.RED); canvas.setLineWidth(3);/* ww w .j a v a 2 s.c o m*/ canvas.moveTo(20, 30); canvas.lineTo(900, 900); canvas.lineTo(220, 330); canvas.closePathStroke(); canvas.setColorFill(BaseColor.RED); canvas.fill(); }
From source file:es.clinica.veterinaria.facturas.FacturaPdf.java
public void createPdf() { try {//from w w w . j a va 2s.com PdfWriter docWriter = null; initializeFonts(); FacturaDAO facturaDao = new FacturaDAO(); document = new Document(PageSize.A4); String fecha = new SimpleDateFormat("yyyy-MM-dd").format(factura.getFecha()); String sfactura = getDirectorio().toString() + "/factura-" + fecha + "-" + factura.getNumero() + ".pdf"; System.out.println("Directorio factura: " + sfactura); docWriter = PdfWriter.getInstance(document, new FileOutputStream(sfactura)); document.open(); PdfContentByte cb = docWriter.getDirectContent(); addMetaData(document); addLogo(document); generateHeader(document, cb); addTitlePage(document); document.add(createTable()); document.close(); factura.setRuta("../facturaspdf/factura-" + fecha + "-" + factura.getNumero() + ".pdf"); facturaDao.updatePDF(factura); System.out.println("Documento cerrado"); } catch (Exception e) { e.printStackTrace(); } }
From source file:Excel.pdfsJavaGenerador.java
public void run() { Document documento = new Document(); documento.setPageSize(PageSize.A4.rotate()); int i = 1;/*w ww . ja v a 2 s.c o m*/ String arch = periodo + "_Iva Ventas.pdf"; File fich = new File(arch); FileOutputStream fichero; try { pdfsJavaGenerador pdf; ArrayList listado = new ArrayList(); String sql = "select * from ivaventas where periodo='" + periodo + "' order by numero"; Transaccionable tra = new ConeccionLocal(); ResultSet rs = tra.leerConjuntoDeRegistros(sql); while (rs.next()) { pdf = new pdfsJavaGenerador(); pdf.setComprobante(rs.getString("comprobante")); pdf.setFecha(rs.getString("fecha")); pdf.setNumeroFactura(rs.getString("numero")); pdf.setRazonSocial(rs.getString("cliente")); pdf.setCondicionIva(rs.getString("condicion")); pdf.setCuit(rs.getString("cuit")); pdf.setNeto(rs.getString("neto")); pdf.setIva(rs.getString("iva")); pdf.setTotal(rs.getString("total")); listado.add(pdf); } rs.close(); Integer totalItems = listado.size(); Integer totalPaginas = totalItems / 46; Integer contadorPaginas = 1; totalPaginas = totalPaginas + 1; System.out.println(" items " + totalItems + " paginas " + totalPaginas); fichero = new FileOutputStream(arch); PdfWriter writer = PdfWriter.getInstance(documento, fichero); documento.open(); //writer.addPageDictEntry(PdfName.ROTATE,PdfPage.SEASCAPE); writer.addPageDictEntry(PdfName.ROTATE, null); PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.setFontAndSize(bf, 12); cb.beginText(); //cb.setTextMatrix(250,820); //cb.showText("Subdiario de IVA Ventas"); cb.setFontAndSize(bf, 10); cb.setTextMatrix(20, 480); cb.showText("Periodo " + periodo); //cb.setTextMatrix(750,550); //cb.showText("Hoja "+contadorPaginas+" de "+totalPaginas); int renglon = 460; String vencimiento; String descripcion; String monto; String recargo; String total; String totalFinal; Double tot = 0.00; String razonSocial; int itt = 0; //aca empieza la iteracion //encabezados bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.setFontAndSize(bf, 8); cb.setTextMatrix(20, renglon); cb.showText("Cbte"); cb.setTextMatrix(50, renglon); cb.showText("Fecha"); cb.setTextMatrix(90, renglon); cb.showText("Nro Factura"); cb.setTextMatrix(150, renglon); cb.showText("Cliente"); cb.setTextMatrix(500, renglon); //tot=saldo.getCantidad() * saldo.getPrecioUnitario(); cb.showText("Cond"); cb.setTextMatrix(540, renglon); cb.showText("C.U.I.T."); cb.setTextMatrix(610, renglon); cb.showText("Neto"); cb.setTextMatrix(660, renglon); cb.showText("I.V.A."); cb.setTextMatrix(700, renglon); cb.showText("Imp. Int."); cb.setTextMatrix(760, renglon); cb.showText("Total"); renglon = renglon - 20; //fin encabezados bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.setFontAndSize(bf, 6); Iterator itl = listado.listIterator(); //vencimiento="Esta cotizacin tendr vigencia 30 das "; Double montoCIva = 0.00; Double descuento = 0.00; Double descUnitario = 0.00; Double descTotal = 0.00; Double montoCIvaTotal = 0.00; Double descuentoTotal = 0.00; Double descUnitarioTotal = 0.00; Double descTotalTotal = 0.00; String descripcionArt = null; while (itl.hasNext()) { pdf = (pdfsJavaGenerador) itl.next(); //vencimiento=saldo.getVencimientoString(); /* descripcion="Numero Resumen de cta "; montoCIva=saldo.getPrecioUnitario() * 1.21; monto=Numeros.ConvertirNumero(montoCIva); recargo="10%"; total="nada"; */ //recargo=String.valueOf(saldo.getRecargo()); //tot=tot + saldo.getTotal(); //total=String.valueOf(saldo.getTotal()); cb.setTextMatrix(20, renglon); cb.showText(pdf.getComprobante()); cb.setTextMatrix(45, renglon); cb.showText(pdf.getFecha()); cb.setTextMatrix(90, renglon); cb.showText(pdf.getNumeroFactura()); cb.setTextMatrix(150, renglon); razonSocial = pdf.getRazonSocial(); cb.showText(razonSocial); cb.setTextMatrix(500, renglon); cb.showText(pdf.getCondicionIva()); cb.setTextMatrix(540, renglon); cb.showText(pdf.getCuit()); cb.setTextMatrix(600, renglon); if (pdf.getComprobante().equals("N.C.")) { String neto = pdf.getNeto(); String iva = pdf.getIva(); String totalP = pdf.getTotal(); pdf.setNeto("-" + neto.trim()); pdf.setIva("-" + iva.trim()); pdf.setTotal("-" + totalP.trim()); } montoCIva = montoCIva + Numeros.ConvertirStringADouble(pdf.getNeto()); descuento = descuento + Numeros.ConvertirStringADouble(pdf.getIva()); descTotal = descTotal + Numeros.ConvertirStringADouble(pdf.getTotal()); cb.showText(pdf.getNeto()); cb.setTextMatrix(650, renglon); cb.showText(pdf.getIva()); cb.setTextMatrix(710, renglon); cb.showText("0.00"); cb.setTextMatrix(750, renglon); cb.showText(pdf.getTotal()); //descuento=descuento+saldo.getDescuento(); renglon = renglon - 10; if (renglon < 30) { bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.setFontAndSize(bf, 7); cb.setTextMatrix(550, renglon); cb.showText("Subtotal:"); cb.setTextMatrix(600, renglon); cb.showText(Numeros.ConvetirNumeroDosDigitos(montoCIva)); cb.setTextMatrix(650, renglon); cb.showText(Numeros.ConvetirNumeroDosDigitos(descuento)); cb.setTextMatrix(710, renglon); cb.showText("0.00"); cb.setTextMatrix(750, renglon); cb.showText(Numeros.ConvetirNumeroDosDigitos(descTotal)); montoCIvaTotal = montoCIvaTotal + montoCIva; descuentoTotal = descuentoTotal + descuento; descTotalTotal = descTotalTotal + descTotal; descuento = 0.00; descTotal = 0.00; montoCIva = 0.00; renglon = 460; cb.endText(); documento.newPage(); documento.setPageSize(PageSize.A4.rotate()); cb.beginText(); contadorPaginas++; cb.setFontAndSize(bf, 12); //cb.setTextMatrix(250,820); //cb.showText("Subdiario de IVA Ventas"); cb.setFontAndSize(bf, 10); cb.setTextMatrix(20, 480); cb.showText("Periodo " + periodo); //cb.setTextMatrix(750,550); //cb.showText("Hoja "+contadorPaginas+" de "+totalPaginas); //aca empieza la iteracion //encabezados bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.setFontAndSize(bf, 8); cb.setTextMatrix(20, renglon); cb.showText("Cbte"); cb.setTextMatrix(50, renglon); cb.showText("Fecha"); cb.setTextMatrix(90, renglon); cb.showText("Nro Factura"); cb.setTextMatrix(150, renglon); cb.showText("Cliente"); cb.setTextMatrix(500, renglon); //tot=saldo.getCantidad() * saldo.getPrecioUnitario(); cb.showText("Cond"); cb.setTextMatrix(540, renglon); cb.showText("C.U.I.T."); cb.setTextMatrix(610, renglon); cb.showText("Neto"); cb.setTextMatrix(660, renglon); cb.showText("I.V.A."); cb.setTextMatrix(700, renglon); cb.showText("Imp. Int."); cb.setTextMatrix(760, renglon); cb.showText("Total"); renglon = renglon - 20; //fin encabezados bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.setFontAndSize(bf, 6); } } bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.setFontAndSize(bf, 7); cb.setTextMatrix(540, renglon); cb.showText("Subtotal:"); cb.setTextMatrix(600, renglon); cb.showText(Numeros.ConvetirNumeroDosDigitos(montoCIva)); cb.setTextMatrix(650, renglon); cb.showText(Numeros.ConvetirNumeroDosDigitos(descuento)); cb.setTextMatrix(710, renglon); cb.showText("0.00"); cb.setTextMatrix(750, renglon); cb.showText(Numeros.ConvetirNumeroDosDigitos(descTotal)); renglon = renglon - 10; montoCIvaTotal = montoCIvaTotal + montoCIva; descuentoTotal = descuentoTotal + descuento; descTotalTotal = descTotalTotal + descTotal; cb.setTextMatrix(540, renglon); cb.showText("Total:"); cb.setTextMatrix(600, renglon); cb.showText(Numeros.ConvetirNumeroDosDigitos(montoCIvaTotal)); cb.setTextMatrix(650, renglon); cb.showText(Numeros.ConvetirNumeroDosDigitos(descuentoTotal)); cb.setTextMatrix(710, renglon); cb.showText("0.00"); cb.setTextMatrix(750, renglon); cb.showText(Numeros.ConvetirNumeroDosDigitos(descTotalTotal)); descuento = 0.00; descTotal = 0.00; montoCIva = 0.00; cb.endText(); documento.close(); File f = new File(arch); if (f.exists()) { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + arch); } int confirmacion = 0; /* if(doc.getArchivo().isEmpty()){ }else{ confirmacion=JOptionPane.showConfirmDialog(null, "DESEA NOTIFICAR POR MAIL?"); if(confirmacion==0){ //JOptionPane.showMessageDialog(null,"acepto"); } } */ System.out.println("eligio " + confirmacion); } catch (FileNotFoundException ex) { Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Export.DocOfReCoSeguro.java
public static void docSeguros(String nomeSeguro, String user, String arquivo, String numDebito, String tileDoc, int idReseguro, boolean isReseguroOfNICON) { String reString;//from www .j a v a 2 s . c om try { Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f); Font fontLinha = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 0.000000358f); Font fontCabecalhoS = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f); Font fontCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontCorpoS = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f, Font.UNDERLINE); Font fontCorpoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontNull = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 4f); Font fontMenor = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 3f); DataResseguro reS = DataReseguro.getDadosReseguro(idReseguro); PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 80, 20 }); pTableEmpresaPricipal.setWidthPercentage(90); PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres2 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres4 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1); PdfPTable pTableFatura = new PdfPTable(new float[] { 80, 20 }); PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoN)); pCellNomeEmpresa.setBorder(0); PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN)); pCellNomeEndereco.setBorder(0); PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN)); pCellCaixaPostal.setBorder(0); PdfPCell pCellTeleFax = new PdfPCell( new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN)); pCellTeleFax.setBorder(0); PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN)); pCellSociedade.setBorder(0); PdfPCell pCellCapital = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAPITALSOCIAL, fontCabecalhoN)); pCellCapital.setBorder(0); PdfPCell pCellPolice = new PdfPCell( new Phrase(ConfigDoc.Empresa.APOLICE + reS.getAPOLICE(), fontCabecalhoN)); pCellPolice.setBorder(0); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(120f, 100f); pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa); pTableEmpresaInforImpres1.addCell(pCellNomeEndereco); pTableEmpresaInforImpres1.addCell(pCellCaixaPostal); pTableEmpresaInforImpres1.addCell(pCellTeleFax); pTableEmpresaInforImpres1.addCell(pCellSociedade); pTableEmpresaInforImpres2.addCell(pCellCapital); pTableEmpresaInforImpres2.addCell(pCellPolice); PdfPCell cellTabela1 = new PdfPCell(pTableEmpresaInforImpres2); cellTabela1.setBorder(0); pTableEmpresaInforImpres4.addCell(cellTabela1); PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1); cellTabela3.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela3); PdfPCell cellTabela4 = new PdfPCell(pTableEmpresaInforImpres4); cellTabela4.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela4); PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5); cellTabela5.setBorder(0); pTableEmpresaPricipal.addCell(cellTabela5); PdfPCell cellTabela6 = new PdfPCell(imageEmpresa); cellTabela6.setBorder(0); cellTabela6.setHorizontalAlignment(Element.ALIGN_RIGHT); pTableEmpresaPricipal.addCell(cellTabela6); PdfPTable pTableLinha = new PdfPTable(1); pTableLinha.setWidthPercentage(90); PdfPCell linha = new PdfPCell(new Phrase(" ", fontLinha)); linha.setBorderWidthTop(0.5f); linha.setBorderWidthBottom(0); linha.setBorderWidthLeft(0); linha.setBorderWidthRight(0); pTableLinha.addCell(linha); /** * Tile Doc start */ /* PdfPTable pTableTileDoc = new PdfPTable(new float[]{50, 50}); PdfPCell cellTileDoc = new PdfPCell(new Phrase(tileDoc, fontCabecalhoS)); cellTileDoc.setColspan(2); cellTileDoc.setPaddingTop(10f); cellTileDoc.setPaddingBottom(20f); cellTileDoc.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellTileDoc.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellTileDoc); Paragraph pTile = new Paragraph(); pTile.add(new Phrase("DEBIT: ", fontCorpoN)); pTile.add(new Phrase("NiCON Seguros STP", fontCorpoN)); PdfPCell cellDebit = new PdfPCell(pTile); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); Paragraph pNotaNum = new Paragraph(); pNotaNum.add(new Phrase("DEBIT NOTE NO: ", fontCorpoN)); pNotaNum.add(new Phrase("05525", fontCorpo)); cellDebit = new PdfPCell(pNotaNum); cellDebit.setPaddingLeft(20f); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); cellDebit = new PdfPCell(new Phrase(" Avenida Marginal 12 de Junlho, 977", fontCorpo)); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); Paragraph pDate = new Paragraph(); pDate.add(new Phrase("Date: ", fontCorpoN)); SimpleDateFormat format = new SimpleDateFormat("dd MMMM',' yyyy",new Locale("pt", "BR")); pDate.add(new Phrase(format.format(new Date()), fontCorpo)); cellDebit = new PdfPCell(pDate); cellDebit.setBorder(PdfPCell.NO_BORDER); cellDebit.setPaddingLeft(20f); pTableTileDoc.addCell(cellDebit); cellDebit = new PdfPCell(new Phrase(" Cx Postal 556-So Tom", fontCorpo)); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); cellDebit = new PdfPCell(new Phrase(" ")); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); */ /** * Tile Doc end */ ArrayList<DataEmpresa> listaDataEmpresas = DataReseguro.getDadosEmpresa(idReseguro); /** * Data Parte 1 Start */ PdfPTable pTableDataPart1 = new PdfPTable(new float[] { 18f, 82f }); pTableDataPart1.setWidthPercentage(90); PdfPCell cellDataPart1 = new PdfPCell(new Phrase("EMPRESA LIDER:", fontCorpoN)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(10f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell( new Phrase(((!isReseguroOfNICON) ? listaDataEmpresas.get(0).getEMPRESA().toUpperCase() : ConfigDoc.Empresa.NOME), fontCorpo)); cellDataPart1.setPaddingTop(10f); cellDataPart1.setPaddingBottom(5f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("CONTRATO N:", fontCorpoN)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase(reS.getAPOLICE(), fontCorpo)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("DESCRIO:", fontCorpoN)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase(reS.getDESCRICAO(), fontCorpo)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("PERIODO:", fontCorpoN)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase(reS.getINICIO() + " - " + reS.getFIM(), fontCorpo)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("LIMITE:", fontCorpoN)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase((covertDouble(reS.getLIMITE()) == null) ? reS.getLIMITE() : Moeda.format(covertDouble(reS.getLIMITE())), fontCorpo)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("MOEDA:", fontCorpoN)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(10f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase(reS.getMOEDA(), fontCorpo)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(10f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); /** * Data Part 1 end */ /** * Data Part 2 start */ PdfPTable pTableDataPart2 = new PdfPTable(new float[] { 33.333333333f, 33.333333333f, 33.333333333f }); pTableDataPart2.setWidthPercentage(90); PdfPCell cellDataPart2 = new PdfPCell(new Phrase("PREMIO GROSSO:", fontCorpoN)); cellDataPart2.setColspan(2); cellDataPart2.setBorder(PdfPCell.NO_BORDER); cellDataPart2.setPaddingTop(10f); cellDataPart2.setPaddingBottom(5f); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase( Moeda.format(Double.valueOf(reS.getPREMIOGROSSO().replace(',', '.'))) + " " + reS.getMOEDA(), fontCorpo)); cellDataPart2.setPaddingTop(10f); cellDataPart2.setPaddingBottom(5f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase("DEDUO:", fontCorpoN)); cellDataPart2.setBorder(PdfPCell.NO_BORDER); cellDataPart2.setColspan(2); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(5f); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase(reS.getDEDUCAO() + "%", fontCorpo)); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(5f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase("LIQUIDO:", fontCorpoN)); cellDataPart2.setBorder(PdfPCell.NO_BORDER); cellDataPart2.setColspan(2); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(5f); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase( Moeda.format(Double.valueOf(reS.getPREMIOGROSSO().replace(',', '.'))) + " " + reS.getMOEDA(), fontCorpo)); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(5f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase("TOTAL:", fontCorpoN)); cellDataPart2.setBorder(PdfPCell.NO_BORDER); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(10f); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase("100%", fontCorpo)); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(10f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase( Moeda.format(Double.valueOf(reS.getTOTAL().replace(',', '.'))) + " " + reS.getMOEDA(), fontCorpo)); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(10f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); // cellDataPart2 = new PdfPCell(new Phrase("Your faithfully", fontCorpo)); // cellDataPart2.setColspan(3); // cellDataPart2.setPaddingTop(5f); // cellDataPart2.setPaddingBottom(0.7f); // cellDataPart2.setBorder(PdfPCell.NO_BORDER); // pTableDataPart2.addCell(cellDataPart2); // cellDataPart2 = new PdfPCell(new Phrase("THE UNITED AFRICAN INSURANCE BROKERS LTD", fontCorpo)); // cellDataPart2.setColspan(3); // cellDataPart2.setPaddingTop(0.7f); // cellDataPart2.setPaddingBottom(10F); // cellDataPart2.setBorder(PdfPCell.NO_BORDER); // pTableDataPart2.addCell(cellDataPart2); /** * Data Part 2 end */ PdfPTable pTableSecureter = new PdfPTable(new float[] { 30f, 30f, 40f }); PdfPCell cellSecureterNull = new PdfPCell(new Phrase(" ", fontCorpoN)); cellSecureterNull.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellSecureterNull.setPaddingTop(2f); cellSecureterNull.setPaddingBottom(2f); cellSecureterNull.setColspan(3); cellSecureterNull.setBorder(PdfPCell.NO_BORDER); pTableSecureter.addCell(cellSecureterNull); cellSecureterNull.setColspan(0); if (isReseguroOfNICON) { PdfPCell cellSecureter = new PdfPCell(new Phrase("RESSEGURADORA USADA", fontCorpoN)); cellSecureter.setColspan(2); cellSecureter.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellSecureter.setPaddingTop(8f); cellSecureter.setPaddingBottom(8f); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); pTableSecureter.addCell(cellSecureter); pTableSecureter.addCell(cellSecureterNull); cellSecureter = new PdfPCell(new Phrase("RESSEGURA", fontCorpoN)); cellSecureter.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellSecureter.setPaddingTop(5f); cellSecureter.setPaddingBottom(5); pTableSecureter.addCell(cellSecureter); cellSecureter = new PdfPCell(new Phrase("%PERCENTAGEM", fontCorpoN)); cellSecureter.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellSecureter.setPaddingTop(5f); cellSecureter.setPaddingBottom(5); pTableSecureter.addCell(cellSecureter); pTableSecureter.addCell(cellSecureterNull); int total = listaDataEmpresas.size(); for (int i = 0; (i < total); i++) { cellSecureter = new PdfPCell(new Phrase(listaDataEmpresas.get(i).getEMPRESA(), fontCorpo)); cellSecureter.setPaddingTop(5f); cellSecureter.setPaddingBottom(5); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); pTableSecureter.addCell(cellSecureter); cellSecureter = new PdfPCell(new Phrase( listaDataEmpresas.get(i).getPERCENTAGEM() + "% -- " + Moeda.format(((covertDouble(listaDataEmpresas.get(i).getPERCENTAGEM()) / 100) * covertDouble(reS.getPREMIOGROSSO()))) + " " + reS.getMOEDA(), fontCorpo)); cellSecureter.setPaddingTop(5f); cellSecureter.setPaddingBottom(5); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellSecureter.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableSecureter.addCell(cellSecureter); pTableSecureter.addCell(cellSecureterNull); } } PdfPTable pTablePocessed = new PdfPTable(new float[] { 100 }); PdfPCell cellPocessed = new PdfPCell(new Phrase("_____________________________", fontCorpoN)); cellPocessed.setBorder(PdfPCell.NO_BORDER); cellPocessed.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM); cellPocessed.setPaddingTop(50f); cellPocessed.setPaddingBottom(1f); pTablePocessed.addCell(cellPocessed); cellPocessed = new PdfPCell(new Phrase("PROCESSED BY", fontCorpoN)); cellPocessed.setPaddingTop(1f); cellPocessed.setVerticalAlignment(PdfPCell.ALIGN_TOP); cellPocessed.setBorder(PdfPCell.NO_BORDER); pTablePocessed.addCell(cellPocessed); SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); Document documento = new Document(); documento.setPageSize(PageSize.A4); documento.setMargins(20f, 20f, 70f, 5f); String f1 = (arquivo + "/" + user + "/Seguro " + nomeSeguro + "/"); File f = new File(f1); String Ddata = sdf1.format(new Date()); f.mkdirs(); f = new File(f.getAbsoluteFile() + "/" + "Doc Nota CO-ReSSEGURO " + Ddata + ".pdf"); reString = "../Documentos/" + user + "/Seguro " + nomeSeguro + "/" + "Doc Nota CO-ReSSEGURO " + Ddata + ".pdf"; OutputStream outputStraem = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); documento.open(); documento.add(pTableEmpresaPricipal); documento.add(pTableLinha); documento.add(pTableLinha); /* documento.add(pTableTileDoc); documento.add(pTableLinha); */ documento.add(pTableDataPart1); documento.add(pTableLinha); documento.add(pTableDataPart2); documento.add(pTableLinha); documento.add(pTableLinha); documento.add(pTableSecureter); // documento.add(pTablePocessed); pTablePocessed.setTotalWidth(200); pTablePocessed.writeSelectedRows(-1, 100, 100f, 175f, writer.getDirectContent()); documento.close(); RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')"); } catch (FileNotFoundException | DocumentException e) { } catch (IOException ex) { Logger.getLogger(DocNotaCredito.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Export.ExportMapaProducao__.java
public String criarDoc(String user, Date dataInicio, Date dataFim) { try {//from ww w . j av a2 s . c o m SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); SimpleDateFormat sdfPT = new SimpleDateFormat("dd-MM-yyyy"); Font fontCabecalhoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10f); Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f); Font fontCorpoTable = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontCorpoBP = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8.5f); Font fontCorpoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f); Font fontCabecalhoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f, Font.UNDERLINE); Document documento = new Document(); documento.setPageSize(PageSize.A4.rotate()); documento.setMargins(10f, 10f, 35f, 80f); File ff = new File(getDiretorio() + "/" + user + "/Relatorio/"); ff.mkdirs(); String stringData = sdf.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + "Export Mapa Producao " + stringData + ".pdf"); String reString = "../Documentos/" + user + "/Relatorio/" + "Export Mapa Producao " + stringData + ".pdf"; OutputStream outputStraem = new FileOutputStream(ff); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); MyFooter event = new MyFooter(); writer.setPageEvent(event); documento.open(); PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 10f, 90f }); PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1); PdfPTable pTableNull = new PdfPTable(1); PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo)); cellNull.setBorder(0); pTableNull.addCell(cellNull); PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(Empresa.NOME, fontCabecalhoNG)); pCellNomeEmpresa.setBorder(0); PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(Empresa.ENDERECO, fontCabecalhoN)); pCellNomeEndereco.setBorder(0); PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(Empresa.CAIXAPOSTAL, fontCabecalhoN)); pCellCaixaPostal.setBorder(0); PdfPCell pCellTeleFax = new PdfPCell( new Phrase(Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN)); pCellTeleFax.setBorder(0); PdfPCell pCellSociedade = new PdfPCell(new Phrase(Empresa.SOCIEDADE, fontCabecalhoN)); pCellSociedade.setBorder(0); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(120f, 85f); pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa); pTableEmpresaInforImpres1.addCell(pCellNomeEndereco); pTableEmpresaInforImpres1.addCell(pCellCaixaPostal); pTableEmpresaInforImpres1.addCell(pCellTeleFax); pTableEmpresaInforImpres1.addCell(pCellSociedade); PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1); cellTabela3.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela3); PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5); cellTabela5.setBorder(0); PdfPCell cellTabela6 = new PdfPCell(imageEmpresa); cellTabela6.setBorder(0); pTableEmpresaPricipal.setWidthPercentage(95); pTableEmpresaPricipal.addCell(cellTabela6); pTableEmpresaPricipal.addCell(cellTabela5); documento.add(pTableEmpresaPricipal); documento.add(pTableNull); PdfPTable pptTitileMapa = new PdfPTable(new float[] { 100 }); pptTitileMapa.setWidthPercentage(95); PdfPCell cellTitileMapa = new PdfPCell(new Phrase("Mapa de produo de ".toUpperCase() + ((dataInicio != null) ? sdfPT.format(dataInicio) + " " : " dos Ultimos anos te hoje".toUpperCase()) + ((dataFim == null) ? "" : sdfPT.format(dataFim)), fontCorpoNG)); cellTitileMapa.setBorder(0); cellTitileMapa.setHorizontalAlignment(Element.ALIGN_CENTER); pptTitileMapa.addCell(cellTitileMapa); documento.add(pptTitileMapa); documento.add(pTableNull); ResultSet rs = ud.relatorioSeguroForImpresao(dataInicio, dataFim); Consumer<HashMap<String, Object>> act = (map) -> { list = new ArrayList<>(); putNewDado(map, dataInicio, dataFim); }; Call.forEchaResultSet(act, rs); int f = 0; for (Map.Entry<String, ArrayList<Producao>> al : hasList.entrySet()) { if (f > 0) { documento.add(pTableNull); documento.add(pTableNull); } f++; PdfPTable pptTitulo = new PdfPTable(new float[] { 100 }); pptTitulo.setWidthPercentage(95); PdfPCell cellTitulo = new PdfPCell(new Phrase(al.getKey().toUpperCase(), fontCorpoNG)); cellTitulo.setBorder(0); pptTitulo.addCell(cellTitulo); documento.add(pptTitulo); documento.add(pTableNull); PdfPTable pTableDate = HeadTablePrincipal(); documento.add(pTableDate); for (Producao pro : al.getValue()) { pTableDate = new PdfPTable(new float[] { 9.7f, 28.8f, 14.7f, 10.7f, 10.7f, 10.7f, 14.7f }); pTableDate.setWidthPercentage(95); if (!pro.DATA.equals("SOMATORIO")) { newDado(pro.NUMAPOLICE, fontCorpoTable, pTableDate, documento, Element.ALIGN_LEFT, 0.5f); newDado(pro.CLIENTESEGURO, fontCorpoTable, pTableDate, documento, Element.ALIGN_LEFT, 0.5f); priencherTable(pro, fontCorpoTable, pTableDate, documento, 0.5f); } else { PdfPTable pTableDate2 = rodapeTabelaPrincipal(); newDado(("TOTAL " + al.getKey()).toUpperCase(), fontCorpoN, pTableDate2, documento, Element.ALIGN_LEFT, 1.5f); priencherTable(pro, fontCorpoBP, pTableDate2, documento, 1.5f); } } } PdfPTable pTableAssinatura = new PdfPTable(new float[] { 50f, 50f }); pTableAssinatura.setTotalWidth(700f); PdfPCell cellAssinatura = new PdfPCell(); cellAssinatura.setBorder(0); Paragraph assinatora = new Paragraph("DIRETOR TECNICO", fontCorpoN); assinatora.setAlignment(Element.ALIGN_CENTER); Paragraph espaco = new Paragraph(" ", fontCorpoN); Paragraph linha = new Paragraph("______________________________________", fontCorpoN); linha.setAlignment(Element.ALIGN_CENTER); cellAssinatura.addElement(assinatora); cellAssinatura.addElement(espaco); cellAssinatura.addElement(linha); pTableAssinatura.addCell(cellAssinatura); cellAssinatura = new PdfPCell(); cellAssinatura.setBorder(0); assinatora = new Paragraph("DIRETORA GERAL", fontCorpoN); assinatora.setAlignment(Element.ALIGN_CENTER); linha.setAlignment(Element.ALIGN_CENTER); cellAssinatura.addElement(assinatora); cellAssinatura.addElement(espaco); cellAssinatura.addElement(linha); pTableAssinatura.addCell(cellAssinatura); pTableAssinatura.writeSelectedRows(-1, 2, 70, 80, writer.getDirectContent()); documento.close(); // PrintPdf printPdf = new PrintPdf(ff.getAbsolutePath(), ff.getAbsolutePath(), 0, 595f,842f,"Enviar Para o OneNote 2013",0); //PrintPdf printPdf = new PrintPdf(ff.getAbsolutePath(), ff.getAbsolutePath(), 0, 595f,842f,"Hewlett-Packard HP LaserJet P2035",0); // printPdf.print(); return reString; } catch (BadElementException | IOException ex) { Logger.getLogger(SeguroAPG.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(SeguroAPG.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:Export.ReciboPagamento.java
/** * new Documento Pagamento/*from www . j a va 2 s . c o m*/ * * @param Prestacao * @param user * @return String */ public String criarDoc(Integer Prestacao, String user) { try { SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); numPrestacao = Prestacao; File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Pagamentos/"); ff.mkdirs(); String Ddata = sdf1.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + "Recebimento " + Ddata + ".pdf"); OutputStream outputStraem = new FileOutputStream(ff); reString = "../Documentos/" + user + "/Pagamentos/" + "Recebimento " + Ddata + ".pdf"; Document document = new Document(PageSize.A4); document.setMargins(20f, 20f, 0f, 0f); PdfWriter writer = PdfWriter.getInstance(document, outputStraem); Font fontTitile = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 17f, Font.NORMAL, BaseColor.BLUE.darker().darker()); Font fontTitileShort = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f, Font.NORMAL, BaseColor.BLUE.darker().darker()); Font fontRecibo = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10f, Font.NORMAL, BaseColor.BLUE.darker().darker()); Font fontReciboTxt = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 10f, Font.NORMAL, BaseColor.BLACK.darker().darker().darker()); Font fontConteudo = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 7f, Font.NORMAL, BaseColor.BLUE.darker().darker()); Font fontConteudoTxt = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7f, Font.ITALIC, BaseColor.BLACK.darker().darker().darker()); Font fontConteudoTxtUl = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7f, Font.ITALIC + Font.UNDERLINE, BaseColor.BLACK.darker().darker().darker()); MyFooter event = new MyFooter(); writer.setPageEvent(event); daoRecibo r = new daoRecibo(); HashMap<String, Object> map = r.getDados(); document.open(); PdfPTable table = detaDoc(map, fontTitile, fontRecibo, fontTitileShort, fontReciboTxt, fontConteudo, fontConteudoTxt, fontConteudoTxtUl); // document.add(table); // document.add(new Paragraph("\n\n\n\n\n\n\n\n\n", fontTitileShort)); // document.add(table); // document.newPage(); table.setTotalWidth(555); table.writeSelectedRows(-1, 100, 22.5f, 820f, writer.getDirectContent()); table.writeSelectedRows(-1, 100, 22.5f, 400f, writer.getDirectContent()); // table.writeSelectedRows(-1, 2, 52.5f, 402.5f, writer.getDirectContent()); document.close(); return reString; } catch (DocumentException ex) { Logger.getLogger(ReciboPagamento.class.getName()).log(Level.SEVERE, null, ex); return reString; } catch (FileNotFoundException ex) { Logger.getLogger(ReciboPagamento.class.getName()).log(Level.SEVERE, null, ex); } return reString; }
From source file:ExternalNonFormClasses.PDFEnator.java
public void createPDF() { try {/* www .jav a 2 s.c o m*/ Rectangle one = new Rectangle(PageSize.LETTER); Document doc = new Document(one); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(getDirectory() + "\\" + data_title + ".pdf")); //doc.setMargins(1, 1, 1, 1); doc.open(); PdfContentByte canvas = writer.getDirectContent(); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 11); x = one.getWidth(); y = one.getHeight(); tableX = (x / 2) - 235; tableY = y - 180; getHeader(); Paragraph para = new Paragraph("Province of " + formHeaderValues[0], font); para.setAlignment(Element.ALIGN_CENTER); doc.add(para); Paragraph para2 = new Paragraph("City/Municipality of " + formHeaderValues[1], font); para2.setAlignment(Element.ALIGN_CENTER); doc.add(para2); Paragraph para3 = new Paragraph("Barangay " + formHeaderValues[2], font); para3.setAlignment(Element.ALIGN_CENTER); doc.add(para3); doc.add(Chunk.NEWLINE); doc.add(Chunk.NEWLINE); Paragraph para4 = new Paragraph(data_title, font); para4.setAlignment(Element.ALIGN_CENTER); doc.add(para4); PdfPTable pdftable; pdftable = writeHeaders(font); //pdftable.writeSelectedRows(0, -1, (x / 2) - 235, y - 180, canvas); int counter = 1, rowCounter = 0, columnCounter = 0; int yIncrementor = 16; boolean test = true; while (counter <= this.totalDataSize) { //System.out.println("data#: " + counter + "@ (" + rowCounter + "," + (columnCounter) + ") = " + this.table.getValueAt(rowCounter, columnCounter).toString()); PdfPCell cell1 = new PdfPCell( new Paragraph(this.table.getValueAt(rowCounter, columnCounter++).toString(), font)); cell1.setPaddingBottom(5); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); pdftable.addCell(cell1); if (counter > 0 && (counter % column) == 0) { //if there are 4 columns //pdftable.writeSelectedRows(0, -1, (x / 2) - 235, (y - 180) - yIncrementor, canvas); //print row of 4 columns yIncrementor += 16; //move to next row coordinate, so y coordinate plus plus rowCounter++; //move to next row columnCounter = 0; //back to start column boolean newPage = false; if ((tableY - ((yIncrementor - 16) + 80)) <= 72) { //if it exceeds 1 inch in footer, new page // System.out.println("(" + tableY + "-((" + yIncrementor + "-16)+" + 16 + "))"); // System.out.println("Nanobra? YES; " + (tableY - ((yIncrementor - 16) + 16))); newPage = true; } else if ((tableY - (yIncrementor + 80)) <= 72) { // System.out.println("(" + tableY + "-(" + yIncrementor + "+" + 16 + "))"); // System.out.println("Nanobra? YES; " + (tableY - (yIncrementor + 16))); newPage = true; } if (newPage) { pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); //print the data for the current page doc.newPage(); //create new page pdftable = writeHeaders(font); //write headers to new page yIncrementor = 16; //restore default } } // if (counter == this.totalDataSize) { //para lng mudouble ang data // if (test) { // test = false; // counter = 0; // rowCounter = 0; // columnCounter = 0; // } // } else if (counter == this.totalDataSize) { // if (!test) { // break; // } // } counter++; } pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); doc.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(PDFEnator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ExternalNonFormClasses.PDFEnator.java
public void createProfilePDF(String id, ArrayList<String> data) { this.data_title = "Citizen Profile"; this.table = null; this.caller = 4; this.row = 17; this.column = 2; this.personID = id; this.totalDataSize = row * column; tableHeaderData = new ArrayList<>(); tableHeaderData.add("Label"); tableHeaderData.add("Information"); ArrayList<String> dataAll = data; try {/* w w w .jav a 2s.c om*/ getHeader(); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(getDirectory() + "\\" + data_title + ".pdf")); Rectangle one = new Rectangle(PageSize.LETTER); doc.setPageSize(one); //doc.setMargins(1, 1, 1, 1); doc.open(); PdfContentByte canvas = writer.getDirectContent(); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 11); x = one.getWidth(); y = one.getHeight(); tableX = (x / 2) - 235; tableY = y - 180; Paragraph para = new Paragraph("Province of " + formHeaderValues[0], font); para.setAlignment(Element.ALIGN_CENTER); doc.add(para); Paragraph para2 = new Paragraph("City/Municipality of " + formHeaderValues[1], font); para2.setAlignment(Element.ALIGN_CENTER); doc.add(para2); Paragraph para3 = new Paragraph("Barangay " + formHeaderValues[2], font); para3.setAlignment(Element.ALIGN_CENTER); doc.add(para3); Paragraph para4 = new Paragraph(data_title, font); para4.setAlignment(Element.ALIGN_CENTER); doc.add(para4); PdfPTable pdftable; pdftable = writeHeaders(font); int counter = 1, rowCounter = 0, columnCounter = 0; int yIncrementor = 16; String label = null, value = null; System.out.println(dataAll.size()); while (counter <= this.row) { switch (counter - 1) { case 0: label = "Citizen ID"; value = id; break; case 1: label = "Last Name"; value = dataAll.get(counter - 2); break; case 2: label = "First Name"; value = dataAll.get(counter - 2); break; case 3: label = "Middle Name"; value = dataAll.get(counter - 2); break; case 4: label = "Name Suffix"; value = dataAll.get(counter - 2); break; case 5: label = "Date of Birth"; value = dataAll.get(counter - 2); break; case 6: label = "Gender"; value = dataAll.get(counter - 2); break; case 7: label = "Address"; value = dataAll.get(counter - 2); break; case 8: label = "Age"; value = dataAll.get(counter - 2); break; case 9: label = "Place of Birth"; value = dataAll.get(counter - 2); break; case 10: label = "Civil Status"; value = dataAll.get(counter - 2); break; case 11: label = "Contact"; value = dataAll.get(counter - 2); break; case 12: label = "Zip Code"; value = dataAll.get(counter - 2); break; case 13: label = "Precinct Number"; value = dataAll.get(counter - 2); break; case 14: label = "Occupation"; value = dataAll.get(counter - 2); break; case 15: label = "Email Address"; value = dataAll.get(counter - 2); break; case 16: label = "Religion"; value = dataAll.get(counter - 2); break; } if (value.length() <= 0) { value = "N/A"; } System.out.println(label + ": " + value); PdfPCell cell1 = new PdfPCell(new Paragraph(label, font)); cell1.setPaddingBottom(5); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); pdftable.addCell(cell1); PdfPCell cell2 = new PdfPCell(new Paragraph(value, font)); cell2.setPaddingBottom(5); cell2.setHorizontalAlignment(Element.ALIGN_LEFT); pdftable.addCell(cell2); if (counter > 0 && (counter % column) == 0) { //if there are 4 columns yIncrementor += 16; //move to next row coordinate, so y coordinate plus plus rowCounter++; //move to next row columnCounter = 0; //back to start column boolean newPage = false; if ((tableY - ((yIncrementor - 16) + 80)) <= 72 || (tableY - (yIncrementor + 80)) <= 72) { //if it exceeds 1 inch in footer, new page newPage = true; } if (newPage) { pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); //print the data for the current page doc.newPage(); //create new page pdftable = writeHeaders(font); //write headers to new page yIncrementor = 16; //restore default } } counter++; } pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); doc.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(PDFEnator.class.getName()).log(Level.SEVERE, null, ex); } }