List of usage examples for com.itextpdf.text Image scaleToFit
public void scaleToFit(final float fitWidth, final float fitHeight)
From source file:GUI.Framenewventa.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed if (jLabel17.getText().toString().equals("-")) { JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE"); } else {//from w w w. jav a2 s.c om try { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); funciones f = new funciones(); String dia = (Calendar.getInstance().getTime().getDate() < 10) ? "0" + Calendar.getInstance().getTime().getDate() : Calendar.getInstance().getTime().getDate() + ""; String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1)); String anio = (Calendar.getInstance().getTime().getYear() + 1900) + ""; String nombre = "COTIZACION TIENDA ULTIMO ROUND"; String rut_socio = ""; int mon = 0; String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf"; DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); Date date = new Date(); String stringToEncrypt = nombre.trim() + dateFormat.format(date); int encryptedString = stringToEncrypt.trim().hashCode(); String aRemplazar = Integer.toString(encryptedString); String remplazado = aRemplazar.replace("-", ""); String url = f.getRutaCotizacion() + arch; FileOutputStream archivo = new FileOutputStream(url); int deuda = Integer.parseInt("1"); String palabra = f.Convertir(deuda + "", false); palabra = palabra.substring(0, palabra.length() - 2); if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones") | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) { palabra = palabra + "de pesos"; } else { palabra = palabra + "pesos"; } Document documento = new Document(PageSize.LETTER); PdfWriter.getInstance(documento, archivo); documento.open(); try { Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png"); im.setAlignment(Image.ALIGN_CENTER); im.scaleToFit(600, 400); documento.add(im); } catch (Exception e) { setCursor(Cursor.getDefaultCursor()); JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.", "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE); } int linea = 0; Font fuente = new Font(); fuente.setStyle(Font.UNDERLINE | Font.BOLD); fuente.setSize(11); fuente.setColor(BaseColor.BLACK); documento.add(new Paragraph(" ")); Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n", FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK)); fecha.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(fecha); Paragraph obp = new Paragraph("ULTIMO ROUND\n", FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK)); obp.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(obp); Paragraph codigo = new Paragraph("COD." + remplazado, FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK)); codigo.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(codigo); Paragraph space = new Paragraph("\n", FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK)); space.setAlignment(Paragraph.ALIGN_LEFT); documento.add(space); Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); origen.setAlignment(Paragraph.ALIGN_LEFT); documento.add(origen); Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); origen2.setAlignment(Paragraph.ALIGN_LEFT); documento.add(origen2); Paragraph a = new Paragraph(nombre, FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); a.setAlignment(Paragraph.ALIGN_LEFT); documento.add(a); Paragraph rut = new Paragraph(rut_socio, FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); rut.setAlignment(Paragraph.ALIGN_LEFT); documento.add(rut); Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n", FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK)); ref.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(ref); documento.add(space); int numerocheque = 0; int montofinal = 0; String montostring = ""; String detalle = ""; String monto = jLabel22.getText(); String montoaux = monto.replace(".", ""); deuda = Integer.parseInt(montoaux); palabra = f.Convertir(deuda + "", false); System.out.println(palabra); palabra = palabra.replaceAll("0", ""); System.out.println(palabra); Paragraph e = new Paragraph( "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos" + " por el monto de $" + monto + ".- ( " + palabra + "pesos IVA INCLUIDO) ,segn detalle:\n\n", FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK)); e.setAlignment(Paragraph.ALIGN_LEFT); documento.add(e); documento.add(new Paragraph(" ")); // ACA DEBE IR LA TABLA //special font sizes Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0)); Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10); //specify column widths //create PDF table with the given widths documento.add(new Paragraph(" ")); float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f }; PdfPTable tabla = new PdfPTable(5); tabla.setWidths(colsWidth); String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" }; tabla.setWidthPercentage(100); PdfPCell celda; for (int k = 0; k < titulos.length; k++) { celda = new PdfPCell(new Paragraph(titulos[k], FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } int var = 0; int w = 0; for (w = 0; w < jTable1.getRowCount(); w++) { celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("MONTO NETO", FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(monto, FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("IVA TOTAL", FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); double iva2 = Float.parseFloat(monto) * (0.19); iva2 = Math.round(iva2); celda = new PdfPCell(new Paragraph(Double.toString(iva2), FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("VALOR TOTAL", FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); int valortotal = Integer.parseInt(monto); ; celda = new PdfPCell(new Paragraph(Integer.toString(valortotal), FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); //FOOOTER documento.add(space); Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); despido.setAlignment(Paragraph.ALIGN_LEFT); documento.add(despido); documento.add(space); Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); firma2.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(firma2); documento.add(space); documento.add(space); documento.add(space); Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); firma3.setAlignment(Paragraph.ALIGN_CENTER); documento.add(firma3); documento.add(space); documento.add(space); try { Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png"); im.setAlignment(Image.ALIGN_CENTER); im.scaleToFit(600, 500); documento.add(im); } catch (Exception ex) { setCursor(Cursor.getDefaultCursor()); JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE); } documento.close(); setCursor(Cursor.getDefaultCursor()); JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN", JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE); } catch (Exception ex) { setCursor(Cursor.getDefaultCursor()); JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE); } } }
From source file:GUI.frameNewVentaKit.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed if (jLabel17.getText().toString().equals("-")) { JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE"); } else {//from w ww .ja v a 2 s . c o m try { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); funciones f = new funciones(); String dia = (Calendar.getInstance().getTime().getDate() < 10) ? "0" + Calendar.getInstance().getTime().getDate() : Calendar.getInstance().getTime().getDate() + ""; String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1)); String anio = (Calendar.getInstance().getTime().getYear() + 1900) + ""; String nombre = "COTIZACION TIENDA ULTIMO ROUND"; String rut_socio = ""; int mon = 0; String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf"; DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); Date date = new Date(); String stringToEncrypt = nombre.trim() + dateFormat.format(date); int encryptedString = stringToEncrypt.trim().hashCode(); String aRemplazar = Integer.toString(encryptedString); String remplazado = aRemplazar.replace("-", ""); String url = f.getRutaCotizacion() + arch; FileOutputStream archivo = new FileOutputStream(url); int deuda = Integer.parseInt("1"); String palabra = f.Convertir(deuda + "", false); palabra = palabra.substring(0, palabra.length() - 2); if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones") | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) { palabra = palabra + "de pesos"; } else { palabra = palabra + "pesos"; } Document documento = new Document(PageSize.LETTER); PdfWriter.getInstance(documento, archivo); documento.open(); try { Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png"); im.setAlignment(Image.ALIGN_CENTER); im.scaleToFit(600, 400); documento.add(im); } catch (Exception e) { setCursor(Cursor.getDefaultCursor()); JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.", "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE); } int linea = 0; Font fuente = new Font(); fuente.setStyle(Font.UNDERLINE | Font.BOLD); fuente.setSize(11); fuente.setColor(BaseColor.BLACK); documento.add(new Paragraph(" ")); Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n", FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK)); fecha.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(fecha); Paragraph obp = new Paragraph("ULTIMO ROUND\n", FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK)); obp.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(obp); Paragraph codigo = new Paragraph("COD." + remplazado, FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK)); codigo.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(codigo); Paragraph space = new Paragraph("\n", FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK)); space.setAlignment(Paragraph.ALIGN_LEFT); documento.add(space); Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); origen.setAlignment(Paragraph.ALIGN_LEFT); documento.add(origen); Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); origen2.setAlignment(Paragraph.ALIGN_LEFT); documento.add(origen2); Paragraph a = new Paragraph(nombre, FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); a.setAlignment(Paragraph.ALIGN_LEFT); documento.add(a); Paragraph rut = new Paragraph(rut_socio, FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); rut.setAlignment(Paragraph.ALIGN_LEFT); documento.add(rut); Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n", FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK)); ref.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(ref); documento.add(space); int numerocheque = 0; int montofinal = 0; String montostring = ""; String detalle = ""; String monto = jLabel22.getText(); String montoaux = monto.replace(".", ""); deuda = Integer.parseInt(montoaux); palabra = f.Convertir(deuda + "", false); System.out.println(palabra); palabra = palabra.replaceAll("0", ""); System.out.println(palabra); Paragraph e = new Paragraph( "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos" + " por el monto de $" + monto + ".- ( " + palabra + "pesos IVA INCLUIDO) ,segn detalle:\n\n", FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK)); e.setAlignment(Paragraph.ALIGN_LEFT); documento.add(e); documento.add(new Paragraph(" ")); // ACA DEBE IR LA TABLA //special font sizes Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0)); Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10); //specify column widths //create PDF table with the given widths documento.add(new Paragraph(" ")); float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f }; PdfPTable tabla = new PdfPTable(5); tabla.setWidths(colsWidth); String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" }; tabla.setWidthPercentage(100); PdfPCell celda; for (int k = 0; k < titulos.length; k++) { celda = new PdfPCell(new Paragraph(titulos[k], FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } int var = 0; int w = 0; for (w = 0; w < jTable1.getRowCount(); w++) { celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("MONTO NETO", FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph(monto, FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("IVA TOTAL", FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); double iva2 = Float.parseFloat(monto) * (0.19); iva2 = Math.round(iva2); celda = new PdfPCell(new Paragraph(Double.toString(iva2), FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("", FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("VALOR TOTAL", FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); int valortotal = Integer.parseInt(monto); celda = new PdfPCell(new Paragraph(Integer.toString(valortotal), FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK))); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); //FOOOTER documento.add(space); Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); despido.setAlignment(Paragraph.ALIGN_LEFT); documento.add(despido); documento.add(space); Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); firma2.setAlignment(Paragraph.ALIGN_RIGHT); documento.add(firma2); documento.add(space); documento.add(space); documento.add(space); Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n", FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK)); firma3.setAlignment(Paragraph.ALIGN_CENTER); documento.add(firma3); documento.add(space); documento.add(space); try { Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png"); im.setAlignment(Image.ALIGN_CENTER); im.scaleToFit(600, 500); documento.add(im); } catch (Exception ex) { setCursor(Cursor.getDefaultCursor()); JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE); } documento.close(); setCursor(Cursor.getDefaultCursor()); JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN", JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE); } catch (Exception ex) { setCursor(Cursor.getDefaultCursor()); JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE); } } }
From source file:info.longnetpro.examples.PdfLibExamples.java
public static void generatePdf() throws DocumentException, URISyntaxException, MalformedURLException, IOException { String licFile = getLicenseFilePath(); loadLicenseFile(licFile);/*from w w w . j a va 2s . com*/ String dest = getTargetFilePath(); Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(dest)); Rectangle pageSize = PageSize.LETTER; Rectangle rect = new Rectangle(0f, 0f, 50f, 100f); rect.setBorder(15); rect.setBorderColor(BaseColor.RED); rect.setBorderWidth(.5f); rect.setBackgroundColor(BaseColor.BLUE); doc.setPageSize(pageSize); doc.open(); Page page = new Page(pageSize.getWidth(), pageSize.getHeight()); ContentBox rpage = page.margin(new Float[] { 10f, 50f, 10f, 50f }); for (Anchor anchor : Anchor.values()) { ContentBox box = new ContentBox(50f, 100f); float offx = anchor.equals(Anchor.CENTER) ? -50f : 0f; float offy = anchor.equals(Anchor.CENTER) ? -50f : 0f; ContentBox rr = anchor.anchorElement(rpage, box, offx, offy); if (anchor.equals(Anchor.BOTTOM_LEFT)) { float[] dim = box.scaleByPercentage(0.5f); //rr = rr.reposition(dim[0], dim[1], Anchor.TOP_RIGHT); } rect.setLeft(rr.getLeft()); rect.setBottom(rr.getBottom()); rect.setRight(rr.getRight()); rect.setTop(rr.getTop()); doc.add(rect); } String imageFile = getImageFilePath(); Image image = Image.getInstance(imageFile); float width = Measurement.dotsToUserUnits(image.getWidth(), 1200); float height = Measurement.dotsToUserUnits(image.getHeight(), 1200); System.out.println(width + " " + height); ContentBox img = Anchor.BOTTOM_LEFT.anchorElement(rpage, width, height); image.scaleToFit(width, height); image.setAbsolutePosition(img.getLeft(), img.getBottom()); System.out.println(image.getWidth() + " " + image.getHeight()); System.out.println(image.getAbsoluteX() + " " + image.getAbsoluteY()); doc.add(image); doc.close(); }
From source file:itextpdf.GeneratePdf.java
License:Minecraft Mod Public
public void addPhoto(String photoName) { try {/*from ww w . ja va2 s.c o m*/ Image image = Image.getInstance(photoName); image.scaleToFit(400, 400); image.setAlignment(Chunk.ALIGN_MIDDLE); document.add(image); } catch (Exception e) { e.printStackTrace(); } }
From source file:jsimpresos.ConexionNotas.java
public void generarPdf(int idNota, String nombre, int cuenta) { Document documento = new Document(); Nota nota = this.getNotaPorId(idNota); FileOutputStream ficheroPdf;// ww w . j a va 2s. c o m try { File carpeta = new File("C:\\archivosPuntoDeVenta"); if (!carpeta.exists()) { carpeta.mkdir(); } ficheroPdf = new FileOutputStream("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); documento.setMargins(0, 0, 0, 0); documento.open(); Image foto = Image.getInstance("c:/archivosPuntoDeVenta/logo.JPG"); foto.scaleToFit(80, 90); PdfPTable tabla = new PdfPTable(5); tabla.setWidths(new float[] { 13, 12, 25, 25, 25 }); tabla.setWidthPercentage(100); PdfPCell celda = new PdfPCell(); celda.addElement(foto); celda.setBorder(Rectangle.NO_BORDER); celda.setRowspan(6); tabla.addCell(celda); PdfPCell celda2 = new PdfPCell( new Paragraph("NOTA DE PEDIDO", FontFactory.getFont("Arial", 15, Font.BOLD))); System.out.println(nota.getUsuario()); celda2.setColspan(3); celda2.setUseAscender(true); celda2.setBorder(Rectangle.NO_BORDER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); tabla.addCell(celda2); PdfPCell celdaFecha = new PdfPCell(new Paragraph("Fecha: " + nota.getFecha())); celdaFecha.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdaFecha); PdfPCell celda3 = new PdfPCell(new Phrase("Calle del Rayo y 2 de Abril 31a. Col. centro, Parral, Chih.", FontFactory.getFont("Arial", 7, Font.BOLD, BaseColor.RED))); celda3.setColspan(2); celda3.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda3); PdfPCell celda4 = new PdfPCell(new Phrase("Tel. 5230073 y 6271034745", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.RED))); celda4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda4); Paragraph p = new Paragraph("No. " + nota.getIdNota(), FontFactory.getFont("Arial", 13, Font.BOLD, BaseColor.RED)); PdfPCell celda5 = new PdfPCell(); celda5.setUseAscender(true); celda5.setVerticalAlignment(Element.ALIGN_MIDDLE); celda5.setHorizontalAlignment(Element.ALIGN_MIDDLE); celda5.addElement(p); tabla.addCell(celda5); PdfPCell celdanueva = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva.setBorder(Rectangle.NO_BORDER); celdanueva.setColspan(4); tabla.addCell(celdanueva); PdfPCell celdanueva1 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva1.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva1); PdfPCell celdanueva2 = new PdfPCell( new Phrase("Datos del cliente", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva2.setBorder(Rectangle.NO_BORDER); celdanueva2.setColspan(3); tabla.addCell(celdanueva2); PdfPCell celdanueva3 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva3.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva3); if (nota.getCliente() == null) { PdfPCell celda6 = new PdfPCell( new Phrase("Cliente: " + nota.getNombres() + " " + nota.getApPaterno(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda6.setBorder(Rectangle.NO_BORDER); celda6.setColspan(3); tabla.addCell(celda6); PdfPCell celdanueva4 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva4); PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio: " + nota.getDomicilio(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda7.setBorder(Rectangle.NO_BORDER); celda7.setColspan(2); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getTelefono(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda8.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda8); } else { PdfPCell celda6 = new PdfPCell(new Phrase( "Cliente: " + nota.getCliente().getNombres() + " " + nota.getCliente().getApPaterno(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda6.setBorder(Rectangle.NO_BORDER); celda6.setColspan(3); tabla.addCell(celda6); PdfPCell celdanueva4 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva4); PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio: " + nota.getCliente().getDomicilio(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda7.setBorder(Rectangle.NO_BORDER); celda7.setColspan(2); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getCliente().getTelefono(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda8.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda8); } PdfPTable tabla2 = new PdfPTable(4); tabla2.setWidths(new float[] { 10, 70, 15, 15 }); tabla2.setWidthPercentage(99.5f); PdfPCell celda21 = new PdfPCell( new Phrase("Cantidad", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda21); PdfPCell celda22 = new PdfPCell( new Phrase("Artculo", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda22); PdfPCell celda23 = new PdfPCell( new Phrase("Precio unitario", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda23); PdfPCell celda24 = new PdfPCell( new Phrase("Total", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda24); double total = 0; for (int i = 0; i < 6; i++) { if (i < nota.getArticulos().size()) { PdfPCell celda25 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getCantidad() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda25); PdfPCell celda26 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getServicio() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda26); PdfPCell celda27 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getPrecio() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda27); PdfPCell celda28 = new PdfPCell(new Phrase( (nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio()) + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda28); total += nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio(); } else { PdfPCell celda29 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda29); tabla2.addCell(celda29); tabla2.addCell(celda29); tabla2.addCell(celda29); } } PdfPTable tabla3 = new PdfPTable(4); tabla3.setWidths(new float[] { 55, 25, 15, 15 }); tabla3.setWidthPercentage(99.5f); PdfPCell celda31 = new PdfPCell(new Phrase("Observaciones: " + nota.getObservaciones(), FontFactory.getFont("Arial", 9, BaseColor.BLACK))); celda31.setRowspan(4); tabla3.addCell(celda31); PdfPCell celda32 = new PdfPCell(new Phrase( "Suma recibida de abono : " + nota.getAbonos().get(nota.getAbonos().size() - 1).getMonto(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda32.setRowspan(4); tabla3.addCell(celda32); PdfPCell celda33 = new PdfPCell( new Phrase("Total", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda33); PdfPCell celda34 = new PdfPCell( new Phrase(total + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda34); PdfPCell celda35 = new PdfPCell( new Phrase("Total abonado", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda35); double totalAbonado = 0; for (int i = 0; i < nota.getAbonos().size(); i++) { totalAbonado += nota.getAbonos().get(i).getMonto(); } PdfPCell celda36 = new PdfPCell( new Phrase(totalAbonado + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda36); PdfPCell celda37 = new PdfPCell( new Phrase("Saldo actual", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda37); PdfPCell celda38 = new PdfPCell(new Phrase((total - totalAbonado) + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda38); PdfPCell celda39 = new PdfPCell( new Phrase("Fecha entrega", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda39); PdfPCell celda40 = new PdfPCell(new Phrase(nota.getFechaEntrega(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda40); PdfPTable tabla4 = new PdfPTable(3); tabla4.setWidths(new float[] { 30, 30, 30 }); tabla4.setWidthPercentage(99.5f); PdfPCell celda41 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda41.setBorder(Rectangle.NO_BORDER); celda41.setColspan(3); tabla4.addCell(celda41); PdfPCell celda42 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda42.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda42); PdfPCell celda43 = new PdfPCell(new Phrase("Firma de conformidad del cliente: ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda43.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda43); PdfPCell celda44 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda44.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda44); tabla4.addCell(celda41); tabla4.addCell(celda41); tabla4.addCell(celda41); documento.add(tabla); documento.add(tabla2); documento.add(tabla3); documento.add(tabla4); documento.add(tabla); documento.add(tabla2); documento.add(tabla3); documento.add(tabla4); documento.close(); abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); } catch (FileNotFoundException ex) { // JOptionPane.showMessageDialog(null, "Error con el pdf"); // System.out.println(ex.getMessage()); cuenta++; generarPdf(idNota, "nota", cuenta); abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error al guardar pdf"); System.out.println(ex.getMessage()); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error con el pdf"); } }
From source file:modelo.DTO.PDF_Registro2.java
public static void generar() throws DocumentException, FileNotFoundException, BadElementException, IOException { Rectangle pageSize = new Rectangle(816f, 1056f); //ancho y alto miPDF = new Document(pageSize, 0, 0, 0, 0); PdfWriter.getInstance(miPDF, new FileOutputStream(PDF_Registro2.rutaDestino + ".pdf")); miPDF.open();//from w ww . j a v a 2s . c o m miPDF.addTitle("Registro"); miPDF.addAuthor("Universidad Tecnolgica de Len"); miPDF.addSubject("Constancia de Registro"); miPDF.addKeywords("1"); //Inicio //Image foto = Image.getInstance("src/imagens/Registro.png"); String thisIp = InetAddress.getLocalHost().getHostAddress(); Image foto = Image.getInstance("http://" + thisIp + ":8084/ExamenParcial2Web/imagenes/Registro.png"); foto.setAlignment(Chunk.ALIGN_MIDDLE); foto.scaleToFit(816, 754); miPDF.add(foto); PdfPTable ta = new PdfPTable(2); PdfPCell celda; celda = new PdfPCell(new Paragraph("\nClave:\n\n", FontFactory.getFont("arial", 12, Font.BOLD))); celda.setBorderColor(BaseColor.WHITE); ta.addCell(celda); celda = new PdfPCell(new Paragraph("\n" + clave + "\n\n")); celda.setBorderColor(BaseColor.WHITE); ta.addCell(celda); celda = new PdfPCell(new Paragraph("\nNombre:\n\n", FontFactory.getFont("arial", 12, Font.BOLD))); celda.setBorderColor(BaseColor.WHITE); ta.addCell(celda); celda = new PdfPCell(new Paragraph("\n" + nombre + "\n\n")); celda.setBorderColor(BaseColor.WHITE); ta.addCell(celda); celda = new PdfPCell(new Paragraph("\nE-mail:\n\n", FontFactory.getFont("arial", 12, Font.BOLD))); celda.setBorderColor(BaseColor.WHITE); ta.addCell(celda); celda = new PdfPCell(new Paragraph("\n" + email + "\n\n")); celda.setBorderColor(BaseColor.WHITE); ta.addCell(celda); celda = new PdfPCell(new Paragraph("\nUT:\n\n", FontFactory.getFont("arial", 12, Font.BOLD))); celda.setBorderColor(BaseColor.WHITE); ta.addCell(celda); celda = new PdfPCell(new Paragraph("\n" + procedencia + "\n\n")); celda.setBorderColor(BaseColor.WHITE); ta.addCell(celda); miPDF.add(ta); miPDF.close(); //Fin miPDF.close(); }
From source file:objects.manipulate.java
public static void createPDF(String filename, String[] RESOURCES) throws DocumentException, FileNotFoundException, IOException { Document document = new Document(); document.setMargins(0, 0, 0, 0);/* w ww . jav a2s .com*/ Rectangle rectangle = new Rectangle(0, 0, 742, 960); document.setPageSize(rectangle); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); Image img; for (int i = 0; i < RESOURCES.length; i++) { //img = Image.getInstance(String.format("resources/img/%s", RESOURCES[i])); img = Image.getInstance(RESOURCES[i]); if (img.getScaledWidth() > 742 || img.getScaledHeight() > 960) { img.scaleToFit(742, 960); } document.add(img); } document.close(); }
From source file:org.bonitasoft.studio.migration.utils.PDFMigrationReportWriter.java
License:Open Source License
private com.itextpdf.text.Image getImageForStatus(int status) throws BadElementException, MalformedURLException, IOException { switch (status) { case IStatus.OK: Image im = Image.getInstance(FileLocator .toFileURL(MigrationPlugin.getDefault().getBundle().getResource("/icons/valid.png"))); im.setCompressionLevel(12);/*from w w w . j a va2 s . c o m*/ im.scaleToFit(12, 12); return im; case IStatus.WARNING: im = Image.getInstance(FileLocator .toFileURL(MigrationPlugin.getDefault().getBundle().getResource("/icons/warning.gif"))); im.setCompressionLevel(12); im.scaleToFit(16, 16); return im; case IStatus.ERROR: im = Image.getInstance(FileLocator .toFileURL(MigrationPlugin.getDefault().getBundle().getResource("/icons/error.png"))); im.setCompressionLevel(12); im.scaleToFit(12, 12); return im; default: break; } return null; }
From source file:org.jaqpot.core.service.data.ReportService.java
/** helper function to add logo image in header*/ public static PdfPCell createImageCell(String path) throws DocumentException, IOException { Image img = Image.getInstance(path); img.scaleToFit(120f, 120f); PdfPCell cell = new PdfPCell(img, false); cell.setPaddingBottom(5f);// w w w . java 2 s . c om cell.setUseBorderPadding(true); cell.setBorder(Rectangle.BOTTOM); return cell; }
From source file:org.obiba.mica.PdfUtils.java
License:Open Source License
public static void addImage(byte[] input, OutputStream output, Image image, String placeholder) throws IOException, DocumentException { try (PdfReaderAutoclosable pdfReader = new PdfReaderAutoclosable(input); PdfStamperAutoclosable pdfStamper = new PdfStamperAutoclosable(pdfReader, output)) { AcroFields form = pdfStamper.getAcroFields(); List<AcroFields.FieldPosition> positions = form.getFieldPositions(placeholder); positions.forEach(p -> {/*from w ww. j a v a2 s .c om*/ image.scaleToFit(p.position.getWidth(), p.position.getHeight()); image.setAbsolutePosition( p.position.getLeft() + (p.position.getWidth() - image.getScaledWidth()) / 2, p.position.getBottom() + (p.position.getHeight() - image.getScaledHeight()) / 2); PdfContentByte cb = pdfStamper.getOverContent(p.page); try { cb.addImage(image); } catch (DocumentException e) { throw Throwables.propagate(e); } }); } }