List of usage examples for com.itextpdf.text.pdf PdfContentByte rectangle
public void rectangle(final Rectangle rectangle)
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawRectangle(PdfContentByte cb, Rectangle rect, float lineWidth, float grayStroke) { setLineWidthGrayStroke(cb, lineWidth, grayStroke); cb.rectangle(rect); cb.stroke();/*from w w w.j a v a2 s . c o m*/ }
From source file:com.softwaremagico.tm.pdf.complete.elements.TableBorderEvent.java
License:Open Source License
@Override public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvas) {//ww w . ja v a 2 s . c om float width[] = widths[0]; float x1 = width[0]; float x2 = width[width.length - 1]; float y1 = heights[0]; float y2 = heights[heights.length - 1]; PdfContentByte cb = canvas[PdfPTable.LINECANVAS]; Rectangle rect1 = new Rectangle(x1, y1, x2, y2); rect1.setBorder(Rectangle.BOX); rect1.setBorderWidth(2); cb.rectangle(rect1); cb.stroke(); }
From source file:com.vectorprint.report.itext.debug.DebugHelper.java
License:Open Source License
public static void debugBackground(PdfContentByte canvas, Rectangle rect, BaseColor color, String prefix, EnhancedMap settings, LayerManager layerAware) { canvas = canvas.getPdfWriter().getDirectContentUnder(); int rgb = color.getRed() + color.getBlue() + color.getGreen(); rect.setBackgroundColor(color);/* w w w . ja v a 2 s . c om*/ canvas.rectangle(rect); layerAware.startLayerInGroup(DEBUG, canvas); debugFont(canvas, settings); BaseColor txtColor = (rgb < 150) ? color.brighter().brighter() : color.darker().darker(); canvas.setColorFill(txtColor); canvas.setColorStroke(txtColor); canvas.beginText(); canvas.showTextAligned(Element.ALIGN_LEFT, prefix + color.toString().replace(Color.class.getName(), ""), rect.getLeft() + rect.getWidth() / 2, rect.getTop() - rect.getHeight() / 2, 0); canvas.endText(); canvas.endLayer(); }
From source file:com.vectorprint.report.itext.EventHelper.java
License:Open Source License
/** * prints debug info when property debug is true, calls renderHeader and renderFooter and * {@link Advanced#draw(com.itextpdf.text.Rectangle, java.lang.String) } with {@link Document#getPageSize() } * and null for {@link DefaultStylerFactory#PAGESTYLERS}. * * @param writer// www . j a va 2 s .co m * @param document */ @Override public final void onEndPage(PdfWriter writer, Document document) { super.onEndPage(writer, document); sanitize(writer); try { if (failuresHereAfter || debugHereAfter) { PdfContentByte bg = writer.getDirectContentUnder(); Rectangle rect = writer.getPageSize(); rect.setBackgroundColor(itextHelper .fromColor(getSettings().getColorProperty(new Color(240, 240, 240), "legendbackground"))); bg.rectangle(rect); bg.closePathFillStroke(); } else { for (Advanced a : doForAllPages) { try { if (a.shouldDraw(null)) { a.draw(document.getPageSize(), null); } } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } } } if (!debugHereAfter && getSettings().getBooleanProperty(false, DEBUG)) { PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(document.leftMargin(), document.bottomMargin(), document.right() - document.rightMargin(), document.top() - document.topMargin()); DebugHelper.debugRect(canvas, rect, new float[] { 10, 2 }, 0.3f, getSettings(), stylerFactory.getLayerManager()); } renderHeader(writer, document); maxTagForGenericTagOnPage = ((DefaultElementProducer) elementProducer).getAdvancedTag(); if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.PRINTFOOTER)) { renderFooter(writer, document); } else { log.warning("not printing footer, if you want page footers set " + ReportConstants.PRINTFOOTER + " to true"); } maxTagForGenericTagOnPage = Integer.MAX_VALUE; } catch (VectorPrintException | DocumentException | InstantiationException | IllegalAccessException e) { throw new VectorPrintRuntimeException("failed to create the report header or footer: ", e); } }
From source file:com.vectorprint.report.itext.style.stylers.Page.java
License:Open Source License
private void pageSettings() { if (getBackground() != null) { if (log.isLoggable(Level.FINE)) { log.fine("Possibly page background is written on top of page content making it invisible"); }/*from w w w .j a v a 2 s . c o m*/ PdfContentByte bg = getWriter().getDirectContentUnder(); Rectangle rect = getWriter().getPageSize(); rect.setBackgroundColor(itextHelper.fromColor(getBackground())); bg.rectangle(rect); bg.closePathFillStroke(); } getDocument().setPageSize(new Rectangle(getWidth(), getHeight())); getDocument().setMargins(getMargin_left(), getMargin_right(), getMargin_top(), getMargin_bottom()); }
From source file:Controlador.EmailWithPdf.java
/** * Writes the content of a PDF file (using iText API) * to the {@link OutputStream}.// www. j av a2s.c o m * @param outputStream {@link OutputStream}. * @throws Exception */ public void writePdf(OutputStream outputStream) throws Exception { Document document = new Document(PageSize.LETTER, 50, 50, 50, 30); Font boldFontTitulo = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font boldFontTexto = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); Font FontTexto = new Font(Font.FontFamily.HELVETICA, 12); // document.setPageSize(null); PdfWriter writer = PdfWriter.getInstance(document, outputStream); Image imagen = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\BSeguroLogo.png"); Image imagen2 = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\mapfre.png"); DateFormat df = new SimpleDateFormat("dd/MM/YYYY"); Calendar cdos = Calendar.getInstance(); Date datediamas = new Date(); Date dateaniomas = new Date(); cdos.add(Calendar.DATE, 1); datediamas = cdos.getTime(); String fechadiamas = df.format(datediamas); cdos.add(Calendar.YEAR, 1); dateaniomas = cdos.getTime(); String fechavencimiento = df.format(dateaniomas); document.open(); PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(36, 36, 579, 756); rect.setBorder(Rectangle.BOX); rect.setBorderWidth(2); canvas.rectangle(rect); // Rectangle rect= new Rectangle(36,108); // rect.setBorder(Rectangle.BOX); // //rect.setBorderColor(BaseColor.BLACK); //rect.setBorderWidth(2); //document.add(rect); document.addTitle("Cotizacion"); document.addSubject("Cotizacion"); document.addKeywords("Cotizacion, seguros"); document.addAuthor("BSeguro"); document.addCreator("Bseguro"); imagen.scaleAbsoluteHeight(30f); imagen.setAbsolutePosition(45f, 720f); imagen2.scaleAbsoluteHeight(30f); imagen2.setAbsolutePosition(450f, 720f); document.add(imagen); document.add(imagen2); Paragraph paragraph2 = new Paragraph("DATOS DE TU POLIZA" + fechadiamas + " hasta: " + fechavencimiento, boldFontTitulo); Paragraph paragraph3 = new Paragraph( "DhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhATOS DE TU POLIZA", boldFontTitulo); paragraph2.setAlignment(Element.ALIGN_CENTER); document.add(paragraph2); document.add(paragraph3); document.close(); }
From source file:GUI_Apoteker.Panel_Detil_PO.java
private void createPdf(List<detil_pesan_obat> a) { try {/*w ww. j av a 2 s .c om*/ JFileChooser saveFile = new JFileChooser(); String namaFile = "D:/kampus/si-klinik-PO" + po.getId_Pemesanan_obat() + ".pdf"; saveFile.setSelectedFile(new File(namaFile)); String result = null; if (saveFile.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = saveFile.getSelectedFile().toString(); } else { System.out.println("No Selection "); } // TODO add your handling code here: Document document = new Document(); PdfWriter writer = null; try { writer = PdfWriter.getInstance(document, new FileOutputStream(result)); } catch (FileNotFoundException ex) { Logger.getLogger(Panel_Detil_PO.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(50, 800, 550, 700); rect.setBorder(Rectangle.BOX); rect.setBorderWidth(5); rect.setBorderColor(BaseColor.BLACK); canvas.rectangle(rect); Paragraph preface; preface = getPreface("Bulanan"); document.add(preface); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(createTableBulanan(a)); document.close(); open(result); } catch (DocumentException ex) { Logger.getLogger(Panel_Detil_PO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:GUI_StafKlinik.Panel_Laporan_Keuangan.java
private void createPdf(List<Laporan_Keuangan> list) { JFileChooser saveFile = new JFileChooser(); saveFile.setSelectedFile(new File("D:/document/Laporan Keuangan.pdf")); String result = null;//from w w w.ja v a 2 s . c o m if (saveFile.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = saveFile.getSelectedFile().toString(); } else { System.out.println("No Selection "); } try { // TODO add your handling code here: Document document = new Document(); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(result)); document.open(); PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(50, 800, 550, 700); rect.setBorder(Rectangle.BOX); rect.setBorderWidth(0); rect.setBorderColor(BaseColor.BLACK); canvas.rectangle(rect); Paragraph preface; preface = getPreface("Laporan Keuangan"); document.add(preface); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(createTableLaporan(list)); document.close(); open(result); } catch (DocumentException ex) { Logger.getLogger(Panel_Laporan_Keuangan.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(Panel_Laporan_Keuangan.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:GUI_StafKlinik.Panel_Penggajian.java
private void createPdf(List<Penggajian> list) { JFileChooser saveFile = new JFileChooser(); saveFile.setSelectedFile(new File("D:/document/Slip Gaji.pdf")); String result = null;/*w w w. j a v a 2 s . com*/ if (saveFile.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = saveFile.getSelectedFile().toString(); } else { System.out.println("No Selection "); } try { Document document = new Document(); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(result)); document.open(); PdfContentByte canvas = writer.getDirectContent(); for (int i = 0; i < list.size(); i++) { document.newPage(); Rectangle rect = new Rectangle(50, 800, 550, 700); rect.setBorder(Rectangle.BOX); rect.setBorderWidth(0); rect.setBorderColor(BaseColor.BLACK); canvas.rectangle(rect); Paragraph preface; preface = getPreface("Slip Gaji"); document.add(preface); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(createTableLaporan(list.get(i))); } document.close(); open(result); } catch (DocumentException ex) { Logger.getLogger(Panel_Laporan_Keuangan.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(Panel_Laporan_Keuangan.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Modelo.CotizacionDAO.java
public void writePdf(OutputStream outputStream, Cotizacion x, int idcotizacion) throws Exception { DateFormat df = new SimpleDateFormat("dd/MM/YYYY"); Calendar cdos = Calendar.getInstance(); Date datediamas = new Date(); Date dateaniomas = new Date(); cdos.add(Calendar.DATE, 1);//w ww .ja v a 2 s .c om datediamas = cdos.getTime(); String fechadiamas = df.format(datediamas); cdos.add(Calendar.YEAR, 1); dateaniomas = cdos.getTime(); String fechavencimiento = df.format(dateaniomas); Document document = new Document(PageSize.LETTER, 50, 50, 50, 30); Font boldFontTitulo = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font boldFontTexto = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); Font FontTexto = new Font(Font.FontFamily.HELVETICA, 10); // document.setPageSize(null); PdfWriter writer = PdfWriter.getInstance(document, outputStream); Image imagen = Image.getInstance("http://54.67.56.185/BSeguros_pa18/img/BSeguroLogo.png"); // Image imagen = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\BSeguroLogo.png"); Image imagen2 = Image.getInstance( "http://54.67.56.185/BSeguros_pa18/img/Aseguradoras/" + x.getId_aseguradora() + ".png"); //Image imagen2 = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\Mapfre.png"); document.open(); PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(36, 36, 579, 756); rect.setBorder(Rectangle.BOX); rect.setBorderWidth(2); canvas.rectangle(rect); document.addTitle("Cotizacion"); document.addSubject("Cotizacion"); document.addKeywords("Cotizacion, seguros"); document.addAuthor("BSeguro"); document.addCreator("Bseguro"); imagen.scaleAbsoluteHeight(30f); imagen.setAbsolutePosition(45f, 720f); imagen2.scaleAbsoluteHeight(30f); imagen2.setAbsolutePosition(450f, 720f); document.add(imagen); document.add(imagen2); Paragraph paragraph2 = new Paragraph("DATOS DE TU POLIZA", boldFontTitulo); paragraph2.setAlignment(Element.ALIGN_CENTER); document.add(paragraph2); //creas una tabla con un ancho de 3 celdas, el salto a la siguiente fila sera automatico PdfPTable table = new PdfPTable(3); table.getDefaultCell().setBorder(0); PdfPCell cell; Paragraph saltodelinea = new Paragraph(" "); document.add(saltodelinea); document.add(new Paragraph(" Datos de tu poliza folio: " + "BC" + x.getId_aseguradora().substring(0, 1) + x.getMetododepago().substring(0, 1) + ": 0000" + idcotizacion, boldFontTitulo)); document.add(new Paragraph(" Vigencia de la poliza del: " + fechadiamas + " al: " + fechavencimiento, boldFontTitulo)); document.add(saltodelinea); document.add(new Paragraph(" Datos del Contratante: ", boldFontTitulo)); //document.add(saltodelinea); //agrego otra tabla table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("Nombre: ", boldFontTexto)); PdfPCell celdaNombre = new PdfPCell( new Paragraph(x.getNombre_contratante() + " " + x.getApellido_paterno(), FontTexto)); celdaNombre.setColspan(5); celdaNombre.setBorder(0); table.addCell(celdaNombre); table.addCell(new Paragraph("RFC : ", boldFontTexto)); PdfPCell celdaRFC = new PdfPCell(new Paragraph(x.getRfc(), FontTexto)); celdaRFC.setColspan(5); celdaRFC.setBorder(0); table.addCell(celdaRFC); table.addCell(new Paragraph("Direccion: ", boldFontTexto)); PdfPCell celdaDir = new PdfPCell( new Paragraph(x.getCall() + ", " + x.getNo_ext() + ", " + x.getNo_int() + ", " + x.getColonia() + ", " + x.getDelegacion() + ", " + x.getEstado() + ", " + x.getCp(), FontTexto)); celdaDir.setColspan(5); celdaDir.setBorder(0); table.addCell(celdaDir); table.addCell(new Paragraph("Email: ", boldFontTexto)); table.addCell(AddCell(x.getMail(), 5)); table.addCell(new Paragraph("Telefono ", boldFontTexto)); PdfPCell celdaTel = new PdfPCell(new Paragraph(x.getTelefono(), FontTexto)); celdaTel.setColspan(5); celdaTel.setBorder(0); table.addCell(celdaTel); document.add(table); document.add(saltodelinea); document.add(new Paragraph(" Datos del Vehiculo: ", boldFontTitulo)); // document.add(saltodelinea); //agrego otra tabla table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("Marca: ", boldFontTexto)); table.addCell(AddCell(x.getId_marca(), 5)); table.addCell(new Paragraph("Modelo:", boldFontTexto)); table.addCell(AddCell(x.getId_anio().toString(), 5)); table.addCell(new Paragraph("Tipo: ", boldFontTexto)); table.addCell(AddCell(x.getId_submarca(), 5)); table.addCell(new Paragraph("Version: ", boldFontTexto)); table.addCell(AddCell(x.getId_modelo(), 5)); table.addCell(new Paragraph("No. De Serie: ", boldFontTexto)); table.addCell(AddCell(x.getSerie(), 5)); document.add(table); document.add(saltodelinea); document.add(new Paragraph(" Informacion de la Poliza: ", boldFontTitulo)); // document.add(saltodelinea); //agrego otra tabla table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("Pago: ", boldFontTexto)); table.addCell(AddCell(x.getTipo_pago(), 5)); table.addCell(new Paragraph("Aseguradora: ", boldFontTexto)); table.addCell(AddCell(x.getId_aseguradora(), 5)); document.add(table); document.add(saltodelinea); document.add(new Paragraph(" Detalles de la Cobertura: Cobertura Amplia ", boldFontTitulo)); // document.add(saltodelinea); //agrego otra tabla table = new PdfPTable(3); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("Cobertura ", boldFontTexto)); table.addCell(new Paragraph("Responsabilidad Civil", boldFontTexto)); table.addCell(new Paragraph("Deducible ", boldFontTexto)); table.addCell(new Paragraph("Daos Materiales", FontTexto)); table.addCell(new Paragraph("Valor Comercial", FontTexto)); table.addCell(new Paragraph("5%", FontTexto)); table.addCell(new Paragraph("Robo Total", FontTexto)); table.addCell(new Paragraph("Valor Comercial", FontTexto)); table.addCell(new Paragraph("10%", FontTexto)); table.addCell(new Paragraph("Responsabilidad Civil", FontTexto)); table.addCell(new Paragraph("$4,000,000.00", FontTexto)); table.addCell(new Paragraph("", FontTexto)); table.addCell(new Paragraph("Gastos Medicos Ocupantes", FontTexto)); table.addCell(new Paragraph("$500,000.00", FontTexto)); table.addCell(new Paragraph("", FontTexto)); table.addCell(new Paragraph("Asistencia Legal", FontTexto)); table.addCell(new Paragraph("Amparada", FontTexto)); table.addCell(new Paragraph("", FontTexto)); table.addCell(new Paragraph("Asistencia Vial", FontTexto)); table.addCell(new Paragraph("Amparada", FontTexto)); table.addCell(new Paragraph("", FontTexto)); document.add(table); document.add(saltodelinea); document.add(new Paragraph(" Informacion del Pago ", boldFontTitulo)); document.add(new Paragraph(" Instrumento de Pago: " + x.getMetododepago(), boldFontTexto)); //agrego otra tabla table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(AddCell("Concepto ", 2)); table.addCell(AddCell("Monto", 4)); table.addCell(AddCell("Prima Total ", 2)); table.addCell(AddCell(x.getMonto(), 4)); table.addCell(AddCell("Prima Inicial", 2)); table.addCell(AddCell(x.getMonto(), 4)); table.addCell(AddCell("Pago Subsecuente ", 2)); table.addCell(AddCell("0", 4)); document.add(table); document.add(saltodelinea); if (x.getCobertura_auto_siempre() == true) { document.add(new Paragraph(" Informacion de Modulos HDI ", boldFontTitulo)); table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(AddCell("Modulos ", 2)); table.addCell(AddCell("Contratados", 4)); table.addCell(AddCell("HDI - Autos por Siempre ", 2)); table.addCell(AddCell("$ 1,799.00", 4)); document.add(table); } else { if (x.getCobertura_auto_amante() == true) { document.add(new Paragraph(" Informacion de Modulos HDI ", boldFontTitulo)); table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(AddCell("Modulos ", 2)); table.addCell(AddCell("Contratados", 4)); table.addCell(AddCell("HDI - Amante de los Autos ", 2)); table.addCell(AddCell("$ 1,799.00", 4)); document.add(table); } else { } document.add(saltodelinea); } document.add(new Paragraph("* Estaras asegurado a partir de las 12 horas del siguiente dia habil.", boldFontTexto)); document.close(); }