List of usage examples for com.itextpdf.text.pdf PdfContentByte rectangle
public void rectangle(final double x, final double y, final double w, final double h)
From source file:ConexionBD.CreaPrefichaPDF.java
public ByteArrayOutputStream ElaboraPreficha(String curp, ServletContext d) throws IOException { System.out.println("Elaborando preficha...."); PrefichaModel prefichaR = VerificaDAO.recuperaPreficha(Constants.BD_NAME, Constants.BD_PASS, curp); Paragraph vacio = new Paragraph(" ", FontFactory.getFont("arial", 10, Font.BOLD)); vacio.setAlignment(Element.ALIGN_CENTER); Document preficha = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*from www . j a v a2 s .c o m*/ PdfWriter writer = PdfWriter.getInstance(preficha, baos); preficha.open(); Paragraph depto = new Paragraph("Departamento de servicios escolares", FontFactory.getFont("arial", 20, Font.BOLD)); depto.setAlignment(Element.ALIGN_CENTER); preficha.add(depto); PdfContentByte rectangulo_general = writer.getDirectContentUnder(); rectangulo_general.rectangle(50, 48, 500, 710); rectangulo_general.fill(); drawRectangleSC(rectangulo_general, 50, 48, 500, 710); if (prefichaR.getExiste() == 1) { preficha.add(vacio); preficha.add(vacio); Paragraph periodo_text = new Paragraph( "Convocatoria de nuevo ingreso periodo: " + prefichaR.getPeriodobd(), FontFactory.getFont("arial", 10, Font.BOLD)); periodo_text.setAlignment(Element.ALIGN_CENTER); preficha.add(periodo_text); preficha.add(vacio); preficha.add(vacio); Paragraph fotografia = new Paragraph("", FontFactory.getFont("arial", 10, Font.BOLD)); fotografia.setAlignment(Element.ALIGN_CENTER); preficha.add(fotografia); preficha.add(vacio); String url_logo = "/Imagenes/itt_logo_opt.jpg"; String absolute_url_logo = d.getRealPath(url_logo); Image itt_logo = Image.getInstance(absolute_url_logo); Image Logo_itt = Image.getInstance(itt_logo); Logo_itt.setAbsolutePosition(260f, 640f); preficha.add(Logo_itt); PdfContentByte rectangulo_periodo = writer.getDirectContentUnder(); rectangulo_periodo.rectangle(125, 725, 350, 20); rectangulo_periodo.fill(); drawRectangleSC(rectangulo_periodo, 125, 725, 350, 20); String url_logo_bnmx = "/Imagenes/bnmx_color_opt.jpg"; String absolute_url_logo_bnmx = d.getRealPath(url_logo_bnmx); Image bnmx_logo = Image.getInstance(absolute_url_logo_bnmx); Image Logo_banco = Image.getInstance(bnmx_logo); Logo_banco.setAbsolutePosition(380f, 310f); preficha.add(Logo_banco); preficha.add(vacio); PdfContentByte fechaimpr = writer.getDirectContentUnder(); fechaimpr.rectangle(416, 635, 100, 35); fechaimpr.fill(); drawRectangleSC(fechaimpr, 416, 635, 100, 35); Paragraph fechapdf_impr = new Paragraph("\tFecha de impresin ", FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD)); fechapdf_impr.setAlignment(Element.ALIGN_RIGHT); preficha.add(fechapdf_impr); Paragraph fechapdf_fec = new Paragraph( "\t" + prefichaR.getFechapdf() + " ", FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD)); fechapdf_fec.setAlignment(Element.ALIGN_RIGHT); preficha.add(fechapdf_fec); preficha.add(vacio); Paragraph no_preficha = new Paragraph("Preficha N: " + prefichaR.getPrefichabd(), FontFactory.getFont("arial", 20, Font.BOLD)); no_preficha.setAlignment(Element.ALIGN_CENTER); preficha.add(no_preficha); preficha.add(vacio); PdfContentByte rectangulo_preficha_no = writer.getDirectContentUnder(); rectangulo_preficha_no.rectangle(85, 590, 430, 25); rectangulo_preficha_no.fill(); drawRectangleSC(rectangulo_preficha_no, 85, 590, 430, 25); PdfContentByte rectangulo_datos = writer.getDirectContentUnder(); rectangulo_datos.rectangle(85, 480, 430, 105); rectangulo_datos.fill(); drawRectangleSC(rectangulo_datos, 85, 480, 430, 105); Paragraph nombre = new Paragraph( " Nombre: " + prefichaR.getNombrebd(), FontFactory.getFont("arial", 10, Font.BOLD)); nombre.setAlignment(Element.ALIGN_LEFT); preficha.add(nombre); Paragraph apellidos = new Paragraph( " " + prefichaR.getApellidosbd(), FontFactory.getFont("arial", 10, Font.BOLD)); apellidos.setAlignment(Element.ALIGN_LEFT); preficha.add(apellidos); Paragraph CURP = new Paragraph( " CURP: " + prefichaR.getCurpbd(), FontFactory.getFont("arial", 10, Font.BOLD)); CURP.setAlignment(Element.ALIGN_LEFT); preficha.add(CURP); Paragraph carrera = new Paragraph("Carrera Solicitada:", FontFactory.getFont("arial", 10, Font.BOLD)); carrera.setAlignment(Element.ALIGN_CENTER); preficha.add(carrera); Paragraph Nomcarrera = new Paragraph(prefichaR.getCarrerabd(), FontFactory.getFont("arial", 10, Font.BOLD)); Nomcarrera.setAlignment(Element.ALIGN_CENTER); preficha.add(Nomcarrera); Paragraph modalidad = new Paragraph( " Modalidad: " + prefichaR.getModalidadbd(), FontFactory.getFont("arial", 10, Font.BOLD)); modalidad.setAlignment(Element.ALIGN_LEFT); preficha.add(modalidad); preficha.add(vacio); // preficha.add(vacio); Paragraph formatoBanamex = new Paragraph( "\nFORMATO UNIVERSAL PARA DEPSITOS EN SUCURSALES BANAMEX", FontFactory.getFont("arial", 10, Font.BOLD)); formatoBanamex.setAlignment(Element.ALIGN_CENTER); preficha.add(formatoBanamex); PdfContentByte rectanguloDepositoB = writer.getDirectContentUnder(); rectanguloDepositoB.rectangle(85, 440, 430, 20); rectanguloDepositoB.fill(); drawRectangle(rectanguloDepositoB, 85, 440, 430, 20); PdfContentByte rectanguloPago = writer.getDirectContentUnder(); rectanguloPago.rectangle(85, 250, 430, 190); rectanguloPago.fill(); drawRectangleSC(rectanguloPago, 85, 250, 430, 190); preficha.add(vacio); PdfContentByte rectanguloConcepto = writer.getDirectContentUnder(); rectanguloConcepto.rectangle(150, 395, 295, 35); rectanguloConcepto.fill(); drawRectangleSC(rectanguloConcepto, 150, 395, 295, 35); Paragraph formatoConceptoPre = new Paragraph("CONCEPTO: PAGO DE DERECHO A EXAMEN DE ADMISIN", FontFactory.getFont("arial", 10, Font.BOLD)); formatoConceptoPre.setAlignment(Element.ALIGN_CENTER); preficha.add(formatoConceptoPre); Paragraph fechaEmision = new Paragraph("FECHA L?MITE DE PAGO: " + prefichaR.getFecha_limite_pago(), FontFactory.getFont("arial", 10, Font.BOLD)); fechaEmision.setAlignment(Element.ALIGN_CENTER); preficha.add(fechaEmision); preficha.add(vacio); preficha.add(vacio); Paragraph importe = new Paragraph("IMPORTE A PAGAR: $" + prefichaR.getImporte_bd() + ".", FontFactory.getFont("arial", 15, Font.BOLD)); importe.setAlignment(Element.ALIGN_CENTER); preficha.add(importe); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); String ref = prefichaR.getRef_bancaria(); Paragraph referencia = new Paragraph( " REFERENCIA (B): " + ref, FontFactory.getFont("arial", 10, Font.BOLD)); referencia.setAlignment(Element.ALIGN_LEFT); preficha.add(referencia); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); Paragraph atencion = new Paragraph("Atencin", FontFactory.getFont("arial", 15, Font.BOLD)); atencion.setAlignment(Element.ALIGN_CENTER); preficha.add(atencion); PdfContentByte rectangulo_atencion = writer.getDirectContentUnder(); rectangulo_atencion.rectangle(245, 198, 100, 25); rectangulo_atencion.fill(); drawRectangle(rectangulo_atencion, 245, 198, 100, 25); PdfContentByte rectangulo_info = writer.getDirectContentUnder(); rectangulo_info.rectangle(85, 60, 430, 100); rectangulo_info.fill(); drawRectangle(rectangulo_info, 85, 60, 430, 120); preficha.add(vacio); preficha.add(vacio); Paragraph informacion = new Paragraph( " Para continuar con el proceso de preinscripcin deber:\n" + " - Realizar el pago para su examen de admisin con la \"REFERENCIA\" que aparece\n" + " en este documento en cualquier sucursal BANAMEX.\n" + " - Recibir la notificacin en su correo electrnico y estar al pendiente de \n" + " las notificaciones que sern enviadas al mismo de que el pago ya fue procesado \n" + " para completar su proceso de preinscripcin.\n", FontFactory.getFont("arial", 10, Font.BOLD)); informacion.setAlignment(Element.ALIGN_LEFT); preficha.add(informacion); preficha.addTitle("Preficha"); preficha.addSubject("Instituto Tecnolgico de Toluca"); preficha.addKeywords("Instituto Tecnolgico de Toluca"); preficha.addAuthor("Departamento de Servicios escolares"); preficha.addCreator("Departamento de Servicios escolares"); } else { preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); Paragraph curpNoEncontrada = new Paragraph( " Lo sentimos, no se encontraron " + " coincidencias con su clave CURP.", FontFactory.getFont("arial", 14, Font.BOLD)); curpNoEncontrada.setAlignment(Element.ALIGN_LEFT); preficha.add(curpNoEncontrada); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); Paragraph curp_no = new Paragraph(curp, FontFactory.getFont("arial", 19, Font.PLAIN)); curp_no.setAlignment(Element.ALIGN_CENTER); preficha.add(curp_no); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); Paragraph lamenta = new Paragraph("" + "El deparamento de servicios escolares lamenta los inconvenientes ocurridos al intentar recuperar su preficha." + "", FontFactory.getFont("arial", 19, Font.BOLD)); lamenta.setAlignment(Element.ALIGN_CENTER); preficha.add(lamenta); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); Paragraph se_le_aconseja = new Paragraph(" RECOMENDACIONES", FontFactory.getFont("arial", 14, Font.BOLD)); se_le_aconseja.setAlignment(Element.ALIGN_LEFT); preficha.add(se_le_aconseja); Paragraph msjCurp = new Paragraph("\n" + " - Le aconsejamos revisar su CURP, ya que sin esta, no podr recuperar su preficha.\n" + " - Si el problema contina, acuda con esta hoja al departamento de SERVICIOS ESCOLARES (Edif.\n" + " X) de lunes a viernes de 9:00 a 18:00 horas, de lo contrario \n" + " haga su registro.\n" + " - Revise que en el proceso de registro cada paso se haya terminado correctamente\n" + " - Revise el manual de proceso de registro que se encuentra en la pgina www.ittoluca.edu.mx\n" + " - Revise el apartado de preguntas frecuentes que se encuentra en la pgina www.ittoluca.edu.mx\n" + " - En la seccin de contacto, se encuentran el telfono de contacto y la extensin.\n" + " - Otra alternativa es enviar un correo exponiendo su situacin al departamento de servicios \n" + " escolares." + "\n" + "" + "", FontFactory.getFont("arial", 10, Font.BOLD)); msjCurp.setAlignment(Element.ALIGN_LEFT); preficha.add(msjCurp); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); Paragraph no_comprobante = new Paragraph("" + "Este documento carece de validz oficial, su funcin es servir como medio de comunicacin.", FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.RED)); no_comprobante.setAlignment(Element.ALIGN_CENTER); preficha.add(no_comprobante); // preficha.add(vacio); String url_logo = "/Imagenes/itt_logo_opt.jpg"; String absolute_url_logo = d.getRealPath(url_logo); Image itt_logo = Image.getInstance(absolute_url_logo); Image Logo_itt = Image.getInstance(itt_logo); Logo_itt.setAbsolutePosition(140f, 640f); preficha.add(Logo_itt); } preficha.close(); return baos; } catch (DocumentException docE) { throw new IOException(docE.getMessage()); } }
From source file:ConexionBD.CreaPrefichaPDF.java
public static void drawRectangle(PdfContentByte content, float x, float y, float width, float height) { content.saveState();/*from w w w .j a v a 2s.co m*/ PdfGState state = new PdfGState(); content.setGState(state); content.setRGBColorFill(232, 232, 232); content.setColorStroke(BaseColor.BLUE); content.setLineWidth((float) .5); content.rectangle(x, y, width, height); content.fillStroke(); content.restoreState(); }
From source file:ConexionBD.CreaPrefichaPDF.java
public static void drawRectangleSC(PdfContentByte content, float x, float y, float width, float height) { content.saveState();/* w w w. j ava 2 s .com*/ PdfGState state = new PdfGState(); content.setGState(state); content.setRGBColorFill(0xFF, 0xFF, 0xFA); content.setColorStroke(BaseColor.BLUE); content.setLineWidth((float) .5); content.rectangle(x, y, width, height); content.fillStroke(); content.restoreState(); }
From source file:ConexionBD.CreaPrefichaPDF.java
public static void drawRectangleText(PdfContentByte content, float x, float y, float width, float height) { content.saveState();/* ww w .ja v a2 s. c o m*/ PdfGState state = new PdfGState(); content.setGState(state); content.setRGBColorFill(0, 230, 255); content.setColorStroke(BaseColor.BLUE); content.setLineWidth((float) .5); content.rectangle(x, y, width, height); content.fillStroke(); content.restoreState(); }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
/** * Prints a square and fills half of it with a gray rectangle. * @param x//from w w w . j a v a2 s.c o m * @param y * @param cb * @throws Exception */ public void pictureBackdrop(float x, float y, PdfContentByte cb) throws Exception { cb.setColorStroke(new BaseColor(Color.black)); cb.setColorFill(new BaseColor(Color.gray)); cb.rectangle(x, y, 100, 200); cb.fill(); cb.setLineWidth(2); cb.rectangle(x, y, 200, 200); cb.stroke(); }
From source file:frames.main.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { try {// ww w.j a va 2s. c o m BaseFont unicode = BaseFont.createFont("c:/windows/fonts/ALGER.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font1003 = new Font(unicode, 18, Font.ITALIC, new BaseColor(139, 0, 0)); Font font1008 = new Font(unicode, 20, Font.BOLD, new BaseColor(101, 67, 33)); Font font1004 = new Font(unicode, 18, Font.BOLD, new BaseColor(139, 0, 0)); Font font1009 = new Font(unicode, 10, Font.NORMAL, new BaseColor(139, 10, 20)); Font font1005 = new Font(unicode, 18, Font.UNDERLINE, new BaseColor(101, 67, 33)); Font font1006 = new Font(unicode, 9, Font.BOLDITALIC, new BaseColor(101, 67, 33)); // Rectangle rect=new RectangleReadOnly(590, 470, 0); ///////////////////////////////////// Font font100 = new Font(unicode, 10, Font.ITALIC, BaseColor.BLUE); Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("REGISTRATION-FORM.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); Font font111 = new Font(Font.FontFamily.COURIER, 16, Font.BOLD, BaseColor.ORANGE); Font font110 = new Font(Font.FontFamily.COURIER, 14, Font.NORMAL, BaseColor.GREEN); Font font11 = new Font(Font.FontFamily.COURIER, 12, Font.NORMAL, BaseColor.GREEN); com.itextpdf.text.Image image2 = com.itextpdf.text.Image .getInstance("C:\\smart kid\\src\\frames\\logo.jpg"); image2.scaleAbsolute(115f, 115f); image2.setAbsolutePosition(3, 716); Paragraph p = new Paragraph(); document.add(image2); document.add(new Chunk(" ", font1004)); document.add(new Chunk("ADMISSION FORM", font1005)); document.add(new Paragraph(" SMART KIDS CONVENT SCHOOL", font1004)); document.add(new Paragraph( " Managed By:The Smart Kids Educational Society,")); document.add(new Paragraph( " Reg.No:-00169")); document.add(new Paragraph( " 413A/23,HEERA NAGAR,GURGAON")); document.add(new Paragraph( " MOB:-9911752900 , 9891929835")); document.add(new Paragraph( " Reg.No" + " " + Rtf8.getText())); document.add(new Paragraph( "Admission No." + " " + new Date().toString())); document.add(new Paragraph(" ")); Paragraph p1 = new Paragraph(); p1.add(new Chunk("Certified that " + "Son/Daughter of:", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); p1.add(new Chunk(Rtf1.getText(), font11)); document.add(p1); document.add(new Paragraph(" ")); Paragraph p2 = new Paragraph(); p2.add(new Chunk("Father's Name :" + Rtf2.getText() + "Mob:-", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); p2.add(new Chunk(Rtf2.getText(), font11)); document.add(p2); document.add(new Paragraph(" ")); Paragraph p3 = new Paragraph(); p3.add(new Chunk("Mother's Name :" + Rtf2.getText() + "Mob:-", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); p3.add(new Chunk(Rtf2.getText(), font11)); document.add(p3); document.add(new Paragraph(" ")); Paragraph p4 = new Paragraph(); p4.add(new Chunk("His/Her Date of birth :" + Rtf2.getText() + "Age", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); p4.add(new Chunk(Rtf2.getText(), font11)); document.add(p4); document.add(new Paragraph(" ")); Paragraph p5 = new Paragraph(); p5.add(new Chunk("Corrosponding Address :", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); p5.add(new Chunk("", font11)); document.add(p5); document.add(new Paragraph(" ")); Paragraph p6 = new Paragraph(); p6.add(new Chunk("Parmanent Address :", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); p6.add(new Chunk("", font11)); document.add(p6); document.add(new Paragraph(" ")); Paragraph p7 = new Paragraph(); p7.add(new Chunk("Previous School & result :", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); p7.add(new Chunk("He/She Wants Admmisiion in", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); document.add(p7); document.add(new Paragraph(" ")); Paragraph p8 = new Paragraph(); p8.add(new Chunk("Smart Kids Convent School in :", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); p8.add(new Chunk("Class.He/She will always be regular and punctual to school.", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); document.add(p8); document.add(new Paragraph(" ")); Paragraph p9 = new Paragraph(); p9.add(new Chunk("Please admit him/her :" + "Signature", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); p9.add(new Chunk( " in" + "Class" + "Parents/Guardian", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); document.add(p9); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph( " Principal(Signature) Permission of Director", FontFactory.getFont(FontFactory.COURIER, 11, Font.ITALIC, BaseColor.BLACK))); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph("NOTE:- FEES WILL NOT BE REFUNDED AFTER ADMISSION.")); cb.saveState(); cb.setColorStroke(BaseColor.BLACK); cb.rectangle(2, 2, 588, 826); cb.stroke(); cb.restoreState(); JOptionPane.showMessageDialog(this, "receipt printed.."); document.close(); ; } catch (Exception ee) { JOptionPane.showMessageDialog(this, ee); } }
From source file:frames.main.java
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) { try {//from w w w.j a va 2s. c o m BaseFont unicode = BaseFont.createFont("c:/windows/fonts/ALGER.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // Font font11113 = new Font(unicode, 16, Font.BOLD,BaseColor(2,2,2)); ///////////////////////////////////////////////dark brown////////////////////////////////////////////////////// Font font1003 = new Font(unicode, 16, Font.BOLD, new BaseColor(101, 67, 33)); Font font1008 = new Font(unicode, 20, Font.BOLD, new BaseColor(101, 67, 33)); ///////////////////////////////////// ///////////////////////////////////////////////dark red////////////////////////////////////////////////////// Font font1004 = new Font(unicode, 14, Font.BOLD, new BaseColor(139, 0, 0)); Font font1005 = new Font(unicode, 14, Font.BOLD, new BaseColor(255, 0, 0)); ///////////////////////////////////// Font font100 = new Font(unicode, 8, Font.ITALIC, BaseColor.BLUE); Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SMART-TC.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); Font font111 = new Font(Font.FontFamily.COURIER, 16, Font.BOLD, BaseColor.ORANGE); com.itextpdf.text.Image image2 = com.itextpdf.text.Image .getInstance("C:\\smart kid\\src\\frames\\logo.jpg"); image2.scaleAbsolute(125f, 125f); image2.setAbsolutePosition(31, 700); document.add(image2); com.itextpdf.text.Image ing = com.itextpdf.text.Image.getInstance("C:\\smart kid\\src\\frames\\BC.jpg"); ing.setAbsolutePosition(1, 200); document.add(ing); Font font1111 = new Font(unicode, 16, Font.BOLD, BaseColor.ORANGE); Font font11111 = new Font(unicode, 14, Font.BOLD, BaseColor.ORANGE); java.awt.Font awtPlainFont = new java.awt.Font("ALGERIAN", java.awt.Font.PLAIN, 10); document.add(new Paragraph(" SMART KIDS CONVENT SCHOOL", font1008)); document.add(new Paragraph( " HEERA NAGAR (GURGAON) ", font1003)); document.add( new Chunk(" SCHOLOR'S REGISTER AND TRANSFER CERTIFICATE", font1005)); document.add(new Paragraph(" ")); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(" ", font111)); Font font41 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD, new BaseColor(0, 0, 0)); Font font23 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD, new BaseColor(92, 64, 51)); Font font1 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD, new BaseColor(0, 0, 0)); Font font11 = new Font(Font.FontFamily.HELVETICA, 12, Font.ITALIC, new BaseColor(148, 0, 211)); Font font31 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD, new BaseColor(990000)); Font font2 = new Font(Font.FontFamily.COURIER, 18, Font.ITALIC | Font.UNDERLINE); Font font3 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD, new BaseColor(255, 255, 200)); document.add(new Paragraph( "Ref No: " + TC16.getText() + " " + new java.util.Date().toString(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); document.add(new Paragraph(" ")); String ho4 = TC1.getText(); Paragraph p1 = new Paragraph(); p1.add(new Chunk("NAME OF STUDENT :", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); p1.add(new Chunk(ho4, font11)); document.add(p1); String ho5 = TC2.getText(); Paragraph p2 = new Paragraph(); p2.add(new Chunk("FATHER'S NAME :", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); p2.add(new Chunk(ho5, font11)); document.add(p2); String ho6 = TC3.getText(); Paragraph p93 = new Paragraph(); p93.add(new Chunk("MOTHER'S NAME :", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); p93.add(new Chunk(ho6, font11)); document.add(p93); Font font15 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD, new BaseColor(0, 0, 0)); String ho8 = TC1.getText(); String tt = TC4.getText(); Paragraph p4 = new Paragraph(); p4.add(new Chunk("RELIGION :", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); p4.add(new Chunk(tt, font11)); document.add(p4); // document.add(new Paragraph(" ",font1003)); String kk = TC5.getText(); Paragraph p5 = new Paragraph(); p5.add(new Chunk("CASTE OF SCHOLOR :", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); p5.add(new Chunk(kk, font11)); document.add(p5); String ho10 = TC10.getText(); Paragraph p6 = new Paragraph(); p6.add(new Chunk("ADDRESS :", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); p6.add(new Chunk(ho10, font11)); document.add(p6); Paragraph p8 = new Paragraph(); p8.add(new Chunk("DATE OF BIRTH :", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); p8.add(new Chunk(TC9.getText(), font11)); document.add(p8); Paragraph p9 = new Paragraph(); p9.add(new Chunk("SECTION :", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); p9.add(new Chunk(TC7.getText(), font11)); document.add(p9); Paragraph p10 = new Paragraph(); p10.add(new Chunk("REGISTRATION NO: :", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLACK))); p10.add(new Chunk(TC8.getText(), font11)); document.add(p10); document.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(8); String vacume = ""; table.addCell("Class"); table.addCell("Date of Admission"); table.addCell("Date of Promotion"); table.addCell("Date of Removal"); table.addCell("Cause of Removal"); table.addCell("Year"); table.addCell("Conduct and Work"); table.addCell("Sign"); PdfPCell cell10 = new PdfPCell(new Paragraph("NURSERY", font100)); table.addCell(cell10); if (TC6.getSelectedIndex() == 0) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell111 = new PdfPCell(new Paragraph("LKG", font100)); table.addCell(cell111); if (TC6.getSelectedIndex() == 1) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell1 = new PdfPCell(new Paragraph("UKG", font100)); table.addCell(cell1); if (TC6.getSelectedIndex() == 2) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell2 = new PdfPCell(new Paragraph("STD-1", font100)); table.addCell(cell2); if (TC6.getSelectedIndex() == 3) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell3 = new PdfPCell(new Paragraph("STD-2", font100)); table.addCell(cell3); if (TC6.getSelectedIndex() == 4) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell4 = new PdfPCell(new Paragraph("STD-3", font100)); table.addCell(cell4); if (TC6.getSelectedIndex() == 5) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell5 = new PdfPCell(new Paragraph("STD-4", font100)); table.addCell(cell5); if (TC6.getSelectedIndex() == 6) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell6 = new PdfPCell(new Paragraph("STD-5", font100)); table.addCell(cell6); if (TC6.getSelectedIndex() == 7) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell8 = new PdfPCell(new Paragraph("STD-6", font100)); table.addCell(cell8); if (TC6.getSelectedIndex() == 8) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell9 = new PdfPCell(new Paragraph("STD-7", font100)); table.addCell(cell9); if (TC6.getSelectedIndex() == 9) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } PdfPCell cell18 = new PdfPCell(new Paragraph("STD-8", font100)); table.addCell(cell18); if (TC6.getSelectedIndex() == 2) { PdfPCell cell11 = new PdfPCell(new Paragraph(TC11.getText(), font100)); PdfPCell cell12 = new PdfPCell( new Paragraph(((JTextField) TC12.getDateEditor().getUiComponent()).getText(), font100)); PdfPCell cell13 = new PdfPCell( new Paragraph(((JTextField) TC13.getDateEditor().getUiComponent()).getText(), font100)); ; PdfPCell cell14 = new PdfPCell(new Paragraph(TC14.getText(), font100)); PdfPCell cell15 = new PdfPCell(new Paragraph((String) TC15.getSelectedItem(), font100)); PdfPCell cell16 = new PdfPCell(new Paragraph(TC17.getText(), font100)); table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); table.addCell(cell14); table.addCell(cell15); table.addCell(cell16); table.addCell(""); } else { for (int i = 0; i < 7; i++) table.addCell(vacume); } float[] ColumnWidths = new float[] { 8f, 12f, 12f, 12f, 22f, 8f, 15f, 7f }; table.setWidths(ColumnWidths); table.setWidthPercentage(106); table.setHorizontalAlignment(Element.ALIGN_LEFT); document.add(table); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph( "1. I certified that the entries as regard details of the student have been duly checked from the 'Admission form' and that they are complete.", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL, BaseColor.BLACK))); // document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph( "2. Certified that the above Students register have been posted up-to date of students leaving as required by the departmental rules.", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL, BaseColor.BLACK))); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph( "Prepared by:-" + " " + "Date:-" + " " + new java.util.Date().toString() + " " + "Principal's Sign:-", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.NORMAL, BaseColor.BLACK))); document.add(new Paragraph(" ")); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph("An ISO 9001:2008 Certified School(Certificate Number:NOR/0712M/1505)", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLUE))); document.add(new Paragraph("(Run By:Smart Educational Society)Regd.No.(DR/GGN/285)", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, BaseColor.BLUE))); document.add(new Paragraph( "413A/23,Gali No:-2,Heera Nagar,Near Rajendra Hospital,Khandsa Road,Gurgaon(Haryana)", FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLUE))); cb.saveState(); cb.setColorStroke(BaseColor.BLACK); cb.rectangle(2, 2, 588, 828); cb.stroke(); cb.restoreState(); JOptionPane.showMessageDialog(this, "it is saved"); document.close(); } catch (Exception ee) { JOptionPane.showMessageDialog(this, ee); } // TODO add your handling code here: }
From source file:mkl.testarea.itext5.pdfcleanup.StrictPdfCleanUpProcessor.java
License:Open Source License
private void insertFormXObj(PdfContentByte canvas, PdfDictionary pageDict, PdfStream formXObj, List<Rectangle> clippingRects, Rectangle annotRect) throws IOException { PdfName xobjName = generateNameForXObj(pageDict); canvas.saveState();/*from w w w .java 2 s .c om*/ for (Rectangle rect : clippingRects) { canvas.rectangle(rect.getLeft(), rect.getBottom(), rect.getWidth(), rect.getHeight()); } canvas.clip(); canvas.newPath(); canvas.addFormXObj(formXObj, xobjName, 1, 0, 0, 1, annotRect.getLeft(), annotRect.getBottom()); canvas.restoreState(); }
From source file:nz.ac.waikato.cms.doc.SimplePDFOverlay.java
License:Open Source License
/** * Applies the instructions to the input PDF. * * @return null if successful, otherwise error message *///from ww w. j a v a 2 s. c o m public String execute() { String result; String line; BufferedReader breader; FileReader freader; int i; int lineNo; String units; int pageNo; PdfReader reader; PdfStamper stamper; PdfContentByte cb; ColumnText ct; Font font; String[] parts; StringBuilder text; result = null; freader = null; breader = null; try { reader = new PdfReader(new FileInputStream(m_Pdf.getAbsolutePath())); stamper = new PdfStamper(reader, new FileOutputStream(m_Output.getAbsolutePath())); freader = new FileReader(m_Instructions); breader = new BufferedReader(freader); lineNo = 0; units = "pt"; pageNo = 1; cb = stamper.getOverContent(pageNo); font = null; while ((line = breader.readLine()) != null) { lineNo++; if (line.trim().startsWith(PREFIX_COMMENT)) continue; if (line.trim().length() == 0) continue; if (line.startsWith(PREFIX_UNITS)) { units = line.substring(PREFIX_UNITS.length()).trim().toLowerCase(); } else if (line.startsWith(PREFIX_PAGE)) { pageNo = Integer.parseInt(line.substring(PREFIX_PAGE.length()).trim()); cb = stamper.getOverContent(pageNo); } else if (line.startsWith(PREFIX_FONT)) { parts = line.substring(PREFIX_FONT.length()).trim().split(" "); if (parts.length == 3) font = FontFactory.getFont(parts[0], Float.parseFloat(parts[1]), new BaseColor(parseColor(parts[2]).getRGB())); else m_Logger.warning("Font instruction not in expected format (" + FORMAT_FONT + "):\n" + line); } else if (line.startsWith(PREFIX_TEXT)) { parts = line.substring(PREFIX_TEXT.length()).trim().split(" "); if (parts.length >= 7) { ct = new ColumnText(cb); ct.setSimpleColumn(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // llx parseLocation(parts[1], reader.getPageSize(pageNo).getHeight(), units), // lly parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // urx parseLocation(parts[3], reader.getPageSize(pageNo).getHeight(), units), // ury Float.parseFloat(parts[4]), // leading parseAlignment(parts[5])); // alignment text = new StringBuilder(); for (i = 6; i < parts.length; i++) { if (text.length() > 0) text.append(" "); text.append(parts[i]); } if (font == null) ct.setText(new Phrase(text.toString())); else ct.setText(new Phrase(text.toString(), font)); ct.go(); } else { m_Logger.warning("Text instruction not in expected format (" + FORMAT_TEXT + "):\n" + line); } } else if (line.startsWith(PREFIX_LINE)) { parts = line.substring(PREFIX_LINE.length()).trim().split(" "); if (parts.length >= 6) { cb.saveState(); cb.setLineWidth(Float.parseFloat(parts[4])); // line width cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // color cb.moveTo(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units)); // y cb.lineTo(parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // w parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units)); // h cb.stroke(); cb.restoreState(); } else { m_Logger.warning("Line instruction not in expected format (" + FORMAT_LINE + "):\n" + line); } } else if (line.startsWith(PREFIX_RECT)) { parts = line.substring(PREFIX_RECT.length()).trim().split(" "); if (parts.length >= 6) { cb.saveState(); cb.rectangle(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units), // y parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // w parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units) // h ); cb.setLineWidth(Float.parseFloat(parts[4])); // line width cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // stroke if (parts.length >= 7) { cb.setColorFill(new BaseColor(parseColor(parts[6]).getRGB())); // fill cb.fillStroke(); } else { cb.stroke(); } cb.restoreState(); } else { m_Logger.warning( "Rectangle instruction not in expected format (" + FORMAT_RECT + "):\n" + line); } } else if (line.startsWith(PREFIX_OVAL)) { parts = line.substring(PREFIX_OVAL.length()).trim().split(" "); if (parts.length >= 6) { cb.saveState(); cb.ellipse(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x1 parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units), // y1 parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // x2 parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units) // y2 ); cb.setLineWidth(Float.parseFloat(parts[4])); // line width cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // stroke if (parts.length >= 7) { cb.setColorFill(new BaseColor(parseColor(parts[6]).getRGB())); // fill cb.fillStroke(); } else { cb.stroke(); } cb.restoreState(); } else { m_Logger.warning("Oval instruction not in expected format (" + FORMAT_OVAL + "):\n" + line); } } else { m_Logger.warning("Unknown command on line #" + lineNo + ":\n" + line); } } stamper.close(); } catch (Exception e) { result = "Failed to process!\n" + Utils.throwableToString(e); } finally { FileUtils.closeQuietly(breader); FileUtils.closeQuietly(freader); } return result; }
From source file:org.gephi.preview.plugin.renderers.NodeLabelRenderer.java
License:Open Source License
public void renderPDF(PDFTarget target, Node node, String label, float x, float y, int fontSize, Color color, float outlineSize, Color outlineColor, boolean showBox, Color boxColor) { Font font = fontCache.get(fontSize); PdfContentByte cb = target.getContentByte(); BaseFont bf = target.getBaseFont(font); //Box//w w w .j a va2 s . c om if (showBox) { cb.setRGBColorFill(boxColor.getRed(), boxColor.getGreen(), boxColor.getBlue()); if (boxColor.getAlpha() < 255) { cb.saveState(); float alpha = boxColor.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setFillOpacity(alpha); cb.setGState(gState); } float textWidth = getTextWidth(bf, fontSize, label); float textHeight = getTextHeight(bf, fontSize, label); //A height of just textHeight seems to be half the text height sometimes //BaseFont getAscentPoint and getDescentPoint may be not very precise cb.rectangle(x - textWidth / 2f - outlineSize / 2f, -y - outlineSize / 2f - textHeight, textWidth + outlineSize, textHeight * 2f + outlineSize); cb.fill(); if (boxColor.getAlpha() < 255) { cb.restoreState(); } } cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue()); float textHeight = getTextHeight(bf, fontSize, label); if (outlineSize > 0) { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE); cb.setRGBColorStroke(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue()); cb.setLineWidth(outlineSize); cb.setLineJoin(PdfContentByte.LINE_JOIN_ROUND); cb.setLineCap(PdfContentByte.LINE_CAP_ROUND); if (outlineColor.getAlpha() < 255) { cb.saveState(); float alpha = outlineColor.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setStrokeOpacity(alpha); cb.setGState(gState); } cb.beginText(); cb.setFontAndSize(bf, font.getSize()); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f); cb.endText(); if (outlineColor.getAlpha() < 255) { cb.restoreState(); } } cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); cb.beginText(); cb.setFontAndSize(bf, font.getSize()); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f); cb.endText(); }