List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(Image image)
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 ww w .j a v a 2 s .com 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.PdfCoreReport.java
License:Apache License
private void writeGraphDetails() throws IOException, DocumentException { if (collector.isStopped()) { return;// w w w.j a v a 2 s . c om } final PdfPTable jrobinTable = new PdfPTable(1); jrobinTable.setHorizontalAlignment(Element.ALIGN_CENTER); jrobinTable.setWidthPercentage(100); jrobinTable.getDefaultCell().setBorder(0); if (largeGraphs != null) { // si les graphiques ont t prinitialiss (en Swing) alors on les utilise for (final byte[] imageData : largeGraphs.values()) { final Image image = Image.getInstance(imageData); jrobinTable.addCell(image); } } else { final Collection<JRobin> counterJRobins = collector.getDisplayedCounterJRobins(); if (counterJRobins.isEmpty()) { return; } for (final JRobin jrobin : counterJRobins) { // la hauteur de l'image est prvue pour qu'il n'y ait pas de graph seul sur une page final Image image = Image.getInstance(jrobin.graph(range, LARGE_GRAPH_WIDTH, LARGE_GRAPH_HEIGHT)); jrobinTable.addCell(image); } } newPage(); addToDocument(jrobinTable); newPage(); }
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 {//from w ww. jav a 2 s .c om final byte[] img = jrobin.graph(range, 100, 50); final Image image = Image.getInstance(img); image.scalePercent(50); addCell(image); } }
From source file:net.bull.javamelody.internal.web.pdf.PdfDocumentFactory.java
License:Apache License
static Image getImage(String resourceFileName) throws BadElementException, IOException { return Image .getInstance(PdfDocumentFactory.class.getResource(Parameters.getResourcePath(resourceFileName))); }
From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java
License:Apache License
private void writeGraph() throws IOException, DocumentException { final JRobin jrobin = collector.getJRobin(graphName); if (jrobin != null) { final byte[] img = jrobin.graph(range, 960, 400); final Image image = Image.getInstance(img); image.scalePercent(50);// ww w. j av a 2 s .c o m final PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell("\n"); table.addCell(image); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(new Phrase(getString("graph_units"), cellFont)); addToDocument(table); } else { // just in case request is null and collector.getJRobin(graphName) is null, we must write something in the document addToDocument(new Phrase("\n", cellFont)); } }
From source file:net.bull.javamelody.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);// ww w . j a va 2 s . com return; } 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")); int i = 0; if (mySmallGraphs != null) { // si les graphiques ont t prinitialiss (en Swing) alors on les utilise for (final byte[] imageData : mySmallGraphs.values()) { 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(imageData); image.scalePercent(50); jrobinParagraph.add(new Phrase(new Chunk(image, 0, 0))); jrobinParagraph.add(new Phrase(" ")); i++; } } else { if (jrobins.isEmpty()) { return; } for (final JRobin jrobin : jrobins) { 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(jrobin.graph(range, SMALL_GRAPH_WIDTH, SMALL_GRAPH_HEIGHT)); 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.laubenberger.bogatyr.helper.HelperPdf.java
License:Open Source License
/** * Writes a PDF from multiple image files to a {@link File}. * /*from w w w . j a v a 2 s. c o m*/ * @param pageSize * of the PDF * @param scale * images to fit the page size * @param file * output as PDF * @param files * for the PDF * @throws DocumentException * @throws IOException * @see File * @see Rectangle * @since 0.9.2 */ public static void writePdfFromImages(final Rectangle pageSize, final boolean scale, final File file, final File... files) throws DocumentException, IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(pageSize, scale, file, files)); if (null == pageSize) { throw new RuntimeExceptionIsNull("pageSize"); //$NON-NLS-1$ } if (null == file) { throw new RuntimeExceptionIsNull("file"); //$NON-NLS-1$ } if (null == files) { throw new RuntimeExceptionIsNull("files"); //$NON-NLS-1$ } if (!HelperArray.isValid(files)) { throw new RuntimeExceptionIsEmpty("files"); //$NON-NLS-1$ } final Document document = new Document(pageSize); document.setMargins(0.0F, 0.0F, 0.0F, 0.0F); final FilterOutputStream fos = new BufferedOutputStream(new FileOutputStream(file)); try { PdfWriter.getInstance(document, fos); document.open(); for (final File inputFile : files) { if (null == inputFile) { throw new RuntimeExceptionIsNull("inputFile"); //$NON-NLS-1$ } final Image image = Image.getInstance(inputFile.getAbsolutePath()); if (scale) { image.scaleToFit(pageSize.getWidth(), pageSize.getHeight()); } document.add(image); document.newPage(); } } finally { document.close(); fos.close(); } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.laubenberger.wichtel.helper.HelperPdf.java
License:Open Source License
/** * Writes a PDF from multiple image files to a {@link File}. * /*from w w w . ja va2s . co m*/ * @param pageSize * of the PDF * @param scale * images to fit the page size * @param file * output as PDF * @param files * for the PDF * @throws DocumentException * @throws IOException * @see File * @see Rectangle * @since 0.0.1 */ public static void writePdfFromImages(final Rectangle pageSize, final boolean scale, final File file, final File... files) throws DocumentException, IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(pageSize, scale, file, files)); if (null == pageSize) { throw new RuntimeExceptionIsNull("pageSize"); //$NON-NLS-1$ } if (null == file) { throw new RuntimeExceptionIsNull("file"); //$NON-NLS-1$ } if (null == files) { throw new RuntimeExceptionIsNull("files"); //$NON-NLS-1$ } if (!HelperArray.isValid(files)) { throw new RuntimeExceptionIsEmpty("files"); //$NON-NLS-1$ } final Document document = new Document(pageSize); document.setMargins(0.0F, 0.0F, 0.0F, 0.0F); try (FilterOutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) { PdfWriter.getInstance(document, fos); document.open(); for (final File inputFile : files) { if (null == inputFile) { throw new RuntimeExceptionIsNull("inputFile"); //$NON-NLS-1$ } final Image image = Image.getInstance(inputFile.getAbsolutePath()); if (scale) { image.scaleToFit(pageSize.getWidth(), pageSize.getHeight()); } document.add(image); document.newPage(); } document.close(); } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.nosleep.superanalyzer.Share.java
License:Open Source License
public static void saveAnalysisPdf(JFrame window, Analysis analysis, JProgressBar progressBar) { File pdfFile = askForFile(window, "pdf"); if (pdfFile == null) return;// w ww.ja v a2s . co m Misc.printMemoryInfo("pdfstart"); DateFormat dateFormat = new SimpleDateFormat().getDateInstance(DateFormat.SHORT); String infoString = Misc.getString("CREATED_ON") + " " + dateFormat.format(Calendar.getInstance().getTime()); int viewCount = 15; int viewsDone = 0; progressBar.setMinimum(0); progressBar.setMaximum(viewCount); Dimension d = new Dimension(500, 400); try { String tmpPath = System.getProperty("java.io.tmpdir") + "/image.png"; // create the pdf document object Document document = new Document(); // create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileOutputStream(pdfFile)); // we open the document document.open(); Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.NORMAL, new Color(0x00, 0x00, 0x00)); Paragraph p = new Paragraph(Misc.getString("MY_MUSIC_COLLECTION"), titleFont); p.setSpacingAfter(4); document.add(p); Font subtitleFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x88, 0x88, 0x88)); p = new Paragraph("The Super Analyzer by Nosleep Software", subtitleFont); p.setSpacingAfter(-2); document.add(p); p = new Paragraph(infoString, subtitleFont); p.setSpacingAfter(30); document.add(p); PdfPTable table = new PdfPTable(2); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table.setTotalWidth(500f); table.setLockedWidth(true); Font statNameFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x66, 0x66, 0x66)); Font statValueFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x00, 0x00, 0x00)); Vector<StringTriple> statPairs = SummaryView.createStatPairs(analysis); Paragraph statParagraph = new Paragraph(); Font summaryTitleFont = FontFactory.getFont(FontFactory.HELVETICA, 11, Font.BOLD, new Color(0x00, 0x00, 0x00)); Paragraph titleParagraph = new Paragraph(Misc.getString("SUMMARY"), summaryTitleFont); statParagraph.add(titleParagraph); Paragraph spaceParagraph = new Paragraph("", statNameFont); statParagraph.add(spaceParagraph); for (int i = 0; i < statPairs.size(); i++) { Paragraph statLine = new Paragraph(); StringTriple triple = statPairs.elementAt(i); Phrase namePhrase = new Phrase(triple.Name + ": ", statNameFont); Phrase valuePhrase = new Phrase(triple.Value, statValueFont); statLine.add(namePhrase); statLine.add(valuePhrase); statParagraph.add(statLine); } table.addCell(statParagraph); viewsDone++; progressBar.setValue(viewsDone); GenreView genreView = new GenreView(analysis); genreView.saveImage(new File(tmpPath), d); genreView = null; Image img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); LikesView likesView = new LikesView(analysis); likesView.saveImage(new File(tmpPath), d); likesView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); YearView yearView = new YearView(analysis); yearView.saveImage(new File(tmpPath), d); yearView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); RatingView ratingView = new RatingView(analysis); ratingView.saveImage(new File(tmpPath), d); ratingView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); TimeView timeView = new TimeView(analysis); timeView.saveImage(new File(tmpPath), d); timeView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); QualityView qualityView = new QualityView(analysis); qualityView.saveImage(new File(tmpPath), d); qualityView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); PlayCountView playCountView = new PlayCountView(analysis); playCountView.saveImage(new File(tmpPath), d); playCountView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); MostPlayedAAView mostPlayedAAView = new MostPlayedAAView(analysis); mostPlayedAAView.saveImage(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedAAView.saveImageExtra(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedAAView = null; viewsDone++; progressBar.setValue(viewsDone); MostPlayedDGView mostPlayedDGView = new MostPlayedDGView(analysis); mostPlayedDGView.saveImage(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedDGView.saveImageExtra(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedDGView = null; viewsDone++; progressBar.setValue(viewsDone); EncodingKindView encodingKindView = new EncodingKindView(analysis); encodingKindView.saveImage(new File(tmpPath), d); encodingKindView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); GrowthView growthView = new GrowthView(analysis); growthView.saveImage(new File(tmpPath), d); growthView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); WordView wordView = new WordView(analysis); wordView.saveImage(new File(tmpPath), d); wordView = null; img = Image.getInstance(tmpPath); table.addCell(img); table.addCell(""); viewsDone++; progressBar.setValue(viewsDone); Misc.printMemoryInfo("pdfend"); document.add(table); // step 5: we close the document document.close(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }
From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java
License:LGPL
/** * *///www . j a va 2 s. c o m protected Image getPxImage() { if (pxImage == null) { try { pxImage = Image.getInstance( JRLoader.loadBytesFromLocation("net/sf/jasperreports/engine/images/pixel.GIF", null)); } catch (Exception e) { throw new JRRuntimeException(e); } } return pxImage; }