List of usage examples for com.itextpdf.text.pdf BaseFont NOT_EMBEDDED
boolean NOT_EMBEDDED
To view the source code for com.itextpdf.text.pdf BaseFont NOT_EMBEDDED.
Click Source Link
From source file:Compras.reportePedidos.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);/*w w w .ja va 2 s . co m*/ if (t_datos.getRowCount() > 0) { Session session = HibernateUtil.getSessionFactory().openSession(); javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { try { DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); session.beginTransaction().begin(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); //Orden ord=buscaApertura(); PDF reporte = new PDF(); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); reporte.Abrir2(PageSize.LETTER.rotate(), "Reporte", ruta + ".pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 5, Font.BOLD); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float[] tam_pdf = new float[] { 10, 25, 13, 18, 10, 50, 50, 60, 18, 18, 15 }; PdfPTable tabla = reporte.crearTabla(tam_pdf.length, tam_pdf, 100, Element.ALIGN_LEFT); cabecera(reporte, bf, tabla); int ren = 0; double dm = 0d, cam = 0d, min = 0d, med = 0d, max = 0d, pin = 0d, tot = 0d; for (int i = 0; i < t_datos.getRowCount(); i++) { for (int j = 0; j < t_datos.getColumnCount(); j++) { if (t_datos.getColumnName(j).compareTo("Monto tot.") == 0) { if (t_datos.getValueAt(i, j) != null) tabla.addCell( reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, j)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda("0.00", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } else { if (t_datos.getValueAt(i, j) != null) tabla.addCell(reporte.celda("" + t_datos.getValueAt(i, j), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } } /*if(ren==38) { reporte.agregaObjeto(tabla); reporte.writer.newPage(); tabla=reporte.crearTabla(tam_pdf.length, tam_pdf, 100, Element.ALIGN_LEFT); cabecera(reporte, bf, tabla); ren=-1; } ren++;*/ } tabla.setHeaderRows(1); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto."); } finally { if (session != null) if (session.isOpen()) session.close(); } } } } }
From source file:Compras.reportePedidos.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);//w w w.j a va 2 s .c om if (t_datos.getRowCount() > 0) { Session session = HibernateUtil.getSessionFactory().openSession(); javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { try { DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); session.beginTransaction().begin(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); PDF reporte = new PDF(); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); reporte.Abrir2(PageSize.LETTER.rotate(), "Reporte", ruta + ".pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float[] tam_pdf = new float[] { 15, 40, 130, 20, 15, 30, 20, 15 }; PdfPTable tabla = reporte.crearTabla(tam_pdf.length, tam_pdf, 100, Element.ALIGN_LEFT); cabeceraReporte(reporte, bf, tabla); Object no[]; int ren[]; if (t_datos.getSelectedRows().length > 0) { no = new Object[t_datos.getSelectedRows().length]; ren = t_datos.getSelectedRows(); for (int x = 0; x < t_datos.getSelectedRows().length; x++) { no[x] = (int) t_datos.getValueAt(ren[x], 0); } } else { no = new Object[t_datos.getRowCount()]; //ren =new int[t_datos.getRowCount()]; for (int x = 0; x < t_datos.getRowCount(); x++) { no[x] = (int) t_datos.getValueAt(x, 0); } } Pedido[] pedidos; if (autorizado.isSelected() == true) { pedidos = (Pedido[]) session.createCriteria(Pedido.class) .add(Restrictions.and( Restrictions.and(Restrictions.isNotNull("usuarioByAutorizo"), Restrictions.isNotNull("usuarioByAutorizo2")), Restrictions.in("idPedido", no))) .list().toArray(new Pedido[0]); } else { pedidos = (Pedido[]) session.createCriteria(Pedido.class) .add(Restrictions.in("idPedido", no)).list().toArray(new Pedido[0]); } if (pedidos.length > 0) { ArrayList ordena = new ArrayList(); for (int a = 0; a < pedidos.length; a++) { Pedido aux = pedidos[a]; if (aux.getTipoPedido().compareTo("Interno") == 0) { Partida[] par = (Partida[]) aux.getPartidas().toArray(new Partida[0]); for (int b = 0; b < par.length; b++) { Partida ren1 = par[b]; Renglon nuevo; if (ren1.getEjemplar() != null) nuevo = new Renglon("" + aux.getIdPedido(), ren1.getEjemplar().getIdParte(), ren1.getCatalogo().getNombre(), ren1.getCantPcp(), ren1.getMed(), ren1.getPcp(), "" + ren1.getOrdenByIdOrden().getIdOrden(), "" + ren1.getIdEvaluacion() + "-" + ren1.getSubPartida()); else nuevo = new Renglon("" + aux.getIdPedido(), "", ren1.getCatalogo().getNombre(), ren1.getCantPcp(), ren1.getMed(), ren1.getPcp(), "" + ren1.getOrdenByIdOrden().getIdOrden(), "" + ren1.getIdEvaluacion() + "-" + ren1.getSubPartida()); ordena.add(nuevo); } } if (aux.getTipoPedido().compareTo("Externo") == 0) { PartidaExterna[] par = (PartidaExterna[]) aux.getPartidaExternas() .toArray(new PartidaExterna[0]); for (int b = 0; b < par.length; b++) { PartidaExterna ren2 = par[b]; Renglon nuevo; nuevo = new Renglon("" + aux.getIdPedido(), ren2.getNoParte(), ren2.getDescripcion(), ren2.getCantidad(), ren2.getUnidad(), ren2.getCosto(), "", "" + "Ext"); ordena.add(nuevo); } } if (aux.getTipoPedido().compareTo("Adicional") == 0) { PartidaExterna[] par = (PartidaExterna[]) aux.getPartidaExternas() .toArray(new PartidaExterna[0]); for (int b = 0; b < par.length; b++) { PartidaExterna ren2 = par[b]; Renglon nuevo; nuevo = new Renglon("" + aux.getIdPedido(), ren2.getNoParte(), ren2.getDescripcion(), ren2.getCantidad(), ren2.getUnidad(), ren2.getCosto(), "" + aux.getOrden().getIdOrden(), "ADI"); ordena.add(nuevo); } } } Collections.sort(ordena, new Comparator() { @Override public int compare(Object o1, Object o2) { Renglon p1 = (Renglon) o1; Renglon p2 = (Renglon) o2; return new String(p1.np + p1.descripcion) .compareTo(new String(p2.np + p2.descripcion)); } }); for (int c = 0; c < ordena.size(); c++) { Renglon r1 = (Renglon) ordena.get(c); tabla.addCell(reporte.celda(r1.pedido, font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell( reporte.celda(r1.np, font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(r1.descripcion, font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(r1.cant), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell( reporte.celda(r1.med, font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(r1.precio), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("" + r1.orden, font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(r1.partida, font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } } tabla.setHeaderRows(2); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto."); } finally { if (session != null) if (session.isOpen()) session.close(); } } } } }
From source file:Contabilidad.RCuentas.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: if (t_datos.getRowCount() > 0) { javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" })); String ruta = null;/*from w w w. j a v a2s . c o m*/ if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { Session session = HibernateUtil.getSessionFactory().openSession(); try { DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); session.beginTransaction().begin(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); //Orden ord=buscaApertura(); PDF reporte = new PDF(); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); reporte.Abrir2(PageSize.LETTER.rotate(), "Reporte Contabilidad", ruta + ".pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float[] nuevos = new float[] { 36, 75, 95, 250, 145, 36, 47, 65, 90, 70, 140 }; PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_LEFT); cabecera(reporte, bf, tabla, "Reporte de Cuentas por Cobrar", 1); for (int ren = 0; ren < t_datos.getRowCount(); ren++) { for (int col = 0; col < t_datos.getColumnCount(); col++) { try { if (col == 1) { String[] vec = t_datos.getValueAt(ren, col).toString().split("T"); if (vec.length > 0) tabla.addCell(reporte.celda(vec[0], font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } else { if (col == 7) tabla.addCell(reporte.celda( formatoPorcentaje.format(t_datos.getValueAt(ren, col)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(t_datos.getValueAt(ren, col).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } } catch (Exception e) { tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } } } tabla.setHeaderRows(1); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto."); } if (session != null) if (session.isOpen()) session.close(); } } } }
From source file:Controlador.ControladorCrearPase.java
private static void absText(PdfWriter writer, String text, int x, int y) throws DocumentException, IOException { PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.saveState();//ww w . ja va 2s . com cb.beginText(); cb.moveText(x, y); cb.setFontAndSize(bf, 12); cb.showText(text); cb.endText(); cb.restoreState(); }
From source file:Controller.app.ConsultaController.java
private File createPDF(TblServicioFactura factura) throws IOException { String data = factura.getTesPagoResponse(); JSONObject obj = new JSONObject(data); JSONArray content = obj.getJSONArray("lineaFactura"); String temp = ""; File _file = null;//from w w w. ja v a 2s . c o m Document doc = null; OutputStream file = null; int page = 0; try { _file = File.createTempFile("temp_file", ".pdf"); TblServicioServicio servicio = servicios.search(factura.getTesCodigoSintesisBi().toString()); file = new FileOutputStream(_file); doc = new Document(PageSize.LETTER); doc.setMargins(servicio.getMarginLeft().floatValue(), servicio.getMarginRight().floatValue(), servicio.getMarginTop().floatValue(), servicio.getMarginBottom().floatValue()); PdfWriter.getInstance(doc, file); doc.open(); // ClassLoader classloader = Thread.currentThread().getContextClassLoader(); ClassLoader classloader = getClass().getClassLoader(); URL url = classloader.getResource("cour.ttf"); BaseFont base = null; if (url == null) { base = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } else { String path = url.getPath(); if ("/".equals(path.substring(0, 1))) { path = path.substring(1); } Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, path); base = BaseFont.createFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } Font f = new Font(base, servicio.getFontSize(), Font.NORMAL, BaseColor.BLACK); String qr = ""; float line = 0; for (Object item : content) { Paragraph paragraph = new Paragraph(item.toString(), f); if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL")) { if (item.toString().contains("P X#X&$#&K##")) { paragraph = new Paragraph(" ", f); doc.add(paragraph); doc.add(paragraph); paragraph = new Paragraph(item.toString(), f); } } if (item.toString().contains("<b>")) { Font bold = new Font(base, 7.0f, Font.BOLD, BaseColor.BLACK); paragraph = new Paragraph(item.toString().replace("<b>", ""), bold); } if (item.toString().contains("<QR>") || item.toString().contains("<QR_ENT_G>")) { qr = item.toString().replaceAll("<QR>", ""); qr = item.toString().replaceAll("<QR_ENT_G>", ""); Image image = QR.create(qr); image.scaleAbsolute(servicio.getQrScale().floatValue(), servicio.getQrScale().floatValue()); if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL") || servicio.getTesDetalleVc().trim().equals("PAGO TELECEL") || servicio.getTesDetalleVc().trim().equals("PAGO NUEVATEL") || servicio.getTesDetalleVc().trim().equals("PAGO TIGOSTAR (MULTIVISION)")) { float y = (doc.getPageSize().getHeight() - (paragraph.getLeading() * (line + 1))); float x = 0; if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL")) { image.setAlignment(Image.ALIGN_RIGHT); x = doc.getPageSize().getWidth() - (110 - servicio.getMarginLeft().floatValue()); } if (servicio.getTesDetalleVc().trim().equals("PAGO TELECEL")) { image.setAlignment(Image.ALIGN_LEFT); x = 30; y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading() * 2)); } if (servicio.getTesDetalleVc().trim().equals("PAGO NUEVATEL")) { image.setAlignment(Image.ALIGN_LEFT); x = doc.getPageSize().getWidth() - (120 - servicio.getMarginLeft().floatValue()); y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading())); } if (servicio.getTesDetalleVc().trim().equals("PAGO TIGOSTAR (MULTIVISION)")) { image.setAlignment(Image.ALIGN_LEFT); x = doc.getPageSize().getWidth() - (120 - servicio.getMarginLeft().floatValue()); y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading())); } image.setAbsolutePosition(x, y); } doc.add(image); } if (servicio.getDelimitador().equals(item.toString().trim())) { line = 0; page++; doc.newPage(); } else { line += 1f; if (!(item.toString().contains("<QR>") || item.toString().contains("<QR_ENT_G>"))) { doc.add(paragraph); } } temp += item.toString(); } } catch (FileNotFoundException ex) { Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, null, ex); } catch (DocumentException | IOException ex) { Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, null, ex); } doc.close(); file.close(); return _file; }
From source file:edu.avans.ivh5.shared.util.generateInvoicePDF2.java
private void initializeFonts() { try {//from w w w .j a va 2 s .com bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:englishrusbook.Writer.java
public void write(Document document, HashMap<String, String> wordTranslateMap) { document.open();/*from ww w. ja va 2s . com*/ String delimiter = " : "; try { BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Font font = new Font(helvetica, 12); for (Entry<String, String> entry : wordTranslateMap.entrySet()) { document.add(new Paragraph(entry.getKey() + delimiter + entry.getValue(), font)); } } catch (DocumentException | IOException e) { System.out.println("ERROR in writing: " + e); } finally { document.close(); } }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertComment(String sx, String sy, String id, String deptValue, String userInit, String comment, int pageNum, int masterHeight, int masterWidth, int pinned, int customFontSize) throws DocumentException, IOException { float ratio = getRatio(masterHeight, masterWidth, pageNum); float x = Float.parseFloat(sx); float y = Float.parseFloat(sy); float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum); PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(1);/*w w w . j a v a 2 s . com*/ if (customFontSize > 0) fontSize = customFontSize; PdfContentByte fg = pds.getOverContent(pageNum); fg.setGState(gs1); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum); // comment tag image (width=35pts, height=8pts) float[] scalar = scale(trans[0], trans[1], 35, 8, masterHeight, masterWidth, pageNum); /* Addition. ftorres - 7/21/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ float coords[] = translateRotation(trans[0], trans[1], pageNum); coords = checkBounds(coords[0], coords[1], pageNum); /* Addition. ftorres - 10/20/2015 - If the comment was pinned in EPC, then * render the comment inside a comment box. */ if (pinned == 1) { insertPinnedComment(coords[0], coords[1], id + " - " + deptValue + " (" + userInit + ")", comment, pageNum, masterHeight, masterWidth); // Add the pinned comment text to page annotation -Jon Changkachith 11/24/2015 Rectangle rect = new Rectangle(0, 0, 0, 0); PdfAnnotation annotation = PdfAnnotation.createText(pds.getWriter(), rect, id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), true, id); pds.addAnnotation(annotation, pds.getWriter().getCurrentPageNumber()); } else { Image image = Image.getInstance(commentIMGPath); image.setAbsolutePosition(coords[0] + (scalar[0] * (id.length() / 5f)), coords[1]); /* * Commented out by Jon Changkachith 12/09/2015 because it was throwing * DocumentException with the message "The image must have absolute positioning." image.scaleAbsoluteHeight(1); image.scaleAbsoluteWidth(1); */ image.scalePercent(ratio); //Added to fix DocumentException "The image must have absolute positioning." Jon Changkachith 12/09/2015 image.setAnnotation(new Annotation(id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), 0, 0, 0, 0)); fg.addImage(image); } fg.setLineWidth(.5f * ratio); fg.setColorStroke(new BaseColor(Color.decode("0x6E2405").getRGB())); fg.setColorFill(new BaseColor(Color.decode("0x6E2405").getRGB())); float tHeight = scalar[1]; float tWidth = 0; if (id.length() > 3) { tWidth = (scalar[0] * (id.length() / 5f)); } else { tWidth = (scalar[0]); } fg.moveTo(coords[0], coords[1]); fg.lineTo(coords[0] + (10f * ratio), coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] + (tHeight / 2)); fg.lineTo(coords[0] + (10f * ratio), coords[1] + (tHeight / 2)); fg.lineTo(coords[0], coords[1]); fg.closePathFillStroke(); fg.fill(); // Comment number that goes on the comment tag image Phrase p = new Phrase(id); p.getFont().setColor(BaseColor.WHITE); p.getFont().setSize(8f * ratio); //comment number font size = 8f //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id)); float fs[] = translateRotation(f[0], f[1], pageNum); fs = checkBounds(fs[0], fs[1], pageNum); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, p, (float) (fs[0] + (9 * ratio)), (float) (fs[1] - (3 * ratio)), 0); return ""; }
From source file:es.clinica.veterinaria.facturas.FacturaPdf.java
private void initializeFonts() throws DocumentException, IOException { try {/*www. j av a 2 s .c o m*/ bfBold = BaseFont.createFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Excel.pdfsJavaGenerador.java
public void run() { Document documento = new Document(); documento.setPageSize(PageSize.A4.rotate()); int i = 1;// ww w.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); } }