List of usage examples for com.itextpdf.text Image setTransparency
public void setTransparency(final int transparency[])
From source file:com.sapito.pdf.PDFView.PDFGeneratorDireccion.java
public void reportefinanzas(Map<String, Object> model, HttpServletResponse hsr1, List<CuentaBancaria> cuenta) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();/* w w w. jav a 2s .c om*/ document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30); font1.setColor(BaseColor.BLACK); Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24); font2.setColor(BaseColor.BLACK); document.add(new Paragraph("TAILS 2015", font1)); document.add(new Paragraph("Reportes Direccin\n", font2)); //------------------------ 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 = "Reporte de Finanzas"; //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 TextoPdf x = (TextoPdf) model.get("todoTexto"); document.add(new Paragraph(x.getTodoTexto())); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 2.0f }); table.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("Total de dinero que se tiene en CUENTAS BANCARIAS", font)); table.addCell(cell); for (int i = 0; i < cuenta.size(); i++) { a = cuenta.get(i).getHaber(); b = b + a; } String bla = b + " "; table.addCell(bla); document.add(table); //-------------------------- FIN CONTENIDO ----------------- 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.PDFGeneratorVentas.java
public void crearPDFFactura(HttpServletResponse hsr1) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();/*from w w w .jav a 2 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 = "Facturas"; //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(1); table.addCell("Hola"); table.addCell("Soy"); table.addCell("el"); table.addCell("pdf"); table.addCell("del"); table.addCell("sapito"); document.add(table); document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:utility.pdfRead.java
public void readPdfFromUrl(String url) throws MalformedURLException, Exception { URL urlnya = new URL(url); String namafile;// www . j av a 2 s. c o m Date d = new Date(); // kode String dataAkun = "Surat Keterangan Domisili Usaha dari Kelurahan dan Kecamatan yang masih berlaku atau Fotocopy dilegalisir Kecamatan"; pdfRead myEncryptor = new pdfRead(); String dataAkunEnkripsi = myEncryptor.encrypt(dataAkun); String dataAkunDekripsi = myEncryptor.decrypt( "AYxJhAMLk4fftR5XcqYDoUO4GaMY7sNX19k5SRxWWedGj6RB3tSUUmtdx1KHYf19EE1rLonm/3XikRnNoG/Q0rXkbiXO3QXHnmn2douw6SSwrirgYGoHmR3U4wmGUCxXqAERQFd5rdCZcK0CII7sPsb2uiTYqA97"); System.out.println("Text Asli: " + dataAkun); System.out.println("Text Terenkripsi :" + dataAkunEnkripsi); System.out.println("Text Terdekripsi :" + dataAkunDekripsi); // kode byte[] ba1 = new byte[5 * 1024]; // byte[] ba1 = new byte[10*1024]; int baLength; InputStream is1 = null; ByteArrayOutputStream bios = new ByteArrayOutputStream(); ByteArrayOutputStream biosPlusWatermark = new ByteArrayOutputStream(); ByteArrayOutputStream biosPlusWatermarkQr = new ByteArrayOutputStream(); AMedia amedia = null; try { // report.setSrc(url); // ssl disable // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; // Install the all-trusting trust manager SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); // Create all-trusting host name verifier HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; // Install the all-trusting host verifier HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); URLConnection urlConn = urlnya.openConnection(); try { // Read the PDF from the URL and save to a local file is1 = urlnya.openStream(); while ((baLength = is1.read(ba1)) != -1) { bios.write(ba1, 0, baLength); } } catch (Exception e) { } finally { is1.close(); bios.close(); } // add watermark try { PdfReader reader = new PdfReader(bios.toByteArray()); int n = reader.getNumberOfPages(); // create a stamper that will copy the document to a new file try { // Read the PDF from the URL and save to a local file is1 = urlnya.openStream(); while ((baLength = is1.read(ba1)) != -1) { biosPlusWatermark.write(ba1, 0, baLength); } } catch (Exception e) { } finally { is1.close(); biosPlusWatermark.close(); } PdfStamper stamp = new PdfStamper(reader, biosPlusWatermark, '\0', true); int i = 0; PdfContentByte under; Image img = Image.getInstance("img/watermark.png"); img.setTransparency(new int[] { 0x00, 0x10 }); img.setAbsolutePosition(0, 0); while (i < n) { i++; under = stamp.getOverContent(i); under.addImage(img); } stamp.close(); } catch (Exception e) { System.out.println("err watermark:" + e); amedia = new AMedia("Dokumen", "pdf", "application/pdf", bios.toByteArray()); } // add QRcode try { PdfReader reader = new PdfReader(biosPlusWatermark.toByteArray()); int n = reader.getNumberOfPages(); BarcodeQRCode qrcode = new BarcodeQRCode(dataAkunEnkripsi, 50, 50, null); Image image = qrcode.getImage(); Image mask = qrcode.getImage(); mask.makeMask(); image.setImageMask(mask); // create a stamper that will copy the document to a new file try { // Read the PDF from the URL and save to a local file is1 = urlnya.openStream(); while ((baLength = is1.read(ba1)) != -1) { biosPlusWatermarkQr.write(ba1, 0, baLength); } } catch (Exception e) { } finally { is1.close(); biosPlusWatermarkQr.close(); } PdfStamper stamp = new PdfStamper(reader, biosPlusWatermarkQr, '\0', false); int i = 0; PdfContentByte under; Image img = Image.getInstance(image); img.setTransparency(new int[] { 0x00, 0x10 }); img.setAbsolutePosition(0, 0); while (i < n) { i++; under = stamp.getOverContent(i); under.addImage(img); } stamp.close(); amedia = new AMedia("Dokumen", "pdf", "application/pdf", biosPlusWatermarkQr.toByteArray()); } catch (Exception e) { System.out.println("err qrcode:" + e); amedia = new AMedia("Dokumen", "pdf", "application/pdf", bios.toByteArray()); } report.setContent(amedia); } catch (Exception e) { System.out.println("url tidak dapat diakses"); } }