List of usage examples for com.itextpdf.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.itextpdf.text Element ALIGN_LEFT.
Click Source Link
From source file:Output.QuotePDf.java
private PdfPTable packingListTable(JTable packingListTable) throws DocumentException { PdfPTable table = new PdfPTable(11); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100f);/*from w w w. j a va 2 s. c o m*/ table.setWidths(new int[] { 5, 2, 2, 2, 2, 3, 2, 2, 2, 3, 3 }); table.setSpacingAfter(10f); cell = new PdfPCell(new Phrase("Packing List", tableHeadingFont)); cell.setBackgroundColor(BaseColor.BLACK); cell.setColspan(11); cell.setPaddingBottom(5); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Commodity", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("Qty", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("L(cm)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("W(cm)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("H(cm)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("Kgs", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("L(in)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("W(in)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("H(in)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("M3", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("Lbs", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); for (int row = 0; row < packingListTable.getRowCount(); row++) { for (int col = 0; col < 11; col++) { String packingListData = String.valueOf(packingListTable.getValueAt(row, col)); if (packingListData.equals("null")) { packingListData = " "; cell = new PdfPCell(new Phrase(packingListData, textFont)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(packingListData, textFont)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } } } return table; }
From source file:PDF.CrearPDF_Ficha.java
public void generarPDF(ServletOutputStream sops, DatosPDF datos, String url) { try {/*from w ww .j av a 2 s. co m*/ Document documento = new Document(); // ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(documento, sops); documento.open(); Image itt_logo; try { itt_logo = Image.getInstance(url); Image Logo_itt = Image.getInstance(itt_logo); Logo_itt.setAbsolutePosition(50f, 698f); Logo_itt.scaleAbsolute(90, 100); documento.add(Logo_itt); } catch (BadElementException | IOException ex) { Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex); } PdfContentByte rectangulo_info = writer.getDirectContentUnder(); drawRectangle(rectangulo_info, 430, 648, 90, 100); Paragraph leyendaFoto = new Paragraph("\nFOTO:\n", FontFactory.getFont("arial", 14, Font.BOLD)); leyendaFoto.setIndentationLeft(200f); Paragraph titulo = new Paragraph("INSTITUTO TECNOLGICO DE TOLUCA", FontFactory.getFont("arial", 14)); titulo.setAlignment(Element.ALIGN_CENTER); Paragraph asunto = new Paragraph("FICHA DE EXAMEN", FontFactory.getFont("arial", 12)); asunto.setAlignment(Element.ALIGN_CENTER); Chunk folio1 = new Chunk("FICHA PARA EL EXAMEN DE ADMISIN: ", FontFactory.getFont("arial", 10)); Chunk folio2 = new Chunk(datos.getFicha(), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase fol = new Phrase(); fol.add(folio1); fol.add(folio2); Paragraph noFicha = new Paragraph(fol); noFicha.setAlignment(Element.ALIGN_LEFT); Chunk nombre1 = new Chunk("NOMBRE DEL SOLICITANTE: ", FontFactory.getFont("arial", 10)); Chunk nombre2 = new Chunk(datos.getNombre(), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase nom = new Phrase(); nom.add(nombre1); nom.add(nombre2); Paragraph nombre = new Paragraph(nom); nombre.setAlignment(Element.ALIGN_LEFT); Chunk in1 = new Chunk("PROCESO PARA EL REGISTRO DE ASPIRANTES EN EL PERIODO: ", FontFactory.getFont("arial", 10)); Chunk in2 = new Chunk(datos.getPeriodoConcursa().toUpperCase(), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase in = new Phrase(); in.add(in1); in.add(in2); Paragraph instrucciones = new Paragraph(in); instrucciones.setAlignment(Element.ALIGN_LEFT); Chunk folCen1 = new Chunk("1.- NMERO DE FOLIO CENEVAL: ", FontFactory.getFont("arial", 10)); Chunk folCen2 = new Chunk(datos.getFolioCENEVAL(), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase folC = new Phrase(); folC.add(folCen1); folC.add(folCen2); Paragraph folioCENEVAL = new Paragraph(folC); folioCENEVAL.setAlignment(Element.ALIGN_LEFT); Chunk fechas1 = new Chunk("2.- LOS EX?MENES DE ADMISIN SE APLICAR?N LOS D?AS: ", FontFactory.getFont("arial", 10)); Chunk fechas2 = new Chunk(datos.getFechaExamenCeneval() + " (" + datos.getLugarExamenCeneval() + ")", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk fechas3 = new Chunk(" Y ", FontFactory.getFont("arial", 10)); Chunk fechas4 = new Chunk(datos.getFechaExamenMate() + " (" + datos.getLugarExamenMate() + ")", FontFactory.getFont("arial", 10, Font.BOLD)); Phrase fechas = new Phrase(); fechas.add(fechas1); fechas.add(fechas2); fechas.add(fechas3); fechas.add(fechas4); Paragraph fechaExamenes = new Paragraph(fechas); fechaExamenes.setAlignment(Element.ALIGN_LEFT); Phrase lugar = new Phrase(); Paragraph lugarYhora = new Paragraph(lugar); lugarYhora.setAlignment(Element.ALIGN_LEFT); Chunk paginaPub1 = new Chunk( "3.- LA PUBLICACIN DE LOS RESULTADOS SER? NICAMENTE EN LA P?GINA WEB: ", FontFactory.getFont("arial", 10)); Anchor url_itt = new Anchor(datos.getPagResultados()); url_itt.setReference(datos.getPagResultados()); Phrase pag = new Phrase(); pag.add(paginaPub1); pag.add(url_itt); Paragraph pagWeb = new Paragraph(pag); Chunk diaPub1 = new Chunk("EL D?A: ", FontFactory.getFont("arial", 10)); Chunk diaPub2 = new Chunk(convertir(datos.getDiaPublicacion() + "-"), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase dia = new Phrase(); dia.add(diaPub1); dia.add(diaPub2); Paragraph diaResultados = new Paragraph(dia); diaResultados.setAlignment(Element.ALIGN_LEFT); Chunk notas = new Chunk("\nNOTAS:\n", FontFactory.getFont("arial", 14, Font.BOLD)); Chunk uno = new Chunk("1.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk guias = new Chunk("Guas de estudio:\n - (CENEVAL) \n", FontFactory.getFont("arial", 10)); Anchor url_guia_cen = new Anchor(" " + datos.getEstudioCeneval()); // url_guia_cen.setReference(datos.getEstudioCeneval()); Chunk ceneval_inter = new Chunk("\n - (CENEVAL INTERACTIVA) \n", FontFactory.getFont("arial", 10)); Anchor url_guia_cen_inter = new Anchor(" " + datos.getEstudioCenevalInt()); url_guia_cen_inter.setReference(datos.getEstudioCenevalInt()); Chunk tem_mate_itt = new Chunk("\n - Temario de Matemticas (TECNOLGICO DE TOLUCA)\n\n", FontFactory.getFont("arial", 10)); Chunk dos = new Chunk("2.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk veri = new Chunk("Verifique que el nmero de folio de Ceneval de esta ficha, coincida con el", FontFactory.getFont("arial", 10)); Chunk fol_ceneval = new Chunk(" FOLIO CENEVAL ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk capturado = new Chunk("capturado en la informacin proporcionada por el Tecnlogico.\n\n", FontFactory.getFont("arial", 10)); Chunk tres = new Chunk("3.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk dia_exam = new Chunk( "El da del examen deber presentarse con el presente documento, pase de ingreso al examen(Ceneval), una identificacin con fotografa reciente(credencial escolar, IMSS, ISSSTE, ISSEMYM, licencia, pasaporte), lpiz del nmero 2 y goma.\n\n", FontFactory.getFont("arial", 10)); Chunk cuatro = new Chunk("4.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk curso = new Chunk( "Si curs sus estudios de secundaria o bachillerato en el extranjero deber presentar revalidacin de estudios correspondientes al momento de la inscripcin.\n", FontFactory.getFont("arial", 10)); Chunk cinco = new Chunk("\n5.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk examenes = new Chunk( "Los exmenes que se evaluarn son: 1) ADMISIN Y DIAGNSTICO. 2) MATEM?TICAS.", FontFactory.getFont("arial", 10)); Phrase ulti = new Phrase(); ulti.add(notas); ulti.add(uno); ulti.add(guias); ulti.add(url_guia_cen); ulti.add(ceneval_inter); ulti.add(url_guia_cen_inter); ulti.add(tem_mate_itt); ulti.add(dos); ulti.add(veri); ulti.add(fol_ceneval); ulti.add(capturado); ulti.add(tres); ulti.add(dia_exam); ulti.add(cuatro); ulti.add(curso); ulti.add(cinco); ulti.add(examenes); Paragraph ultimo = new Paragraph(ulti); ultimo.setAlignment(Element.ALIGN_LEFT); documento.addTitle("Ficha de Examen"); documento.addSubject("Instituto Tecnolgico de Toluca"); documento.addKeywords("Instituto Tecnolgico de Toluca"); documento.addAuthor("Departamento de Servicios escolares"); documento.addCreator("Departamento de Servicios escolares"); documento.add(titulo); documento.add(asunto); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(noFicha); documento.add(nombre); documento.add(new Paragraph(" ")); documento.add(instrucciones); documento.add(new Paragraph(" ")); documento.add(folioCENEVAL); documento.add(fechaExamenes); documento.add(lugarYhora); documento.add(pagWeb); documento.add(diaResultados); documento.add(new Paragraph(" ")); documento.add(ultimo); documento.close(); } catch (DocumentException ex) { Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:pdf.FooterHeader.java
License:Open Source License
@Override public void onCloseDocument(PdfWriter writer, Document document) { ColumnText.showTextAligned(total, Element.ALIGN_LEFT, new Phrase(String.valueOf(writer.getPageNumber() - 1)), 2, 2, 0); }
From source file:pdf.PDFDesign.java
private PdfPTable createLine3Table(Item item, int s1, int s2, int s3) throws DocumentException { if (s1 != 0 && s1 != 0 && s3 != 0) { bigPriceNumberFont.setSize(s1);/* w w w . ja v a2 s. com*/ decimalPriceNumberFont.setSize(s2); decimalPriceNumberFont.setSize(s3); } else { bigPriceNumberFont.setSize(70); } Paragraph p3 = new Paragraph(); p3.setFont(bigPriceNumberFont); p3.add(item.getPrice().substring(0, item.getPrice().length() - 3)); Paragraph p3_2 = new Paragraph(); p3_2.setFont(decimalPriceNumberFont); p3_2.add(item.getPrice().substring(item.getPrice().length() - 2, item.getPrice().length())); Paragraph p3_3 = new Paragraph(); p3_3.setFont(decimalPriceNumberFont); p3_3.add(item.getCurrency()); PdfPTable table = new PdfPTable(2); if (item.getPrice().length() == 6) { table.setWidths(new float[] { 2.8f, 1 }); } else if (item.getPrice().length() == 5) { table.setWidths(new float[] { 1.8f, 1 }); } else { table.setWidths(new float[] { 1.5f, 1 }); } PdfPCell cell = new PdfPCell(p3); cell.setRowspan(2); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); if (s1 != 0 && s1 != 0 && s3 != 0) { cell.setLeading(42.0f, 0f); } else { cell.setLeading(55.0f, 0f); } cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(p3_2); cell.setRowspan(1); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(p3_3); cell.setRowspan(1); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); table.addCell(cell); return table; }
From source file:PDF.Reportes.java
public static ArrayList<PdfPTable> tablaAspAula(String usuario, String contra, String horario, int opc) throws DocumentException { ArrayList<PdfPTable> tablas = new ArrayList(); // IngresoAbd bd = new IngresoAbd(usuario, contra); List<Beans.Reportes> reportes = ReportesDAO.AspPAula(usuario, contra, horario, opc); PdfPTable table = new PdfPTable(2); // reportes = bd.AspPAula(horario, opc); PdfPCell cell;/*w w w . j av a 2s .c o m*/ String carrera = "", fecha = ""; if (reportes.isEmpty()) { cell = new PdfPCell( new Phrase("Lo sentimos, por el momento an no existe informacin para este reporte.")); cell.setColspan(5); table.addCell(cell); tablas.add(table); } else if (reportes.get(0).getCodError() != 0) { if (reportes.get(0).getCodError() == -1) { cell = new PdfPCell(new Phrase(Constants.ERROR1)); cell.setColspan(5); table.addCell(cell); } if (reportes.get(0).getCodError() == -2) { cell = new PdfPCell(new Phrase(Constants.ERROR3)); cell.setColspan(5); table.addCell(cell); } if (reportes.get(0).getCodError() == -3) { cell = new PdfPCell(new Phrase(Constants.ERROR2)); cell.setColspan(5); table.addCell(cell); } tablas.add(table); } else { table = new PdfPTable(5); BaseColor color = new BaseColor(217, 217, 217); BaseColor colorB = new BaseColor(0, 0, 0); cell = new PdfPCell(new Phrase("Ficha(5)", FontFactory.getFont("arial", 12, colorB))); cell.setMinimumHeight(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); cell = new PdfPCell(new Phrase("Folio Ceneval(6)", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); cell = new PdfPCell(new Phrase("Nombre(7)", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); // cell = new PdfPCell(new Phrase("Nombre carrera", FontFactory.getFont("arial", 12, colorB))); // cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setBackgroundColor(color); // cell.setBorderColor(colorB); // table.addCell(cell); cell = new PdfPCell(new Phrase("Asistencia(8)", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); cell.setColspan(2); table.addCell(cell); // cell = new PdfPCell(new Phrase("Firma", FontFactory.getFont("arial", 12, colorB))); // cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setBackgroundColor(color); // cell.setBorderColor(colorB); // table.addCell(cell); for (int i = 0; i < reportes.size(); i++) { cell = new PdfPCell(new Phrase(reportes.get(i).getFicha())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(reportes.get(i).getFolio())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(reportes.get(i).getNombre(), FontFactory.getFont("arial", 10))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); carrera = reportes.get(i).getNom_carrera(); // cell = new PdfPCell(new Phrase(reportes.get(i).getAsist())); table.addCell(cell); cell = new PdfPCell(new Phrase(reportes.get(i).getFirma())); table.addCell(cell); fecha = reportes.get(i).getFecha(); if ((i % 34 == 0 || (i + 1) == reportes.size()) && i != 0) { table.setWidthPercentage(110); table.setWidths(new int[] { 25, 30, 120, 15, 15 }); tablas.add(table); table = new PdfPTable(5); } } String datos[] = horario.split(" "); String edificio = datos[0]; String aula = ""; if (edificio.length() == 2) { edificio = datos[0].charAt(0) + ""; aula = datos[0].charAt(1) + ""; } if (edificio.length() == 4) { edificio = datos[0].charAt(0) + "" + datos[0].charAt(1); aula = "" + datos[0].charAt(3); } if (edificio.length() == 5) { edificio = datos[0].charAt(0) + "" + datos[0].charAt(1); aula = "" + datos[0].charAt(3) + datos[0].charAt(4); } PdfPTable tableH = new PdfPTable(7); tableH.setTotalWidth(500); cell.setMinimumHeight(20); cell = new PdfPCell(new Phrase("CARRERA:(1)", FontFactory.getFont("arial", 11))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); tableH.addCell(cell); cell = new PdfPCell(new Phrase(carrera)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(5); tableH.addCell(cell); cell = new PdfPCell(new Phrase("FECHA DE EXAMEN:(2)", FontFactory.getFont("arial", 11))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); tableH.addCell(cell); cell = new PdfPCell(new Phrase(fecha)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); cell = new PdfPCell(new Phrase("EDIFICIO:(3)", FontFactory.getFont("arial", 11))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); cell = new PdfPCell(new Phrase(edificio)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); cell = new PdfPCell(new Phrase("AULA:(4)", FontFactory.getFont("arial", 11))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); cell = new PdfPCell(new Phrase(aula)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); tablas.add(tableH); } return tablas; }
From source file:PDF.Reportes.java
public static ArrayList<PdfPTable> firmasAspAula(String usuario, String contra, String horario, int opc) throws DocumentException { ArrayList<PdfPTable> tablas = new ArrayList(); // IngresoAbd bd = new IngresoAbd(usuario, contra); List<Beans.Reportes> reportes; PdfPTable table = new PdfPTable(2); reportes = ReportesDAO.AspPAula(usuario, contra, horario, opc); // reportes = bd.AspPAula(horario, opc); String carrera = "", fecha = ""; if (reportes.isEmpty()) { PdfPCell cell;//from w w w . java 2 s . co m cell = new PdfPCell( new Phrase("Lo sentimos, por el momento an no existe informacin para este reporte.")); cell.setColspan(5); table.addCell(cell); tablas.add(table); } else if (reportes.get(0).getCodError() != 0) { PdfPCell cell; if (reportes.get(0).getCodError() == -1) { cell = new PdfPCell(new Phrase(Constants.ERROR1)); cell.setColspan(5); table.addCell(cell); } if (reportes.get(0).getCodError() == -2) { cell = new PdfPCell(new Phrase(Constants.ERROR3)); cell.setColspan(5); table.addCell(cell); } if (reportes.get(0).getCodError() == -3) { cell = new PdfPCell(new Phrase(Constants.ERROR2)); cell.setColspan(5); table.addCell(cell); } tablas.add(table); } else { PdfPCell cell; table = new PdfPTable(6); BaseColor color = new BaseColor(217, 217, 217); BaseColor colorB = new BaseColor(0, 0, 0); cell = new PdfPCell(new Phrase("Ficha(5)", FontFactory.getFont("arial", 12, colorB))); cell.setMinimumHeight(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); cell = new PdfPCell(new Phrase("Folio Ceneval(6)", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); cell = new PdfPCell(new Phrase("Nombre(7)", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); // cell = new PdfPCell(new Phrase("Nombre carrera", FontFactory.getFont("arial", 12, colorB))); // cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setBackgroundColor(color); // cell.setBorderColor(colorB); // table.addCell(cell); cell = new PdfPCell(new Phrase("Asistencia(8)", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); cell.setColspan(2); table.addCell(cell); cell = new PdfPCell(new Phrase("Firma(9)", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); for (int i = 0; i < reportes.size(); i++) { cell = new PdfPCell(new Phrase(reportes.get(i).getFicha())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(reportes.get(i).getFolio())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(reportes.get(i).getNombre(), FontFactory.getFont("arial", 10))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); carrera = reportes.get(i).getNom_carrera(); // cell = new PdfPCell(new Phrase(reportes.get(i).getAsist())); table.addCell(cell); cell = new PdfPCell(new Phrase(reportes.get(i).getFirma())); table.addCell(cell); table.addCell(cell); fecha = reportes.get(i).getFecha(); if ((i % 34 == 0 || (i + 1) == reportes.size()) && i != 0) { table.setWidthPercentage(110); table.setWidths(new int[] { 25, 30, 90, 15, 15, 30 }); tablas.add(table); table = new PdfPTable(6); } } String datos[] = horario.split(" "); String edificio = datos[0]; String aula = ""; if (edificio.length() == 2) { edificio = datos[0].charAt(0) + ""; aula = datos[0].charAt(1) + ""; } if (edificio.length() == 4) { edificio = datos[0].charAt(0) + "" + datos[0].charAt(1); aula = "" + datos[0].charAt(3); } if (edificio.length() == 5) { edificio = datos[0].charAt(0) + "" + datos[0].charAt(1); aula = "" + datos[0].charAt(3) + datos[0].charAt(4); } PdfPTable tableH = new PdfPTable(7); tableH.setTotalWidth(500); cell.setMinimumHeight(20); cell = new PdfPCell(new Phrase("CARRERA:(1)", FontFactory.getFont("arial", 11))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); tableH.addCell(cell); cell = new PdfPCell(new Phrase(carrera)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(5); tableH.addCell(cell); cell = new PdfPCell(new Phrase("FECHA DE EXAMEN:(2)", FontFactory.getFont("arial", 11))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); tableH.addCell(cell); cell = new PdfPCell(new Phrase(fecha)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); cell = new PdfPCell(new Phrase("EDIFICIO:(3)", FontFactory.getFont("arial", 11))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); cell = new PdfPCell(new Phrase(edificio)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); cell = new PdfPCell(new Phrase("AULA:(4)", FontFactory.getFont("arial", 11))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); cell = new PdfPCell(new Phrase(aula)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableH.addCell(cell); tablas.add(tableH); } return tablas; }
From source file:PdfCreation.PdfTableWriter.java
public Paragraph newParagraph(String text, boolean alignCenter, boolean alignLeft, boolean alignRight) { Paragraph ourParagraph = new Paragraph(); if (alignCenter && !alignLeft && !alignRight) { ourParagraph.setAlignment(Element.ALIGN_CENTER); } else if ((!alignCenter && !alignLeft && !alignRight) && (!alignCenter && alignLeft && !alignRight)) { ourParagraph.setAlignment(Element.ALIGN_LEFT); } else if (!alignCenter && !alignLeft && alignRight) { ourParagraph.setAlignment(Element.ALIGN_RIGHT); }/*w ww .ja v a 2s . c om*/ // ourParagraph.setFont(new Font(Font.FontFamily.COURIER, 11)); ourParagraph.add(text); return ourParagraph; }
From source file:pdfgen.pdf_generation_try5.java
public void AllFunctions(String realpath, String sample_pdf_path) { try {/*from w w w . j av a 2 s.c o m*/ INPUTFILE = sample_pdf_path; // System.out.println("Inputfile: "+INPUTFILE); Document document = new Document(); //PdfWriter.getInstance(document, new FileOutputStream(OUTPUTFILE)); OUTPUTFILE = filepath(realpath); //System.out.println("Outputfile"+OUTPUTFILE); PdfReader reader = new PdfReader(INPUTFILE); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUTPUTFILE)); // writer.setEncryption(USER_PASS.getBytes(), OWNER_PASS.getBytes(),PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128); document.open(); addTitlePage(document); int n = reader.getNumberOfPages(); PdfImportedPage page; // Go through all pages for (int i = 1; i <= n; i++) { page = writer.getImportedPage(reader, i); Image instance = Image.getInstance(page); instance.setAlignment(Element.ALIGN_LEFT); // document.add(instance); } addMetaData(document); pdfReaderFunction(reader); AddParagraph(document); // addContent(document); // scaleImage(); qr_generator(document); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:pdfGenerator.PdfGenerator.java
private PdfPTable createTable(ArrayList<ArrayList<String>> detailsTable) { PdfPTable table = new PdfPTable(detailsTable.get(0).size()); table.setWidthPercentage(100);// w ww . j a v a 2 s. com List<String> headers = detailsTable.remove(0); for (String header : headers) { table.addCell(header); } table.setHeaderRows(0); for (List<String> studentDetails : detailsTable) { for (String studentDetail : studentDetails) { PdfPCell cell = new PdfPCell(new Paragraph(studentDetail)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } } return table; }
From source file:pdfMaker.MakePdfFile.java
public void createPdf(String mainTitle, String subTitle, String url, String userName, //String scanType, String comment,/* w ww.j a va 2s . c o m*/ //String thisPassCode, String passCodeA, String passCodeB, String fileDir, Boolean noBarCodePrint) throws IOException, DocumentException, RuntimeException { Document document = null; try { // step 1 document = new Document(PageSize.A4, 60, 50, 50, 35); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileDir)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); /* Properties props = new Properties(); String jarPath = System.getProperty("java.class.path"); String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator)+1); FontFactory.registerDirectory("/res"); FontFactory.register("ipag.ttf"); Font ipaGothic = FontFactory.getFont("ipag", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); //10 is the size InputStream is = getClass().getResourceAsStream("/res/ipag.ttf"); */ Properties props = new Properties(); String jarPath = System.getProperty("java.class.path"); String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator) + 1); System.out.println(jarPath); System.out.println(dirPath); System.out.println(System.getProperty("user.dir")); Font ipaGothic = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 11); //?(2) PdfPTable pdfPTable = new PdfPTable(2); pdfPTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); pdfPTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.getDefaultCell().setFixedHeight(150); pdfPTable.setWidthPercentage(100f); int pdfPTableWidth[] = { 10, 90 }; pdfPTable.setWidths(pdfPTableWidth); PdfPCell cell_1_1 = new PdfPCell(new Paragraph("??", ipaGothic)); cell_1_1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_1_1.setHorizontalAlignment(Element.ALIGN_CENTER); cell_1_1.setFixedHeight(50); PdfPCell cell_1_2 = new PdfPCell(new Paragraph(mainTitle, ipaGothic)); cell_1_2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_1_2.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell_2_1 = new PdfPCell(new Paragraph("", ipaGothic)); cell_2_1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_2_1.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell_2_2 = new PdfPCell(new Paragraph(subTitle, ipaGothic)); cell_2_2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_2_2.setHorizontalAlignment(Element.ALIGN_CENTER); cell_2_2.setFixedHeight(50); pdfPTable.addCell(cell_1_1); pdfPTable.addCell(cell_1_2); pdfPTable.addCell(cell_2_1); pdfPTable.addCell(cell_2_2); PdfPCell cellUrlKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellUrlKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlKey.setRowspan(2); pdfPTable.addCell(cellUrlKey); PdfPCell cellUrlValue = new PdfPCell(new Paragraph(url, ipaGothic)); cellUrlValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValue.setFixedHeight(50); pdfPTable.addCell(cellUrlValue); /* */ //cellUrlValue.getImage(); writer.getDirectContent().addImage(cellUrlValue.getImage(), 100, 100, 100, 100, 100, 100); if (url.length() != 0 && !noBarCodePrint) { /* ? BarcodeQRCode qr = new BarcodeQRCode(url, 50, 50, null); PdfPCell cellUrlValueQr = new PdfPCell(qr.getImage()); cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValueQr.setFixedHeight(80); pdfPTable.addCell(cellUrlValueQr); */ Image image = ZxingUti.getQRCode(url); // SHIFT_JIS com.itextpdf.text.Image iTextImage = com.itextpdf.text.Image.getInstance(image, null); PdfPCell cell = new PdfPCell(iTextImage); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setFixedHeight(100); pdfPTable.addCell(cell); // SIFT_JIS } else { PdfPCell cellUrlValueQr = new PdfPCell(new Paragraph("", ipaGothic)); cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValueQr.setFixedHeight(80); pdfPTable.addCell(cellUrlValueQr); } PdfPCell cellUserNameKey = new PdfPCell(new Paragraph("", ipaGothic)); cellUserNameKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameKey.setRowspan(2); pdfPTable.addCell(cellUserNameKey); PdfPCell cellUserNameValue = new PdfPCell(new Paragraph(userName, ipaGothic)); cellUserNameValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValue.setFixedHeight(30); pdfPTable.addCell(cellUserNameValue); if (userName.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(userName); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellUserNameValueBc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValueBc.setFixedHeight(80); pdfPTable.addCell(cellUserNameValueBc); } else { PdfPCell cellUserNameValueBc = new PdfPCell(new Paragraph("---", ipaGothic)); cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValueBc.setFixedHeight(80); pdfPTable.addCell(cellUserNameValueBc); } PdfPCell cellPassCodeKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellPassCodeKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeKey.setRowspan(3); pdfPTable.addCell(cellPassCodeKey); PdfPCell cellPassCodeValue = new PdfPCell(new Paragraph(passCodeA + passCodeB, ipaGothic)); cellPassCodeValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeValue.setFixedHeight(30); pdfPTable.addCell(cellPassCodeValue); if (passCodeA.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(passCodeA); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellPassCodeA_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeA_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeA_Bc); } else { PdfPCell cellPassCodeA_Bc = new PdfPCell(new Paragraph("---", ipaGothic)); cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeA_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeA_Bc); } if (passCodeB.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(passCodeB); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellPassCodeB_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeB_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeB_Bc); } else { PdfPCell cellPassCodeB_Bc = new PdfPCell(new Paragraph("---", ipaGothic)); cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeB_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeB_Bc); } PdfPCell cellCommentKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellCommentKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellCommentKey.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cellCommentKey); PdfPCell cellCommentValue = new PdfPCell(new Paragraph(comment, ipaGothic)); cellCommentValue.setVerticalAlignment(Element.ALIGN_TOP); cellCommentValue.setHorizontalAlignment(Element.ALIGN_LEFT); cellCommentValue.setFixedHeight(150); pdfPTable.addCell(cellCommentValue); PdfPCell cellIssueKey = new PdfPCell(new Paragraph("", ipaGothic)); cellIssueKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellIssueKey.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cellIssueKey); Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm"); String strDate = sdf.format(cal.getTime()); PdfPCell cellIssueValue = new PdfPCell(new Paragraph(strDate, ipaGothic)); cellIssueValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellIssueValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellIssueValue.setFixedHeight(20); pdfPTable.addCell(cellIssueValue); //?? document.add(pdfPTable); /* // CODE 128 document.add(new Paragraph("?? : " + mainTitle, ipaGothic)); document.add(new Paragraph(" : " + subTitle, ipaGothic)); document.add(new Paragraph("-------------------------------------------------------")); document.add(new Paragraph(" " + strDate)); document.add(new Paragraph("-------------------------------------------------------")); BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.EMBEDDED); Font font = new Font(bf, 12); document.add(new Paragraph("", ipaGothic)); document.add(new Paragraph(url, ipaGothic)); code128.setCode(url); code128.setFont(bf); code128.setX(1); //document.add(code128.createImageWithBarcode(cb, null, null)); document.add(new Paragraph("USER", ipaGothic)); if (userName.length() != 0) { document.add(new Paragraph(userName, ipaGothic)); code128.setCode(userName); code128.setFont(bf); code128.setBarHeight(40f); document.add(code128.createImageWithBarcode(cb, null, null)); } document.add(new Paragraph("CODE", ipaGothic)); if (passCode.length() != 0) { document.add(new Paragraph(passCode, ipaGothic)); code128.setCode(passCode); code128.setFont(bf); document.add(code128.createImageWithBarcode(cb, null, null)); } document.add(new Paragraph("?", ipaGothic)); document.add(new Paragraph(comment, ipaGothic)); */ // step 5 document.close(); } catch (RuntimeException ex) { document.close(); throw ex; } }