List of usage examples for com.lowagie.text Image scalePercent
public void scalePercent(float percent)
From source file:it.eng.spagobi.engines.exporters.ChartExporter.java
License:Mozilla Public License
/** check if the image has to be turned or resize * /*from ww w .java2s . co m*/ * @param document * @param jpg * @return if the image has been turned */ public void changeLayout(Document pdfDocument, Image jpg, float width, float height) { logger.debug("IN"); // if width is more than 600 and height is not more it suffices to turn the image of the chart if (width > MAX_WIDTH && !(height > MAX_WIDTH) && !(width > MAX_HEIGHT)) { pdfDocument.setPageSize(PageSize.LETTER.rotate()); logger.debug("pdf rotation"); } else { // otherwise the chart needs to be scaled (if width > height also turn!) // SCALED WITH turning if (width > height) { pdfDocument.setPageSize(PageSize.LETTER.rotate()); // calculate wich size is to reduce most: float percentageToReduceHeight = 0; float percentageToReduceWidth = 0; if (height > MAX_WIDTH) { percentageToReduceHeight = (height * 100) / MAX_WIDTH; } if (width > MAX_HEIGHT) { percentageToReduceWidth = (width * 100) / MAX_HEIGHT; } float percToReduce = percentageToReduceHeight > percentageToReduceWidth ? percentageToReduceHeight : percentageToReduceWidth; float percToScale = percToReduce - 100; // float newHeight = height - ((height/100)*percToReduce); // float newWidth = width - ((width/100)*percToReduce); logger.debug("pdf scale of percentage " + percToScale); jpg.scalePercent(percToScale); logger.debug("pdf rotation and scaling"); } else { // SCALED WITHOUT turning // calculate wich size is to reduce most: float percentageToReduceHeight = 0; float percentageToReduceWidth = 0; if (height > MAX_HEIGHT) { percentageToReduceHeight = (height * 100) / MAX_HEIGHT; } if (width > MAX_WIDTH) { percentageToReduceWidth = (width * 100) / MAX_WIDTH; } float percToReduce = percentageToReduceHeight > percentageToReduceWidth ? percentageToReduceHeight : percentageToReduceWidth; float percToScale = percToReduce - 100; // float newHeight = height - ((height/100)*percToReduce); // float newWidth = width - ((width/100)*percToReduce); logger.debug("pdf scale of percentage " + percToScale); jpg.scalePercent(percToScale); logger.debug("pdf scaling"); } } logger.debug("OUT"); }
From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetPDFExporter.java
License:Mozilla Public License
private float[] fitImage(Image jpg, float maxWidth, float maxHeight) { float newWidth = jpg.getWidth(); float newHeight = jpg.getHeight(); if (jpg.getWidth() > maxWidth) { newWidth = maxWidth;/*from w ww .j a v a2s .co m*/ newHeight = (newWidth / jpg.getWidth()) * jpg.getHeight(); jpg.scalePercent(newWidth * 100 / jpg.getWidth()); } if (jpg.getHeight() > maxHeight) { newHeight = maxHeight; newWidth = (newHeight / jpg.getHeight()) * jpg.getWidth(); jpg.scalePercent(newHeight * 100 / jpg.getHeight()); } float[] toReturn = new float[] { newWidth, newHeight }; return toReturn; }
From source file:jm.seg.frmGeneraPdf.java
License:GNU General Public License
private Image getBarcode(PdfWriter pdfWriter, String codigo) { PdfContentByte cimg = pdfWriter.getDirectContent(); Barcode128 code128 = new Barcode128(); code128.setCode(codigo);// w w w . jav a2 s . c o m code128.setCodeType(Barcode128.CODE128); code128.setTextAlignment(Element.ALIGN_CENTER); Image image = code128.createImageWithBarcode(cimg, null, null); //float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin() - 0) / image.getWidth()) * 70; //image.scalePercent(scaler); //image.scaleAbsolute(90f, 35f); image.scalePercent(90f); image.setAlignment(Element.ALIGN_CENTER); return image; }
From source file:jp.ac.utokyo.rcast.karkinos.graph.output.PdfReport.java
License:Apache License
private static void addObj(Document document, Object obj, int width, int hight, int size, PdfWriter writer, int figcount) throws Exception, IOException { if (obj instanceof JFreeChart) { JFreeChart chart = (JFreeChart) obj; BufferedImage bufferedImage = chart.createBufferedImage(width * size, hight * size); Image image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20); image.setAnnotation(new Annotation("fig" + figcount, "karkinos fig" + figcount)); document.add(image);// w w w.ja va 2 s . c om } else if (obj instanceof Element) { document.add((Element) obj); } else if (obj instanceof java.awt.Image) { java.awt.Image aim = (java.awt.Image) obj; Image image = Image.getInstance(writer, aim, 1.0f); image.scalePercent(50); document.add(image); } else { document.add(new Paragraph(String.valueOf(obj))); } }
From source file:jp.ac.utokyo.rcast.karkinos.summary.RegionGraph.java
License:Apache License
/** * @param args//from w ww .j a v a 2 s. c om */ public static void main(String[] args) { String indir = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_rcast," + "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_NCC/karkinosver4.0.25," + "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_baylor/HCC-JP-453-T-HCC-JP-453-N/HCC-JP-453-T-HCC-JP-453-N," + "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/tcga," + "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/goss,"; // // String indir = // "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_rcast/THCC_167T-THCC_167N/THCC_167T-THCC_167N/"; String out = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/chr5Graprh.pdf"; String outpng = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/chr1Graprh.jpeg"; List<File> list = new ArrayList<File>(); for (String s : indir.split(",")) { File f = new File(s); // chage to reccursive file search searchRecursive(f, list); } String chr = "chr5"; int start = 0; int end = 50000000; // String chr = "chr11"; // int start = 0; // int end = 135000000; // String chr = "chr1"; // int start = 0; // int end = 247000000; int[][] target = new int[][] { { 1278756, 1295162 } }; Document document = null; PdfWriter writer = null; int width = 1200; int hight = 500; int size = 1; try { FileOutputStream fileOutputStream = new FileOutputStream(out); document = new Document(); writer = PdfWriter.getInstance(document, fileOutputStream); document.open(); for (File f : list) { document.add(new Paragraph(String.valueOf(f.getName()))); Object[] obj = getChart(f, chr, start, end, target); document.add(new Paragraph("mean=" + toStr(obj[1]) + "\t mean original=" + toStr(obj[2]))); JFreeChart chart = (JFreeChart) obj[0]; // try { // File jpn = new File(outpng); // ChartUtilities.saveChartAsJPEG(jpn, chart, 300, 300); // // } catch (Exception ex) { // // } BufferedImage bufferedImage = chart.createBufferedImage(width * size, hight * size); Image image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20); document.add(image); } document.close(); document = null; writer.close(); writer = null; } catch (Exception e) { e.printStackTrace(); } finally { // release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:jp.ac.utokyo.rcast.karkinos.summary.RegionGraph2.java
License:Apache License
/** * @param args// w w w. j ava2 s . c o m */ public static void main(String[] args) { String indir = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_rcast," + "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_NCC/karkinosver4.0.25," + "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_baylor/HCC-JP-453-T-HCC-JP-453-N/HCC-JP-453-T-HCC-JP-453-N," + "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/tcga," + "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/goss,"; // // String indir = // "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_rcast/THCC_167T-THCC_167N/THCC_167T-THCC_167N/"; String out = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/chr4allelicGraprh.pdf"; // String outpng = // "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/chr1Graprh.jpeg"; List<File> list = new ArrayList<File>(); for (String s : indir.split(",")) { File f = new File(s); // chage to reccursive file search searchRecursive(f, list); } // String chr = "chr5"; // int start = 0; // int end = 300000; // String chr = "chr11"; // int start = 0; // int end = 135000000; String chr = "chr4"; int start = 0; int end = 247000000; int[][] target = new int[][] { { 190328975, 190903950 } }; Document document = null; PdfWriter writer = null; int width = 1200; int hight = 500; int size = 1; try { FileOutputStream fileOutputStream = new FileOutputStream(out); document = new Document(); writer = PdfWriter.getInstance(document, fileOutputStream); document.open(); for (File f : list) { document.add(new Paragraph(String.valueOf(f.getName()))); Object[] obj = getChart(f, chr, start, end, target, 1); document.add(new Paragraph("mean=" + toStr(obj[1]) + "\t mean original=" + toStr(obj[2]))); JFreeChart chart = (JFreeChart) obj[0]; // try { // File jpn = new File(outpng); // ChartUtilities.saveChartAsJPEG(jpn, chart, 300, 300); // // } catch (Exception ex) { // // } BufferedImage bufferedImage = chart.createBufferedImage(width * size, hight * size); Image image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20); document.add(image); obj = getChart(f, chr, start, end, target, 2); chart = (JFreeChart) obj[0]; // try { // File jpn = new File(outpng); // ChartUtilities.saveChartAsJPEG(jpn, chart, 300, 300); // // } catch (Exception ex) { // // } bufferedImage = chart.createBufferedImage(width * size, hight * size); image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20); document.add(image); } document.close(); document = null; writer.close(); writer = null; } catch (Exception e) { e.printStackTrace(); } finally { // release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:jp.ac.utokyo.rcast.karkinos.summary.TextToGraph.java
License:Apache License
/** * @param args//www . j a v a 2 s .c o m */ public static void main(String[] args) { // String s = // "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/TCGA-MR-A520-01A-11D-A25V-10.vs-10_cnvAllelicDepth.txt"; // String s2 = // "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/TCGA-MR-A520-01A-11D-A25V-10.vs-10_cnvdepth.txt"; // String sout = "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/out.pdf"; String s = "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/HCC-JP-468-T.vs-N_cnvAllelicDepth.txt"; String s2 = "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/HCC-JP-468-T.vs-N_cnvdepth.txt"; String sout = "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/468out.pdf"; Document document = null; PdfWriter writer = null; // try { int width = 1200; int hight = 500; int size = 1; FileOutputStream fileOutputStream = new FileOutputStream(sout); document = new Document(); writer = PdfWriter.getInstance(document, fileOutputStream); document.open(); JFreeChart chart0 = getChart(new File(s2), 0); JFreeChart chart1 = getChart(new File(s2), 1); JFreeChart chart2 = getChart(new File(s2), 2); JFreeChart chart3 = getChart(new File(s2), 3); JFreeChart chart4 = getChart(new File(s), 4); JFreeChart chart5 = getChart(new File(s), 5); JFreeChart chart6 = getChart(new File(s), 6); BufferedImage bufferedImage = chart0.createBufferedImage(width * size, hight * size); Image image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20); document.add(image); BufferedImage bufferedImage1 = chart1.createBufferedImage(width * size, hight * size); Image image1 = Image.getInstance(writer, bufferedImage1, 1.0f); image1.scalePercent(20); document.add(image1); BufferedImage bufferedImage2 = chart2.createBufferedImage(width * size, hight * size); Image image2 = Image.getInstance(writer, bufferedImage2, 1.0f); image2.scalePercent(20); document.add(image2); BufferedImage bufferedImage3 = chart3.createBufferedImage(width * size, hight * size); Image image3 = Image.getInstance(writer, bufferedImage3, 1.0f); image3.scalePercent(20); document.add(image3); BufferedImage bufferedImage4 = chart4.createBufferedImage(width * size, hight * size); Image image4 = Image.getInstance(writer, bufferedImage4, 1.0f); image4.scalePercent(20); document.add(image4); BufferedImage bufferedImage5 = chart5.createBufferedImage(width * size, hight * size); Image image5 = Image.getInstance(writer, bufferedImage5, 1.0f); image5.scalePercent(20); document.add(image5); BufferedImage bufferedImage6 = chart6.createBufferedImage(width * size, hight * size); Image image6 = Image.getInstance(writer, bufferedImage6, 1.0f); image6.scalePercent(20); document.add(image6); document.close(); document = null; writer.close(); writer = null; } catch (Exception e) { e.printStackTrace(); } finally { // release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:managedbean.afos.FlightDutyBacking.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();// www . j a v a 2 s. c o m pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "logo.png"; Image logoImg = Image.getInstance(logo); logoImg.scalePercent(20f); SimpleDateFormat sdf = new SimpleDateFormat("E, dd/MM/yyyy 'at' hh:mm:ss a"); Font titleFont = new Font(); Font subtitleFont = new Font(); titleFont.setSize(16); titleFont.setStyle(Font.BOLD); subtitleFont.setSize(12); subtitleFont.setStyle(Font.BOLD); Paragraph title = new Paragraph(flightReport.getType() + " Duty Report", titleFont); title.setAlignment(Element.ALIGN_CENTER); title.setSpacingAfter(12f); Paragraph subTitle1 = new Paragraph("Flight Information:", subtitleFont); subTitle1.setSpacingAfter(8f); Paragraph subTitle2 = new Paragraph(flightReport.getType() + " Checklist:", subtitleFont); subTitle2.setSpacingBefore(12f); subTitle2.setSpacingAfter(12f); com.lowagie.text.List list = new com.lowagie.text.List(true, 15); list.setLettered(true); list.add("Flight: " + selectedFlightSchedule.getFlight().getFlightNo()); list.add("Return Flight: " + selectedFlightSchedule.getFlight().getReturnedFlight().getFlightNo()); Airport departure, arrival; departure = selectedFlightSchedule.getLeg().getDepartAirport(); arrival = selectedFlightSchedule.getLeg().getArrivalAirport(); sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(departure))); list.add("Departure Time: " + sdf.format(selectedFlightSchedule.getDepartDate()) + " (" + departure.getCity().getCityName() + " Time)"); sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(arrival))); list.add("Arrival Time: " + sdf.format(selectedFlightSchedule.getArrivalDate()) + " (" + arrival.getCity().getCityName() + " Time)"); list.add("Origin: " + departure.getCity().getCityName() + " (" + departure.getAirportName() + ")"); list.add("Destination: " + arrival.getCity().getCityName() + " (" + arrival.getAirportName() + ")"); pdf.add(logoImg); pdf.add(new Paragraph(" ")); pdf.add(title); pdf.add(subTitle1); pdf.add(list); pdf.add(subTitle2); pdf.setMargins(72, 72, 72, 72); pdf.addAuthor("Merlion Airline"); pdf.addCreationDate(); sdf.applyPattern("dd/MM/yyyy_hh:mm:ss"); pdf.addTitle("Post-Flight Duty Report_" + selectedFlightSchedule.getFlight().getFlightNo() + "_" + sdf.format(selectedFlightSchedule.getDepartDate())); }
From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java
License:Apache License
private void writeGraphs(Collection<JRobin> jrobins, Map<String, byte[]> mySmallGraphs) throws IOException, DocumentException { if (collector.isStopped()) { // pas de graphs, ils seraient en erreur sans timer // mais un message d'avertissement la place final String message = getString("collect_server_misusage"); final Paragraph jrobinParagraph = new Paragraph(message, PdfFonts.BOLD.getFont()); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); addToDocument(jrobinParagraph);//from w ww . j av a2 s. c o m return; } if (collector.isStorageUsedByMultipleInstances()) { final String message = getString("storage_used_by_multiple_instances") + "\n\n"; final Paragraph jrobinParagraph = new Paragraph(message, PdfFonts.BOLD.getFont()); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); addToDocument(jrobinParagraph); } final Paragraph jrobinParagraph = new Paragraph("", FontFactory.getFont(FontFactory.HELVETICA, 9f, Font.NORMAL)); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); jrobinParagraph.add(new Phrase("\n\n\n\n")); final Collection<byte[]> graphs; if (mySmallGraphs != null) { // si les graphiques ont t prinitialiss (en Swing) alors on les utilise graphs = mySmallGraphs.values(); } else { if (jrobins.isEmpty()) { return; } graphs = new ArrayList<byte[]>(jrobins.size()); for (final JRobin jrobin : jrobins) { graphs.add(jrobin.graph(range, SMALL_GRAPH_WIDTH, SMALL_GRAPH_HEIGHT)); } } int i = 0; for (final byte[] graph : graphs) { if (i % 3 == 0 && i != 0) { // un retour aprs httpSessions et avant activeThreads pour l'alignement jrobinParagraph.add(new Phrase("\n\n\n\n\n")); } final Image image = Image.getInstance(graph); image.scalePercent(50); jrobinParagraph.add(new Phrase(new Chunk(image, 0, 0))); jrobinParagraph.add(new Phrase(" ")); i++; } jrobinParagraph.add(new Phrase("\n")); addToDocument(jrobinParagraph); }
From source file:net.bull.javamelody.internal.web.pdf.PdfCounterReport.java
License:Apache License
private void writeRequestGraph(CounterRequest request) throws BadElementException, IOException { final JRobin jrobin = collector.getJRobin(request.getId()); if (jrobin == null) { addCell(""); } else {/* w w w . j ava 2 s .c o m*/ final byte[] img = jrobin.graph(range, 100, 50); final Image image = Image.getInstance(img); image.scalePercent(50); addCell(image); } }