List of usage examples for com.itextpdf.text Image setAbsolutePosition
public void setAbsolutePosition(final float absoluteX, final float absoluteY)
Image
. From source file:com.pablog178.pdfcreator.android.PdfcreatorModule.java
License:Open Source License
private void generateiTextPDFfunction(HashMap args) { if (args.containsKey("fileName")) { Object fileName = args.get("fileName"); if (fileName instanceof String) { this.fileName = (String) fileName; Log.i(PROXY_NAME, "fileName: " + this.fileName); }//from w ww . java 2 s.com } else return; if (args.containsKey("view")) { Object viewObject = args.get("view"); if (viewObject instanceof TiViewProxy) { TiViewProxy viewProxy = (TiViewProxy) viewObject; this.view = viewProxy.getOrCreateView(); if (this.view == null) { Log.e(PROXY_NAME, "NO VIEW was created!!"); return; } Log.i(PROXY_NAME, "view: " + this.view.toString()); } } else return; if (args.containsKey("quality")) { this.quality = TiConvert.toInt(args.get("quality")); } if (args.containsKey("pageSize")) { Object pageSize = args.get("pageSize"); if (pageSize instanceof String) { if (pageSize.equals("letter")) { this.pageSize = PageSize.LETTER; } else if (pageSize.equals("A4")) { this.pageSize = PageSize.A4; } else { this.pageSize = PageSize.LETTER; } } } TiBaseFile file = TiFileFactory.createTitaniumFile(this.fileName, true); Log.i(PROXY_NAME, "file full path: " + file.nativePath()); try { Resources appResources = app.getResources(); OutputStream outputStream = file.getOutputStream(); final int MARGIN = 0; final float PDF_WIDTH = this.pageSize.getWidth() - MARGIN * 2; // A4: 595 //Letter: 612 final float PDF_HEIGHT = this.pageSize.getHeight() - MARGIN * 2; // A4: 842 //Letter: 792 final int DEFAULT_VIEW_WIDTH = 980; final int DEFAULT_VIEW_HEIGHT = 1384; int viewWidth = DEFAULT_VIEW_WIDTH; int viewHeight = DEFAULT_VIEW_HEIGHT; Document pdfDocument = new Document(this.pageSize, MARGIN, MARGIN, MARGIN, MARGIN); PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream); Log.i(PROXY_NAME, "PDF_WIDTH: " + PDF_WIDTH); Log.i(PROXY_NAME, "PDF_HEIGHT: " + PDF_HEIGHT); WebView view = (WebView) this.view.getNativeView(); if (TiApplication.isUIThread()) { viewWidth = view.capturePicture().getWidth(); viewHeight = view.capturePicture().getHeight(); if (viewWidth <= 0) { viewWidth = DEFAULT_VIEW_WIDTH; } if (viewHeight <= 0) { viewHeight = DEFAULT_VIEW_HEIGHT; } } else { Log.e(PROXY_NAME, "NO UI THREAD"); viewWidth = DEFAULT_VIEW_WIDTH; viewHeight = DEFAULT_VIEW_HEIGHT; } view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); Log.i(PROXY_NAME, "viewWidth: " + viewWidth); Log.i(PROXY_NAME, "viewHeight: " + viewHeight); float scaleFactorWidth = 1 / ((float) viewWidth / PDF_WIDTH); float scaleFactorHeight = 1 / ((float) viewHeight / PDF_HEIGHT); Log.i(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth); Log.i(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight); Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888); Canvas viewCanvas = new Canvas(viewBitmap); // Paint paintAntialias = new Paint(); // paintAntialias.setAntiAlias(true); // paintAntialias.setFilterBitmap(true); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(viewCanvas); } else { viewCanvas.drawColor(Color.WHITE); } view.draw(viewCanvas); TiBaseFile pdfImg = createTempFile(); // ByteArrayOutputStream stream = new ByteArrayOutputStream(32); // viewBitmap.compress(Bitmap.CompressFormat.JPEG, this.quality, stream); viewBitmap.compress(Bitmap.CompressFormat.JPEG, this.quality, pdfImg.getOutputStream()); FileInputStream pdfImgInputStream = new FileInputStream(pdfImg.getNativeFile()); byte[] pdfImgBytes = IOUtils.toByteArray(pdfImgInputStream); pdfImgInputStream.close(); // ByteBuffer buffer = ByteBuffer.allocate(viewBitmap.getByteCount()); // viewBitmap.copyPixelsToBuffer(buffer); pdfDocument.open(); float yFactor = viewHeight * scaleFactorWidth; int pageNumber = 1; do { if (pageNumber > 1) { pdfDocument.newPage(); } pageNumber++; yFactor -= PDF_HEIGHT; Image pageImage = Image.getInstance(pdfImgBytes, true); // Image pageImage = Image.getInstance(buffer.array()); pageImage.scalePercent(scaleFactorWidth * 100); pageImage.setAbsolutePosition(0f, -yFactor); pdfDocument.add(pageImage); Log.i(PROXY_NAME, "yFactor: " + yFactor); } while (yFactor > 0); pdfDocument.close(); sendCompleteEvent(); } catch (Exception exception) { Log.e(PROXY_NAME, "Error: " + exception.toString()); sendErrorEvent(exception.toString()); } }
From source file:com.pdi.util.PdfGenerator.java
public static void generarPresupuesto(String lugar, Date fecha, float cantidad, String tipo, Cliente cliente, float precio, Aliado aliado, String path) { try {//from w ww . j a v a2s .co m NEGRITA_12_VERDE.setColor(145, 189, 57); long miliSemana = System.currentTimeMillis() + (86400 * 7 * 1000); Date vtoPresup = new Date(miliSemana); float precioPers = precio / cantidad; int precioTotalInt = Math.round(precio); int precioPersInt = Math.round(precioPers); int cantPersonasInt = Math.round(cantidad); //Referencia al objeto Doc Document document = new Document(PageSize.A4, //Dimensiones 36, //margIzq 36, //margDer 36, //margenSup 36); // margenInf //Creamos el archivo fisico FileOutputStream salida = new FileOutputStream(path); //Referencia e inicializacion del objeto que "escribe" el PDF PdfWriter writer = PdfWriter.getInstance(document, salida); writer.setInitialLeading(0); //Imagen Logo Image logoPDI = Image.getInstance("Logo PDI.png"); logoPDI.scaleToFit(215, 205); logoPDI.setAlignment(Chunk.ALIGN_LEFT); //image.setAbsolutePosition(200, 200); //Imagen QR Image qr = Image.getInstance("QR PDI.png"); qr.scaleToFit(211, 165); qr.setAbsolutePosition(295, PageSize.A4.getHeight() - 390); //Parrafo info evento Paragraph infoEvento = new Paragraph(); infoEvento.add(new Chunk("Informacin del Evento", NEGRITA_SUB_12)); infoEvento.add(Chunk.NEWLINE); infoEvento.add(negritaNormal("Solicitante: ", cliente.toString())); infoEvento.add(negritaNormal("Evento: ", tipo)); infoEvento.add(negritaNormal("Cantidad de personas: ", Integer.toString(cantPersonasInt))); infoEvento.add(negritaNormal("Fecha: ", General.formatoFecha.format(fecha))); infoEvento.add(negritaNormal("Lugar: ", lugar)); infoEvento.add(Chunk.NEWLINE); infoEvento.setAlignment(Paragraph.ALIGN_LEFT); //Parrafo Modalidad del Servicio Paragraph modalidadServicio = new Paragraph(); modalidadServicio.add(new Chunk("Modalidad Servicio Integral", NEGRITA_SUB_12)); modalidadServicio.add(Chunk.NEWLINE); modalidadServicio.add(new Chunk("Nuestro servicio incluye la totalidad de lo referido a" + " los elementos necesarios para el despacho de bebidas: Barras, Bartenders," + " Artculos de Coctelera, Insumos de calidad para los tragos y Mucha Buena Onda." + " Con esta modalidad aseguramos la expedicin de " + "los tragos desde las 00hs hasta las 05hs, para que se desentiendan del asunto " + "y disfruten al mximo.", NORMAL_12)); modalidadServicio.setAlignment(Paragraph.ALIGN_LEFT); //Parrafo Ver Carta Paragraph verCarta = new Paragraph(); verCarta.add(negritaNormal("\u2022 Carta de Tragos: ", "Ver archivo adjunto.")); verCarta.setIndentationLeft(20); verCarta.add(Chunk.NEWLINE); verCarta.setAlignment(Paragraph.ALIGN_LEFT); //Parrafo Titulo Info Contratacion Paragraph infoContratacionTitulo = new Paragraph(); infoContratacionTitulo.add(new Chunk("Informacin de Contratacin", NEGRITA_SUB_12)); infoContratacionTitulo.setAlignment(Paragraph.ALIGN_LEFT); //Parrafo Inf de Contratacion Paragraph infoContratacion = new Paragraph(); infoContratacion.add(negritaNormal("\u2022 Mtodo de contratacin y reserva de la fecha: ", "A travs de contrato firmado por ambas partes. ")); Phrase lineaCosto = new Phrase(); lineaCosto.add(new Chunk("\u2022 Costo: ", NEGRITA_12)); lineaCosto.add(new Chunk("$" + Integer.toString(precioPersInt) + " ", NEGRITA_14)); lineaCosto.add(new Chunk("por persona ", NEGRITA_12)); lineaCosto.add(new Chunk("(Total: $" + Integer.toString(precioTotalInt) + ")", NEGRITA_14)); infoContratacion.add(lineaCosto); infoContratacion.add(Chunk.NEWLINE); infoContratacion.add(negritaNormal("\u2022 Forma de Pago : ", "50% al momento de la firma del contrato y 50% como mximo una semana antes del evento. ")); infoContratacion.add(Chunk.NEWLINE); infoContratacion.setIndentationLeft(20); infoContratacion.setFirstLineIndent(0); infoContratacion.setAlignment(Paragraph.ALIGN_LEFT); //Parrafo Despedida Paragraph despedida = new Paragraph(); despedida.add(new Phrase("Quedamos al aguardo de tus comentarios,", NEGRITA_14)); despedida.add(Chunk.NEWLINE); despedida.add(new Phrase("Muchas Gracias.", NEGRITA_14)); despedida.add(Chunk.NEWLINE); despedida.add(Chunk.NEWLINE); despedida.setAlignment(Paragraph.ALIGN_LEFT); //Parrafo Firma Paragraph firma = new Paragraph(); firma.add(new Phrase("Piel de Iguana Tragos.-", NEGRITA_CUR_14)); firma.add(Chunk.NEWLINE); firma.add(new Phrase("Cel.: 3462-15337860", NEGRITA_12_VERDE)); firma.setAlignment(Paragraph.ALIGN_RIGHT); float llxLink = 279; float llyLink = PageSize.A4.getHeight() - 145; float anchoLink = 199; float altoLink = 16; //Link al facebook URL urlPDI = new URL("https://www.facebook.com/pieldeiguanatragos.vt"); PdfAction irAlFace = new PdfAction(urlPDI); Rectangle linkLocation = new Rectangle(llxLink, llyLink, llxLink + anchoLink, llyLink + altoLink); PdfAnnotation link = PdfAnnotation.createLink(writer, linkLocation, PdfAnnotation.HIGHLIGHT_NONE, irAlFace); link.setBorder(new PdfBorderArray(0, 0, 0)); writer.addAnnotation(link); //Espacios Vacios Paragraph dosEspacios = new Paragraph(); dosEspacios.add(Chunk.NEWLINE); dosEspacios.add(Chunk.NEWLINE); //Hay que abrir el Documento, llenarlo con los elemntos creados //en el orden que queremos y cerrarlo document.open(); PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); Phrase recuadro = new Phrase(); recuadro.add(new Chunk("Piel de Iguana Tragos", NEGRITA_SUB_14)); recuadro.add(Chunk.NEWLINE); recuadro.add(new Chunk("Servicio de tragos para eventos", NEGRITA_12)); recuadro.add(Chunk.NEWLINE); recuadro.add(Chunk.NEWLINE); recuadro.add(new Chunk("\"Piel de Iguana, para que tu noche nica sea inigualable.\"", NORMAL_CUR_12)); recuadro.add(Chunk.NEWLINE); recuadro.add(Chunk.NEWLINE); Image logoFB = Image.getInstance("Icono FB.png"); logoFB.scaleToFit(13, 13); recuadro.add(new Chunk(logoFB, 0, -3)); recuadro.add(new Chunk("/pieldeiguanatragos.vt -> Click Aqu!", NORMAL_12)); recuadro.add(Chunk.NEWLINE); recuadro.add(Chunk.NEWLINE); recuadro.add(new Chunk("Vencimiento del Prepuesto " + General.formatoFecha.format(vtoPresup), NORMAL_SUB_12)); float llx = 279; float lly = PageSize.A4.getHeight() - 185; float ancho = 228; float alto = 150; ct.setSimpleColumn(recuadro, //Texto llx, //punta inf izquierda (x) lly, //punta inf izquierda (y) PageSize.A4.getHeight() - 185 llx + ancho, //ancho del cuadro lly + alto, // alto del cuadro 15, //espaciado Element.ALIGN_LEFT // Alineacion ); ct.go(); document.add(logoPDI); document.add(qr); document.add(dosEspacios); document.add(infoEvento); document.add(modalidadServicio); document.add(verCarta); document.add(infoContratacionTitulo); document.add(infoContratacion); document.add(despedida); document.add(firma); document.close(); System.out.println("Archivo creado"); int rta = JOptionPane.showConfirmDialog(VentanaMaestra.eventosCurrent, "Se guard el presupesto en:\n" + path + "\nDesea abrirlo?", "Presupuesto guardado", JOptionPane.YES_NO_OPTION); if (rta == JOptionPane.YES_OPTION) { if (Desktop.isDesktopSupported()) { try { File myFile = new File(path); Desktop.getDesktop().open(myFile); } catch (IOException ex) { JOptionPane.showMessageDialog(VentanaMaestra.eventosCurrent, "No se puede abrir el archivo. Ubiquelo en su equipo" + "y abralo manualmente.", "Error al abrir el archivo", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(VentanaMaestra.eventosCurrent, "No se puede abrir el archivo. Ubiquelo en su equipo" + "y abralo manualmente.", "Error al abrir el archivo", JOptionPane.ERROR_MESSAGE); } } } catch (FileNotFoundException ex) { System.out.println("Error: " + ex.toString()); } catch (DocumentException ex) { System.out.println("Error: " + ex.toString()); } catch (IOException ex) { System.out.println("Error: " + ex.toString()); } }
From source file:com.primeleaf.krystal.util.PDFConverter.java
License:Open Source License
public File getConvertedFile(DocumentRevision documentRevision, Document document, String password) throws Exception { File tempFile = documentRevision.getDocumentFile(); if ("TIF".equalsIgnoreCase(document.getExtension()) || "TIFF".equalsIgnoreCase(document.getExtension())) { try {//from ww w . j a v a2 s . c om tempFile = File.createTempFile("temp", ".PDF"); com.itextpdf.text.Document pdf = new com.itextpdf.text.Document(); PdfWriter.getInstance(pdf, new FileOutputStream(tempFile)); pdf.open(); pdf.setMargins(0, 0, 0, 0); FileInputStream fis = new FileInputStream(documentRevision.getDocumentFile()); RandomAccessFileOrArray file = new RandomAccessFileOrArray(fis); int pages = TiffImage.getNumberOfPages(file); for (int page = 1; page <= pages; page++) { Image img = TiffImage.getTiffImage(file, page); img.setAbsolutePosition(0f, 0f); img.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight()); pdf.setMargins(0, 0, 0, 0); pdf.add(img); pdf.newPage(); } fis.close(); pdf.close(); document.setExtension("PDF"); } catch (Exception e) { tempFile = documentRevision.getDocumentFile(); throw new Exception("Unable to convert TIFF Document to PDF"); } } else if ("JPG".equalsIgnoreCase(document.getExtension()) || "JPEG".equalsIgnoreCase(document.getExtension()) || "PNG".equalsIgnoreCase(document.getExtension()) || "BMP".equalsIgnoreCase(document.getExtension()) || "GIF".equalsIgnoreCase(document.getExtension())) { try { tempFile = File.createTempFile("temp", ".PDF"); Image img = Image.getInstance(documentRevision.getDocumentFile().getAbsolutePath()); com.itextpdf.text.Document pdf = new com.itextpdf.text.Document( new Rectangle(img.getWidth(), img.getHeight()), 0, 0, 0, 0); img.setAbsolutePosition(0f, 0f); PdfWriter.getInstance(pdf, new FileOutputStream(tempFile)); pdf.open(); pdf.add(img); pdf.close(); document.setExtension("PDF"); } catch (Exception e) { tempFile = documentRevision.getDocumentFile(); throw new Exception("Unable to convert Image Document to PDF"); } } else if ("PDF".equalsIgnoreCase(document.getExtension())) { tempFile = documentRevision.getDocumentFile(); } else { String tempFilePath = ""; String KRYSTAL_HOME = System.getProperty("krystal.home"); if (KRYSTAL_HOME == null) { KRYSTAL_HOME = System.getProperty("user.dir"); System.setProperty("krystal.home", KRYSTAL_HOME); } tempFilePath = KRYSTAL_HOME + File.separator + "/webapps/DMC/images/unsupport.pdf"; tempFile = new File(tempFilePath); } return tempFile; }
From source file:com.propelics.pdfcreator.PdfcreatorModule.java
License:Open Source License
private void generateiTextPDFfunction(HashMap args) { Log.d(PROXY_NAME, "generateiTextPDFfunction()"); String filename = ""; TiUIView webview = null;//ww w. jav a 2s . c om int quality = 100; try { if (args.containsKey("filename")) { filename = (String) args.get("filename"); Log.d(PROXY_NAME, "filename: " + filename); } else return; if (args.containsKey("webview")) { TiViewProxy viewProxy = (TiViewProxy) args.get("webview"); webview = viewProxy.getOrCreateView(); Log.d(PROXY_NAME, "webview: " + webview.toString()); } else return; if (args.containsKey("quality")) { quality = TiConvert.toInt(args.get("quality")); } TiBaseFile file = TiFileFactory.createTitaniumFile(filename, true); Log.d(PROXY_NAME, "file full path: " + file.nativePath()); OutputStream outputStream = file.getOutputStream(); final int MARGIN = 0; final float PDF_WIDTH = PageSize.LETTER.getWidth() - MARGIN * 2; // A4: 595 //Letter: 612 final float PDF_HEIGHT = PageSize.LETTER.getHeight() - MARGIN * 2; // A4: 842 //Letter: 792 final int DEFAULT_VIEW_WIDTH = 980; final int DEFAULT_VIEW_HEIGHT = 1384; int viewWidth = DEFAULT_VIEW_WIDTH; int viewHeight = DEFAULT_VIEW_HEIGHT; Document pdfDocument = new Document(PageSize.LETTER, MARGIN, MARGIN, MARGIN, MARGIN); PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream); Log.d(PROXY_NAME, "PDF_WIDTH: " + PDF_WIDTH); Log.d(PROXY_NAME, "PDF_HEIGHT: " + PDF_HEIGHT); WebView view = (WebView) webview.getNativeView(); if (TiApplication.isUIThread()) { viewWidth = view.capturePicture().getWidth(); viewHeight = view.capturePicture().getHeight(); if (viewWidth <= 0) { viewWidth = DEFAULT_VIEW_WIDTH; } if (viewHeight <= 0) { viewHeight = DEFAULT_VIEW_HEIGHT; } } else { Log.e(PROXY_NAME, "NO UI THREAD"); viewWidth = DEFAULT_VIEW_WIDTH; viewHeight = DEFAULT_VIEW_HEIGHT; } view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); Log.d(PROXY_NAME, "viewWidth: " + viewWidth); Log.d(PROXY_NAME, "viewHeight: " + viewHeight); float scaleFactorWidth = 1 / (viewWidth / PDF_WIDTH); float scaleFactorHeight = 1 / (viewHeight / PDF_HEIGHT); Log.d(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth); Log.d(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight); Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888); Canvas viewCanvas = new Canvas(viewBitmap); // Paint paintAntialias = new Paint(); // paintAntialias.setAntiAlias(true); // paintAntialias.setFilterBitmap(true); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(viewCanvas); } else { viewCanvas.drawColor(Color.WHITE); } view.draw(viewCanvas); TiBaseFile pdfImg = createTempFile(filename); viewBitmap.compress(Bitmap.CompressFormat.PNG, quality, pdfImg.getOutputStream()); FileInputStream pdfImgInputStream = new FileInputStream(pdfImg.getNativeFile()); byte[] pdfImgBytes = IOUtils.toByteArray(pdfImgInputStream); pdfImgInputStream.close(); pdfDocument.open(); float yFactor = viewHeight * scaleFactorWidth; int pageNumber = 1; do { if (pageNumber > 1) { pdfDocument.newPage(); } pageNumber++; yFactor -= PDF_HEIGHT; Image pageImage = Image.getInstance(pdfImgBytes, true); // Image pageImage = Image.getInstance(buffer.array()); pageImage.scalePercent(scaleFactorWidth * 100); pageImage.setAbsolutePosition(0f, -yFactor); pdfDocument.add(pageImage); Log.d(PROXY_NAME, "yFactor: " + yFactor); } while (yFactor > 0); pdfDocument.close(); sendCompleteEvent(filename); } catch (Exception exception) { sendErrorEvent(exception); } }
From source file:com.qmetric.document.watermark.PdfWatermarkFactory.java
License:Open Source License
public Image createImage(final PdfReader reader) { final Rectangle pageSize = reader.getPageSize(1); try {/*w w w .ja va2s .c om*/ final Image image = imageUtils.getInstance(fileUtils.bytesFrom(imagePath)); image.setAbsolutePosition(getXOffset(pageSize, image), getYOffset(pageSize, image)); return image; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.raghav.plot.ImageIntoPDF.java
public static void main(String[] args) throws Exception { Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/home/raghav/zzzzz.pdf")); document.open();/*w ww.ja va 2s . c o m*/ document.newPage(); //for 4 photo // for (int i=0;i<2;i++) { // Image image1 = Image.getInstance("/home/raghav/Desktop/Firmway-Reco.png"); // image1.setAbsolutePosition(40,80+(350*i)); // image1.scaleAbsolute(200, 260); // document.add(image1); // } // for (int i=0;i<2;i++) { // Image image1 = Image.getInstance("/home/raghav/Desktop/Firmway-Reco.png"); // image1.setAbsolutePosition(300, 80+(350*i)); // image1.scaleAbsolute(260, 200); // document.add(image1); // } //for 6 float margin = 10; float docHeight = ((document.getPageSize().getHeight()) / 3) - (2 * margin); float docwidth = ((document.getPageSize().getWidth()) / 2) - (2 * margin); for (int i = 0; i < 3; i++) { Image image1 = Image.getInstance("/home/raghav/myps/i1.jpeg"); image1.setAbsolutePosition(margin, margin * (i + 1) + (docHeight * i)); image1.scaleToFit(docwidth, docHeight); //image1.scaleAbsolute(190, 130); document.add(image1); } for (int i = 0; i < 3; i++) { Image image1 = Image.getInstance("/home/raghav/myps/i1.jpeg"); image1.setAbsolutePosition(docwidth + (2 * margin), margin * (i + 1) + (docHeight * i)); image1.scaleToFit(docwidth, docHeight); document.add(image1); } document.close(); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorActivosFijos.java
public void crearPDFInversion(HttpServletResponse hsr1, ArrayList<HashMap> resultados, double granTotalDepActual, double granTotalValorActual, double granTotalValorOr) throws Exception { Document dcmntaf = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(dcmntaf, baos); System.out.println(resultados.get(0).size()); dcmntaf.open();//www . j a v a2s.c o m dcmntaf.open(); dcmntaf.addTitle("Sapito PDFs"); dcmntaf.addSubject("Pdf de sapito"); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); dcmntaf.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); dcmntaf.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); dcmntaf.add(footer); //---------------------- TITLE --------------------------- String titulo = "Reporte de Inversin"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); String titulo2 = "Reporte de Activos Fijos por Tipo"; //Cambiar el titulo del PDF aqui Font f2 = new Font(FontFamily.HELVETICA, 12.0f, Font.NORMAL, BaseColor.BLACK); Chunk c2 = new Chunk(titulo2 + " \n ", f2); c2.setBackground(BaseColor.WHITE); Paragraph title2 = new Paragraph(c2); title2.setAlignment(Element.ALIGN_LEFT); title2.setIndentationLeft(50); //------------------------- CONTENIDO ------------------------------------------------------- dcmntaf.add(title); //Titulo del PDF dcmntaf.add(title2); PdfPTable table = new PdfPTable(4); // PdfPCell cell; // cell = new PdfPCell(new Phrase("Tipo de A", FontFactory.getFont("TIMES_ROMAN", 12, Font.BOLD, BaseColor.BLACK))); // table.addCell(cell); table.addCell("Tipo de Activo fijo"); table.addCell("Valor Original"); table.addCell("Depreciacin Actual "); table.addCell("Valor Actual"); // Iterator it = resultados.get(0).entrySet().iterator(); for (int i = 0; i < resultados.size(); i++) { table.addCell(resultados.get(i).get("tipo").toString()); table.addCell(resultados.get(i).get("valorOriginal").toString()); table.addCell(resultados.get(i).get("depreciacionActual").toString()); table.addCell(resultados.get(i).get("valoreActual").toString()); } // while (it.hasNext()) { // Map.Entry e = (Map.Entry) it.next(); // System.out.println(e.getKey() + " " + e.getValue()); // // table.addCell(e.getValue().toString()); // } dcmntaf.add(table); String titulo3 = "Reporte Total de Activos Fijos"; //Cambiar el titulo del PDF aqui Font f3 = new Font(FontFamily.HELVETICA, 12.0f, Font.NORMAL, BaseColor.BLACK); Chunk c3 = new Chunk(titulo3 + " \n ", f3); c3.setBackground(BaseColor.WHITE); Paragraph title3 = new Paragraph(c3); title3.setAlignment(Element.ALIGN_LEFT); title3.setIndentationLeft(50); dcmntaf.add(title3); PdfPTable table2 = new PdfPTable(3); // PdfPCell cell; // cell = new PdfPCell(new Phrase("Tipo de A", FontFactory.getFont("TIMES_ROMAN", 12, Font.BOLD, BaseColor.BLACK))); // table.addCell(cell); table2.addCell("Valor Original Total"); table2.addCell("Depreciacin Anual Total"); table2.addCell("Valor Total"); table2.addCell(granTotalValorOr + ""); table2.addCell(granTotalDepActual + ""); table2.addCell(granTotalValorActual + ""); dcmntaf.add(table2); PdfPTable table3 = new PdfPTable(1); table3.setWidthPercentage(100.0f); table3.setWidths(new float[] { 2.0f }); table3.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.COURIER_BOLD); font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(BaseColor.BLUE); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Resultado", font)); table3.addCell(cell); Depreciacion dep = new Depreciacion(); String bla = a + " "; table3.addCell(bla); //-------------------------- FIN CONTENIDO ----------------- dcmntaf.close(); dcmntaf.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorContabilidad.java
public void crearEstadoResultados(HttpServletResponse hsr1, String ingresos, String cVenta, String cGeneral, String cImpu, String cImpTot) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();/*from ww w .ja v a2 s. c o m*/ document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Estado de Resultados"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF PdfPTable table = new PdfPTable(2); table.addCell("Ingresos"); table.addCell(ingresos);//valor table.addCell("Costo de Venta"); table.addCell(cVenta);//valor table.addCell("Costos Generales"); table.addCell(cGeneral);//valor table.addCell("Impuestos de Ingresos"); table.addCell(cImpu);//valor table.addCell("Impuesto de Costos Totales"); table.addCell(cImpTot);//valor document.add(table); document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorContabilidad.java
public void crearVariacionContable(HttpServletResponse hsr1, String sInicial, String aumento, String utilidad, String disminucion, String perdidas, String sFinal) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();//ww w. j a va 2s. c o m document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Variaciones de Capital Contable"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF PdfPTable table = new PdfPTable(2); table.addCell("Saldo al inicio del ejercicio"); table.addCell(sInicial);//valor table.addCell("Aumentos"); table.addCell(aumento);//valor table.addCell("Utilidades"); table.addCell(utilidad);//valor table.addCell("Disminuciones"); table.addCell(disminucion);//valor table.addCell("Perdidas"); table.addCell(perdidas);//valor table.addCell("Saldo al final del ejercicio"); table.addCell(sFinal);//valor document.add(table); document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorContabilidad.java
public void crearFlujo(HttpServletResponse hsr1, String operacion, String sInicio, String sFin) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();//w ww . j a va 2 s . com document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Flujo de Efectivo"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF PdfPTable table = new PdfPTable(2); table.addCell("Operacin"); table.addCell(operacion);//valor table.addCell("Saldo al inicio del ao"); table.addCell(sInicio);//valor table.addCell("Saldo al inicio del ao"); table.addCell(sFin);//valor document.add(table); document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }