List of usage examples for com.itextpdf.text.pdf PdfContentByte beginText
public void beginText()
From source file:Excel.pdfsJavaGenerador.java
public void run() { Document documento = new Document(); documento.setPageSize(PageSize.A4.rotate()); int i = 1;//from w w w .j ava 2 s . com 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:fattura.Fattura.java
public void setFattura(String cliente, String data, AtomicInteger numerofattura, PdfStamper s) throws SQLException, DocumentException, FileNotFoundException, IOException { //Ho messo che il numero della fattura va passato come parametro, voglio capire se si pu fare altrimenti (con un contatore) try {// w ww .ja va2s. com s.getAcroFields().setField("Num", numerofattura.toString()); // sistemare s.getAcroFields().setField("Data", data); s.getAcroFields().setField("Nome", cliente); PdfContentByte content = s.getUnderContent(1);//1 for the first page BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 7); inserisciDatiMaglie(cliente, data, s); inserisciDatiBorse(cliente, data, s); inserisciDatiPanta(cliente, data, s); inserisciDatiGiubb(cliente, data, s); inserisciDatiFelpe(cliente, data, s); inserisciDatiPubb(cliente, data, s); setImporti(s); content.endText(); s.close(); } catch (IOException | DocumentException e) { } }
From source file:fll.util.SimpleFooterHandler.java
License:Open Source License
@Override public void onEndPage(final PdfWriter writer, final Document document) { final PdfContentByte cb = writer.getDirectContent(); cb.saveState();// w ww. j av a2s. co m // compose the footer final String text = "Page " + writer.getPageNumber() + " of "; final float textSize = _headerFooterFont.getWidthPoint(text, 12); final float textBase = document.bottom() - 20; cb.beginText(); cb.setFontAndSize(_headerFooterFont, 12); final float adjust = _headerFooterFont.getWidthPoint("0", 12); cb.setTextMatrix(document.right() - textSize - adjust, textBase); cb.showText(text); cb.endText(); cb.addTemplate(_tpl, document.right() - adjust, textBase); cb.restoreState(); }
From source file:gravabncertificado.GerandoArquivoCarimbado_1.java
public static void GerandoArquivoCarimbadoPDF(String caminhoarquivo, String BN) throws InvalidPdfException { //Copiando arquivo informado. try {//from ww w . j a v a 2 s. c o m // Adicionado parametro para nao retornar erro quando o documento for protegido. PdfReader.unethicalreading = true; //Cria o reader para o primeiro PDF PdfReader reader = new PdfReader(caminhoarquivo); // n recebe o numero total de paginas int n = reader.getNumberOfPages(); //Tamanho da primeira Pagina ; //Cria Segundo PDF Document document = new Document(PageSize.A4, 36, 36, 36, 36); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf")); document.open(); // Adiciona conteudo ao PDF Carimbado. PdfContentByte cb = writer.getDirectContent(); int i = 0; int p = 0; String caminhodestino = (caminhoarquivo.substring(0, caminhoarquivo.length() - BN.length())); // DESABILITADO PORQUE O MOVER NAO ESTAVA FUNCIONANDO. File destinooriginal = new File(caminhodestino + "ORIGINAL\\"); if (!destinooriginal.exists()) { destinooriginal.mkdir(); } caminhodestino = (caminhodestino + "ORIGINAL\\" + BN); //TESTANDO NOVA FORMA DE COPIAR File origem = new File(caminhoarquivo); File destino = new File(caminhodestino); FileInputStream fis = new FileInputStream(origem); FileOutputStream fos = new FileOutputStream(destino); FileChannel inChannel = fis.getChannel(); FileChannel outChannel = fos.getChannel(); long transferFrom = outChannel.transferFrom(inChannel, 0, inChannel.size()); fis.close(); fos.close(); inChannel.close(); outChannel.close(); // Thread.sleep(10); BN = BN.substring(0, BN.length() - 4); while (i < n) { document.newPage(); p++; i++; PdfContentByte under = writer.getDirectContentUnder(); PdfImportedPage page1 = writer.getImportedPage(reader, i); cb.addTemplate(page1, 0, i * 0.2f); // Page 1: a rectangle /* RETANGULO DESATIVADO drawRectangle(under, 100, 50); under.setRGBColorFill(255, 220, 220); under.rectangle(width /50, 5, 118, 40); under.fill(); */ //CARIMBO DA BN BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setFontAndSize(bf, 14); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 32, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 22, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 12, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0); cb.endText(); } document.close(); writer.close(); reader.close(); origem.delete(); /* PdfContentByte under = writer.getDirectContentUnder(); // Page 1: a rectangle drawRectangle(under, 20, 20); under.setRGBColorFill(0xFF, 0xD7, 0x00); under.rectangle(5, 5, 15, 15); under.fill(); */ //document.newPage(); //COPIANDO ARQUIVO CARIMBADO /* DESABILITADO PORQUE NAO ESTAVA FUNCIONANDO. boolean bool; //caminhoarquivo = caminhoarquivo.replace("\\", "\\\\"); //caminhodestino = caminhodestino.replace("\\", "\\\\"); File origem = new File(caminhoarquivo); File destino = new File(caminhodestino); bool = origem.renameTo(destino); System.out.println(origem); System.out.println(caminhodestino); */ } catch (IOException | DocumentException ex) { } }
From source file:gravabncertificado007.CarimboCertificado.java
public void aplicaCarimboBin(String BN, String caminhoarquivo) throws DocumentException, IOException, RuntimeException { PdfReader.unethicalreading = true;/*from www . j a v a 2 s .c o m*/ //Cria o reader para o primeiro PDF PdfReader reader = new PdfReader(caminhoarquivo); Rectangle psize = reader.getPageSize(1); float width = psize.getWidth(); float height = psize.getHeight(); Document document = new Document(new Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf")); document.open(); int i = 0; BN = BN.substring(BN.length() - 13, BN.length() - 4); PdfContentByte cb = writer.getDirectContent(); while (i < reader.getNumberOfPages()) { i++; document.newPage(); PdfContentByte under = writer.getDirectContentUnder(); PdfImportedPage page1 = writer.getImportedPage(reader, i); cb.addTemplate(page1, 0, i * 0.2f); //CARIMBO DA BN BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setFontAndSize(bf, 14); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 32, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 22, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 12, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0); cb.endText(); } document.close(); writer.close(); reader.close(); }
From source file:gravabncertificado007.CarimboCertificado.java
public void aplicaCariboGedi(String BN, String caminhoarquivo) throws DocumentException, IOException, RuntimeException { PdfReader.unethicalreading = true;/*w ww.j av a2 s . c o m*/ //Cria o reader para o primeiro PDF PdfReader reader = new PdfReader(caminhoarquivo); Rectangle psize = reader.getPageSize(1); float width = psize.getWidth(); float height = psize.getHeight(); Document document = new Document(new Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-G.pdf")); document.open(); int i = 0; BN = BN.substring(BN.length() - 13, BN.length() - 4); PdfContentByte cb = writer.getDirectContent(); while (i < reader.getNumberOfPages()) { i++; document.newPage(); PdfContentByte under = writer.getDirectContentUnder(); PdfImportedPage page1 = writer.getImportedPage(reader, i); cb.addTemplate(page1, 0, i * 0.2f); BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setFontAndSize(bf, 14); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " _________________ ", width / 6, 44, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 32, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 22, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |Copia Controlada |", width / 6, 28, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 16, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 12, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |_________________|", width / 6, 14, 0); cb.endText(); } document.close(); writer.close(); reader.close(); }
From source file:jasperSoft.MergePDF.java
/** * //ww w . jav a2s . c om * @param streamOfPDFFiles * @param outputStream * @param paginate */ public static void concatPDFs(List<InputStream> streamOfPDFFiles, OutputStream outputStream, boolean paginate) { Document document = new Document(); try { List<InputStream> pdfs = streamOfPDFFiles; List<PdfReader> readers = new ArrayList<PdfReader>(); int totalPages = 0; Iterator<InputStream> iteratorPDFs = pdfs.iterator(); // Create Readers for the pdfs. while (iteratorPDFs.hasNext()) { InputStream pdf = iteratorPDFs.next(); PdfReader pdfReader = new PdfReader(pdf); readers.add(pdfReader); totalPages += pdfReader.getNumberOfPages(); } // Create a writer for the outputstream PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); PdfContentByte cb = writer.getDirectContent(); // Holds the PDF // data PdfImportedPage page; int currentPageNumber = 0; int pageOfCurrentReaderPDF = 0; Iterator<PdfReader> iteratorPDFReader = readers.iterator(); // Loop through the PDF files and add to the output. while (iteratorPDFReader.hasNext()) { PdfReader pdfReader = iteratorPDFReader.next(); // Create a new page in the target for each source page. while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) { document.newPage(); pageOfCurrentReaderPDF++; currentPageNumber++; page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF); cb.addTemplate(page, 0, 0); // Code for pagination. if (paginate) { cb.beginText(); cb.setFontAndSize(bf, 9); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "" + currentPageNumber + " of " + totalPages, 520, 5, 0); cb.endText(); } } pageOfCurrentReaderPDF = 0; } outputStream.flush(); document.close(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (document.isOpen()) { document.close(); } try { if (outputStream != null) { outputStream.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } } }
From source file:jati.GerandoArquivoCarimbado.java
public static void GerandoArquivoCarimbadoPDF(String caminhoarquivo, String BN) throws InvalidPdfException, IOException { //Copiando arquivo informado. try {//from w w w . ja v a2s. c o m // Adicionado parametro para nao retornar erro quando o documento for protegido. PdfReader.unethicalreading = true; PdfWriter writer = PdfWriter.getInstance(montaraAquivo(caminhoarquivo), new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf")); // ABRE O DOCUMENTO CRIADO PARA MANUSEIO montaraAquivo(caminhoarquivo).open(); //SUBSTRING RETIRA PARTE DO TEXTO ENTRE OS INDICES ESPECIFICADOS //caminhoDestino RECEBE UM NOVO CAMINHO RESULTANTE DOS INDICES DE CAMINHO.LENGTH - BN.LENGTH // QUE FORMAM UMA NOVA STRING String caminhodestino = (caminhoarquivo.substring(0, caminhoarquivo.length() - BN.length())); File destinooriginal = new File(caminhodestino + "ORIGINAL\\"); if (!destinooriginal.exists()) { destinooriginal.mkdir(); } caminhodestino = (caminhodestino + "ORIGINAL\\" + BN); //TESTANDO NOVA FORMA DE COPIAR File origem = new File(caminhoarquivo); File destino = new File(caminhodestino); FileInputStream fis = new FileInputStream(origem); FileOutputStream fos = new FileOutputStream(destino); FileChannel inChannel = fis.getChannel(); FileChannel outChannel = fos.getChannel(); long transferFrom = outChannel.transferFrom(inChannel, 0, inChannel.size()); fis.close(); fos.close(); inChannel.close(); outChannel.close(); // Thread.sleep(10); BN = BN.substring(0, BN.length() - 4); PdfContentByte cb = writer.getDirectContent(); int i = 0; while (i < reader.getNumberOfPages()) { montaraAquivo(caminhodestino).newPage(); i++; //PDFCONTETBYTE GERA UMA ESPECIE DE CODIGO DE BARRAS PdfContentByte under = writer.getDirectContentUnder(); PdfImportedPage page1 = writer.getImportedPage(reader, i); cb.addTemplate(page1, 0, i * 0.2f); //CARIMBO DA BN BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setFontAndSize(bf, 14); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 32, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 22, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " | |", width / 6, 12, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0); cb.endText(); } montaraAquivo(caminhodestino).close(); writer.close(); reader.close(); origem.delete(); } catch (IOException | DocumentException ex) { } }
From source file:me.Aron.Heinecke.fbot.lib.Converter.java
License:Apache License
/*** * Add a note to the bottom of a pdf file in italic font * @param rfile file to be read from/*from w w w.j a v a 2 s . c om*/ * @param wfile file to be written to * @param text text to add * @return path to the resulting pdf, null if it failed */ private String addPDFNote(File rfile, File wfile, String text) { try { PdfReader pdfReader = new PdfReader(rfile.getAbsolutePath()); PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(wfile)); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte cb = pdfStamper.getUnderContent(i); BaseFont bf = BaseFont.createFont(); bf.setPostscriptFontName("ITALIC"); cb.beginText(); cb.setFontAndSize(bf, 12); cb.setTextMatrix(10, 20); cb.showText(text); cb.endText(); } pdfStamper.close(); return wfile.getAbsolutePath(); } catch (IOException | DocumentException e) { fbot.getLogger().exception("converter", e); return null; } }
From source file:Operaciones.ResponsablesOP.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);/* w ww . ja v a 2s . c o m*/ Session session = HibernateUtil.getSessionFactory().openSession(); try { Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(t_orden.getText())); Configuracion con = (Configuracion) session.get(Configuracion.class, 1); Date fecha = new Date(); Date fecha1 = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); File folder = new File("reportes/" + ord.getIdOrden()); folder.mkdirs(); PdfReader reader = new PdfReader("imagenes/PlantillaHojaAsignacion.pdf"); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-HojaAsignacion.pdf")); PdfContentByte cb = stamp.getUnderContent(1); AcroFields fdfDoc = stamp.getAcroFields(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); cb.beginText(); fdfDoc.setField("orden", String.valueOf(ord.getIdOrden())); if (ord.getCompania() != null) fdfDoc.setField("compania", ord.getCompania().getNombre()); else fdfDoc.setField("compania", ""); if (ord.getSiniestro() != null) fdfDoc.setField("siniestro", ord.getSiniestro()); else fdfDoc.setField("siniestro", ""); if (ord.getPoliza() != null) fdfDoc.setField("poliza", ord.getPoliza()); else fdfDoc.setField("poliza", ""); if (ord.getFecha() != null) fdfDoc.setField("apertura", ord.getFecha().toString()); else fdfDoc.setField("apertura", ""); if (ord.getFechaSiniestro() != null) fdfDoc.setField("f_siniestro", ord.getFechaSiniestro().toString()); else fdfDoc.setField("f_siniestro", ""); if (ord.getInciso() != null) fdfDoc.setField("inciso", ord.getInciso()); else fdfDoc.setField("inciso", ""); if (ord.getTipo() != null) fdfDoc.setField("unidad", ord.getTipo().getTipoNombre()); else fdfDoc.setField("unidad", ""); if (ord.getModelo() != null) fdfDoc.setField("modelo", ord.getModelo().toString()); else fdfDoc.setField("modelo", ""); if (ord.getMarca() != null) fdfDoc.setField("marca", ord.getMarca().getMarcaNombre()); else fdfDoc.setField("marca", ""); if (ord.getNoEconomico() != null) fdfDoc.setField("economico", ord.getNoEconomico()); else fdfDoc.setField("economico", ""); if (ord.getNoMotor() != null) fdfDoc.setField("no_motor", ord.getNoMotor()); else fdfDoc.setField("no_motor", ""); if (ord.getNoSerie() != null) fdfDoc.setField("no_serie", ord.getNoSerie()); else fdfDoc.setField("no_serie", ""); //tabla if (ord.getEmpleadoByRHojalateria() != null) fdfDoc.setField("HOJALATERIA", ord.getEmpleadoByRHojalateria().getIdEmpleado().toString()); else fdfDoc.setField("HOJALATERIA", ""); if (ord.getEmpleadoByRHojalateria() != null) fdfDoc.setField("R_H", ord.getEmpleadoByRHojalateria().getNombre().toString()); else fdfDoc.setField("R_H", ""); if (ord.getEmpleadoByRMecanica() != null) fdfDoc.setField("MECANICA", ord.getEmpleadoByRMecanica().getIdEmpleado().toString()); else fdfDoc.setField("MECANICA", ""); if (ord.getEmpleadoByRMecanica() != null) fdfDoc.setField("R_M", ord.getEmpleadoByRMecanica().getNombre().toString()); else fdfDoc.setField("R_M", ""); if (ord.getEmpleadoByRSuspension() != null) fdfDoc.setField("SUSPENSIN", ord.getEmpleadoByRSuspension().getIdEmpleado().toString()); else fdfDoc.setField("SUSPENSIN", ""); if (ord.getEmpleadoByRSuspension() != null) fdfDoc.setField("R_S", ord.getEmpleadoByRSuspension().getNombre().toString()); else fdfDoc.setField("R_S", ""); if (ord.getEmpleadoByRElectrico() != null) fdfDoc.setField("ELECTRICO", ord.getEmpleadoByRElectrico().getIdEmpleado().toString()); else fdfDoc.setField("ELECTRICO", ""); if (ord.getEmpleadoByRElectrico() != null) fdfDoc.setField("R_E", ord.getEmpleadoByRElectrico().getNombre().toString()); else fdfDoc.setField("R_E", ""); if (ord.getEmpleadoByRPintura() != null) fdfDoc.setField("PINTURA", ord.getEmpleadoByRPintura().getIdEmpleado().toString()); else fdfDoc.setField("PINTURA", ""); if (ord.getEmpleadoByRPintura() != null) fdfDoc.setField("R_P", ord.getEmpleadoByRPintura().getNombre().toString()); else fdfDoc.setField("R_P", ""); //FECHAS String valor1 = ""; if (ord.getRHojalateriaFecha() != null) { fecha1 = ord.getRHojalateriaFecha(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_H", valor1); } else { fdfDoc.setField("F_H", valor1); } if (ord.getRMecanicaFecha() != null) { fecha1 = ord.getRMecanicaFecha(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_M", valor1); } else { fdfDoc.setField("F_M", valor1); } if (ord.getRSuspensionFecha() != null) { fecha1 = ord.getRSuspensionFecha(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_S", valor1); } else { fdfDoc.setField("F_S", valor1); } if (ord.getRElectricoFecha() != null) { fecha1 = ord.getRElectricoFecha(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_E", valor1); } else { fdfDoc.setField("F_E", valor1); } if (ord.getRPinturaFecha() != null) { fecha1 = ord.getRPinturaFecha(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_P", valor1); } else { fdfDoc.setField("F_P", valor1); } //ASIGNO OPERARIO if (ord.getUsuarioByRHojalateriaAsigno() != null) fdfDoc.setField("A_H", ord.getUsuarioByRHojalateriaAsigno().getIdUsuario()); else fdfDoc.setField("A_H", ""); if (ord.getUsuarioByRMecanicaAsigno() != null) fdfDoc.setField("A_M", ord.getUsuarioByRMecanicaAsigno().getIdUsuario()); else fdfDoc.setField("A_M", ""); if (ord.getUsuarioByRSuspensionAsigno() != null) fdfDoc.setField("A_S", ord.getUsuarioByRSuspensionAsigno().getIdUsuario()); else fdfDoc.setField("A_S", ""); if (ord.getUsuarioByRElectricoAsigno() != null) fdfDoc.setField("A_E", ord.getUsuarioByRElectricoAsigno().getIdUsuario()); else fdfDoc.setField("A_E", ""); if (ord.getUsuarioByRPinturaAsigno() != null) fdfDoc.setField("A_P", ord.getUsuarioByRPinturaAsigno().getIdUsuario()); else fdfDoc.setField("A_P", ""); //LIMITE if (ord.getHojalateriaLimite() != null) { fecha1 = ord.getHojalateriaLimite(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_H_L", valor1); } else { fdfDoc.setField("F_H_L", ""); } if (ord.getMecanicaLimite() != null) { fecha1 = ord.getMecanicaLimite(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_M_L", valor1); } else { fdfDoc.setField("F_M_L", ""); } if (ord.getSuspensionLimite() != null) { fecha1 = ord.getSuspensionLimite(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_S_L", valor1); } else { fdfDoc.setField("F_S_L", ""); } if (ord.getElectricoLimite() != null) { fecha1 = ord.getElectricoLimite(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_E_L", valor1); } else { fdfDoc.setField("F_E_L", ""); } if (ord.getPinturaLimite() != null) { fecha1 = ord.getPinturaLimite(); dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); valor1 = dateFormat.format(fecha1); fdfDoc.setField("F_P_L", valor1); } else { fdfDoc.setField("F_P_L", ""); } Foto[] fotos = (Foto[]) ord.getFotos().toArray(new Foto[0]); for (int k = 0; k < fotos.length - 1; k++) { for (int f = 0; f < (fotos.length - 1) - k; f++) { if (fotos[f].getFecha().after(fotos[f + 1].getFecha()) == true) { Foto aux; aux = fotos[f]; fotos[f] = fotos[f + 1]; fotos[f + 1] = aux; } } } if (fotos.length > 0) { try { Image img; img = Image .getInstance("ordenes/" + ord.getIdOrden() + "/miniatura/" + fotos[0].getDescripcion()); img.setAbsolutePosition(30, 495); img.scaleAbsoluteWidth(124); img.scaleAbsoluteHeight(80); cb.addImage(img, true); } catch (Exception e) { //e.printStackTrace(); } } else { } cb.endText(); stamp.close(); PDF reporte = new PDF(); reporte.cerrar(); reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-HojaAsignacion.pdf"); } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } if (session != null) if (session.isOpen()) session.close(); }