List of usage examples for com.itextpdf.text.pdf BaseFont CP1252
String CP1252
To view the source code for com.itextpdf.text.pdf BaseFont CP1252.
Click Source Link
From source file:Almacen.Responsiva.java
private void b_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_imprimirActionPerformed // TODO add your handling code here: Session session = HibernateUtil.getSessionFactory().openSession(); try {//from w ww .j a va2 s .c om String empleado = ""; String puesto = ""; if (t_datos.getRowCount() > 0) { //consulta Query q = session.createSQLQuery( "select empleado.nombre as empleado, puestos.nombre as puesto from empleado inner join puestos on puestos.id_puestos=empleado.id_puesto where empleado.id_empleado=" + t_id_empleado.getText() + ";"); q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); List lista = q.list(); for (int i = 0; i < lista.size(); i++) { java.util.HashMap map = (java.util.HashMap) lista.get(i); empleado = (String) map.get("empleado"); puesto = (String) map.get("puesto"); } Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String Mes[] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; Calendar fecha1 = new GregorianCalendar(); int anio = fecha1.get(Calendar.YEAR); int mes = fecha1.get(Calendar.MONTH); int dia = fecha1.get(Calendar.DAY_OF_MONTH); //DateFormat dateFormat1 = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); File folder = new File("reportes/Responsivas"); folder.mkdirs(); PdfReader reader = new PdfReader("imagenes/CartaResponsiva.pdf"); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("reportes/Responsivas/" + valor + "CartaResponsiva.pdf")); PdfContentByte cb = stamp.getUnderContent(1); PdfContentByte cb2 = stamp.getUnderContent(2); AcroFields fdfDoc = stamp.getAcroFields(); // Creo una fuente BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); cb.beginText(); //dia try { if (dia < 9) fdfDoc.setField("Dia", "0" + String.valueOf(dia)); else fdfDoc.setField("Dia", String.valueOf(dia)); } catch (Exception e) { fdfDoc.setField("Dia", "error"); } //mes try { fdfDoc.setField("Mes", Mes[mes]); } catch (Exception e) { fdfDoc.setField("Mes", ""); } //ao try { fdfDoc.setField("Anio", String.valueOf(anio)); } catch (Exception e) { fdfDoc.setField("Anio", ""); } //nombre try { fdfDoc.setField("Nombre", empleado); } catch (Exception e) { fdfDoc.setField("Nombre", ""); } //puesto try { fdfDoc.setField("Puesto", puesto); } catch (Exception e) { fdfDoc.setField("Puesto", ""); } //tabla de herramientas float tam[] = new float[] { 250, 50, 180 }; Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD); PDF reporte = new PDF(); PdfPTable tabla = reporte.crearTabla(3, tam, 100, Element.ALIGN_LEFT); tabla.setTotalWidth(tam); BaseColor cabecera = BaseColor.GRAY; BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; tabla.addCell(reporte.celda("HERRAMIENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("CANTIDAD", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("NOTAS", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); for (int i = 0; i < t_datos.getRowCount(); i++) { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 1).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(String.valueOf((double) t_datos.getValueAt(i, 2)), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); if (t_datos.getValueAt(i, 3) != null) tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } tabla.completeRow(); tabla.writeSelectedRows(0, -1, 70, 720, cb2); cb.endText(); stamp.close(); reporte.cerrar(); reporte.visualizar("reportes/Responsivas/" + valor + "CartaResponsiva.pdf"); } else { JOptionPane.showMessageDialog(this, "No Existe Ninguna Responsiva"); } } 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(); } } }
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Generate a bout sheet report that has no data in it (only the image). * The length is the given number of pages. * /* w ww. jav a 2 s. c o m*/ * @param numPages * @return True if the report was generated. */ public boolean generateBlank(Dao dao, Integer numPages) { // step 1: creation of a document-object // rotate to make page landscape Document document = new Document(PageSize.A4.rotate()); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); writer.setPageEvent(this); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); float pageWidth = cb.getPdfDocument().getPageSize().getWidth(); float midPage = pageWidth / 2; setHeaderString(dao); int count = 1; while (true) { drawBout(cb, bf, 35, midPage - 35, null); drawBout(cb, bf, midPage + 35, pageWidth - 35, null); if (++count > numPages) { break; } document.newPage(); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Generate a bout sheet report for the given list of bouts. * It is assumed that the list is in the desired order (no sorting is done here). * * @param list//from ww w . j ava 2s . c o m * @return True if the report was generated. */ public boolean generateReport(Dao dao, List<Bout> list) { // step 1: creation of a document-object // rotate to make page landscape Document document = new Document(PageSize.A4.rotate()); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); writer.setPageEvent(this); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); float pageWidth = cb.getPdfDocument().getPageSize().getWidth(); float midPage = pageWidth / 2; setHeaderString(dao); int count = 0; for (Bout b : list) { boolean rightSide = false; if ((count++ % 2) == 0) { if (count > 2) { // We could put this after Bout 2 is added, but // that could leave a blank last page. document.newPage(); } // Bout 1 (Left side) drawBout(cb, bf, 35, midPage - 35, b); } else { // Bout 2 (Right side) drawBout(cb, bf, midPage + 35, pageWidth - 35, b); rightSide = true; } // Print the watermark, if necessary boolean doWatermark = false; String gClass = b.getGroup().getClassification(); String wmValues = dao.getBoutsheetWatermarkValues(); if ((wmValues != null) && !wmValues.isEmpty()) { String[] tokens = wmValues.split(","); for (String s : tokens) { if (s.trim().equalsIgnoreCase(gClass)) { doWatermark = true; break; } } } if (doWatermark) { int rotation = 45; PdfContentByte ucb = writer.getDirectContentUnder(); BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); ucb.saveState(); ucb.setColorFill(BaseColor.LIGHT_GRAY); ucb.beginText(); ucb.setFontAndSize(helv, 86); float centerWidth = document.getPageSize().getWidth() / 4; if (rightSide) { centerWidth = centerWidth * 3; } ucb.showTextAligned(Element.ALIGN_CENTER, gClass, centerWidth, document.getPageSize().getHeight() / 2, rotation); ucb.endText(); ucb.restoreState(); } } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawString(PdfContentByte cb, BaseFont bf, float x, float y, float fontSize, String string) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }//from www .j av a2 s . com cb.setFontAndSize(bf, fontSize); cb.beginText(); cb.setTextMatrix(x, y); cb.showText(string); cb.endText(); cb.stroke(); }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawString(PdfContentByte cb, BaseFont bf, float x, float y, float fontSize, String string, boolean strikethrough) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }//w w w . j a v a2 s . c o m drawString(cb, bf, x, y, fontSize, string); if (strikethrough) { float halfHeight = (bf.getAscentPoint(string, fontSize)) / 2; float width = bf.getWidthPointKerned(string, fontSize); drawHorizontalLine(cb, x, y + halfHeight, width, 1.5f, 0); } }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawString(PdfContentByte cb, BaseFont bf, float mid, float y, float fontSize, String string, float rotation) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }// www. j a v a 2 s . co m cb.setFontAndSize(bf, fontSize); cb.beginText(); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, string, mid, y, rotation); cb.endText(); cb.stroke(); }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawString(PdfContentByte cb, BaseFont bf, float mid, float y, float fontSize, String string, float rotation, boolean strikethrough) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }/*from ww w. j a va2 s . c om*/ drawString(cb, bf, mid, y, fontSize, string, rotation); if (strikethrough) { float halfHeight = (bf.getAscentPoint(string, fontSize)) / 2; float width = bf.getWidthPointKerned(string, fontSize); if (rotation == 0) { drawHorizontalLine(cb, mid, y + halfHeight, width, 1.5f, 0); } else if (rotation == 90) { drawVerticalLine(cb, mid - halfHeight, y, width, 1.5f, 0); } } }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawStringAligned(PdfContentByte cb, BaseFont bf, int alignment, float mid, float y, float fontSize, String string, float rotation) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }//from www. ja va2 s . c o m cb.setFontAndSize(bf, fontSize); cb.beginText(); cb.showTextAligned(alignment, string, mid, y, rotation); cb.endText(); cb.stroke(); }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawStringCentered(PdfContentByte cb, BaseFont bf, float mid, float y, float fontSize, String string, float rotation) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }/* w w w .java 2 s . co m*/ cb.setFontAndSize(bf, fontSize); cb.beginText(); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, (string != null) ? string : "", mid, y, rotation); cb.endText(); cb.stroke(); }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawTournamentHeader(PdfContentByte cb, BaseFont bf, float x, float y, Dao dao, float rotation) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }//from www .ja v a 2 s.co m float linePad = 15; String name = dao.getName(); if (name != null) { drawString(cb, bf, x, y, 12, name, rotation); if (rotation == 0) { y -= linePad; } else { x += linePad; } } String site = dao.getSite(); if (site != null) { drawString(cb, bf, x, y, 12, site, rotation); if (rotation == 0) { y -= linePad; } else { x += linePad; } } String city = dao.getCity(); String state = dao.getState(); if ((city != null) || (state != null)) { String cityState = ""; if (city != null) { cityState = city; if (state != null) { cityState += ", "; } } if (state != null) { cityState += state; } drawString(cb, bf, x, y, 12, cityState, rotation); if (rotation == 0) { y -= linePad; } else { x += linePad; } } String month = dao.getMonth(); Integer day = dao.getDay(); Integer year = dao.getYear(); if ((month != null) || (year != null)) { String date = ""; if (month != null) { date = month; if (day != null) { date += " " + day; } if (year != null) { date += ", "; } } if (year != null) { date += year; } drawString(cb, bf, x, y, 12, date, rotation); } }