List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(java.awt.Image image, java.awt.Color color) throws BadElementException, IOException
From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java
License:Open Source License
public Image getImage() { BitMatrix barcode = getQRCodeMatrix(); BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(barcode); // ZXing now has MatrixToImageWriter to avoid looping through byte arrays. // byte[][] bca = barcode.getArray(); // byte[] data = new byte[200*4*200*4]; // int z=0; // for (int x=0; x<200; x++) { // for (int y=0; y<200; y++) { // data[z++] = bca[x][y]; // }//from ww w . j ava 2s . c om // } // Image image = null; // try { // image = Image.getInstance(200, 200, 1, 8, data); // image.scalePercent(50f); // } catch (BadElementException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // data = null; Image image = null; try { image = Image.getInstance(bufferedImage, null); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return image; }
From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java
License:Open Source License
/** * method to create PDF/*from w ww.ja v a 2s.c o m*/ * @param adminUser The admin user * @param locale The locale * @param strNameFile PDF name * @param out OutputStream * @param nIdRecord the id record * @param listIdEntryConfig list of config id entry * @param bExtractNotFilledField if true, extract empty fields, false */ public static void doCreateDocumentPDF(AdminUser adminUser, Locale locale, String strNameFile, OutputStream out, int nIdRecord, List<Integer> listIdEntryConfig, Boolean bExtractNotFilledField) { Document document = new Document(PageSize.A4); Plugin plugin = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME); EntryFilter filter; Record record = RecordHome.findByPrimaryKey(nIdRecord, plugin); filter = new EntryFilter(); filter.setIdDirectory(record.getDirectory().getIdDirectory()); filter.setIsGroup(EntryFilter.FILTER_TRUE); List<IEntry> listEntry = DirectoryUtils.getFormEntries(record.getDirectory().getIdDirectory(), plugin, adminUser); int nIdDirectory = record.getDirectory().getIdDirectory(); Directory directory = DirectoryHome.findByPrimaryKey(nIdDirectory, plugin); try { PdfWriter.getInstance(document, out); } catch (DocumentException e) { AppLogService.error(e); } document.open(); if (record.getDateCreation() != null) { SimpleDateFormat monthDayYearformatter = new SimpleDateFormat( AppPropertiesService.getProperty(PROPERTY_POLICE_FORMAT_DATE)); Font fontDate = new Font( DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)), DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_DATE)), DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_DATE))); Paragraph paragraphDate = new Paragraph( new Phrase(monthDayYearformatter.format(record.getDateCreation()).toString(), fontDate)); paragraphDate.setAlignment(DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_ALIGN_DATE))); try { document.add(paragraphDate); } catch (DocumentException e) { AppLogService.error(e); } } Image image; try { image = Image.getInstance(ImageIO.read(new File(AppPathService .getAbsolutePathFromRelativePath(AppPropertiesService.getProperty(PROPERTY_IMAGE_URL)))), null); image.setAlignment( DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_IMAGE_ALIGN))); float fitWidth; float fitHeight; try { fitWidth = Float.parseFloat(AppPropertiesService.getProperty(PROPERTY_IMAGE_FITWIDTH)); fitHeight = Float.parseFloat(AppPropertiesService.getProperty(PROPERTY_IMAGE_FITHEIGHT)); } catch (NumberFormatException e) { fitWidth = 100f; fitHeight = 100f; } image.scaleToFit(fitWidth, fitHeight); try { document.add(image); } catch (DocumentException e) { AppLogService.error(e); } } catch (BadElementException e) { AppLogService.error(e); } catch (MalformedURLException e) { AppLogService.error(e); } catch (IOException e) { AppLogService.error(e); } directory.getTitle(); Font fontTitle = new Font( DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)), DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_TITLE_DIRECTORY)), DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_TITLE_DIRECTORY))); fontTitle.isUnderlined(); Paragraph paragraphHeader = new Paragraph(new Phrase(directory.getTitle(), fontTitle)); paragraphHeader.setAlignment(Element.ALIGN_CENTER); paragraphHeader.setSpacingBefore(DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_BEFORE_TITLE_DIRECTORY))); paragraphHeader.setSpacingAfter(DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_AFTER_TITLE_DIRECTORY))); try { document.add(paragraphHeader); } catch (DocumentException e) { AppLogService.error(e); } builderPDFWithEntry(document, plugin, nIdRecord, listEntry, listIdEntryConfig, locale, bExtractNotFilledField); document.close(); }
From source file:mpv5.utils.export.PDFFile.java
License:Open Source License
private void setImage(PdfStamper stamper, String key, java.awt.Image oimg) { try {// w w w . j a v a2 s. c o m Log.Debug(this, "Write Image.." + key); float[] photograph = acroFields.getFieldPositions(key); Rectangle rect = new Rectangle(photograph[1], photograph[2], photograph[3], photograph[4]); Image img = Image.getInstance(oimg, null); img.setAbsolutePosition(photograph[1] + (rect.getWidth() - img.getScaledWidth()) / 2, photograph[2] + (rect.getHeight() - img.getScaledHeight()) / 2); PdfContentByte cb = stamper.getOverContent((int) photograph[0]); cb.addImage(img); } catch (Exception iOException) { Log.Debug(iOException); } }
From source file:net.bull.javamelody.internal.web.pdf.PdfJavaInformationsReport.java
License:Apache License
private void writeSummary(JavaInformations javaInformations) throws BadElementException, IOException { addCell(getString("Host") + ':'); currentTable.addCell(new Phrase(javaInformations.getHost(), boldCellFont)); addCell(getString("memoire_utilisee") + ':'); final MemoryInformations memoryInformations = javaInformations.getMemoryInformations(); final long usedMemory = memoryInformations.getUsedMemory(); final long maxMemory = memoryInformations.getMaxMemory(); final Phrase memoryPhrase = new Phrase( integerFormat.format(usedMemory / 1024 / 1024) + ' ' + getString("Mo") + DIVIDE + integerFormat.format(maxMemory / 1024 / 1024) + ' ' + getString("Mo") + BAR_SEPARATOR, cellFont);/* w w w . j a v a 2 s. c o m*/ final Image memoryImage = Image .getInstance(Bar.toBarWithAlert(memoryInformations.getUsedMemoryPercentage()), null); memoryImage.scalePercent(50); memoryPhrase.add(new Chunk(memoryImage, 0, 0)); currentTable.addCell(memoryPhrase); if (javaInformations.getSessionCount() >= 0) { addCell(getString("nb_sessions_http") + ':'); addCell(integerFormat.format(javaInformations.getSessionCount())); } addCell(getString("nb_threads_actifs") + "\n(" + getString("Requetes_http_en_cours") + "):"); addCell(integerFormat.format(javaInformations.getActiveThreadCount())); if (!noDatabase) { addCell(getString("nb_connexions_actives") + ':'); addCell(integerFormat.format(javaInformations.getActiveConnectionCount())); addCell(getString("nb_connexions_utilisees") + "\n(" + getString("ouvertes") + "):"); final int usedConnectionCount = javaInformations.getUsedConnectionCount(); final int maxConnectionCount = javaInformations.getMaxConnectionCount(); if (maxConnectionCount <= 0) { addCell(integerFormat.format(usedConnectionCount)); } else { final Phrase usedConnectionCountPhrase = new Phrase(integerFormat.format(usedConnectionCount) + DIVIDE + integerFormat.format(maxConnectionCount) + BAR_SEPARATOR, cellFont); final Image usedConnectionCountImage = Image .getInstance(Bar.toBarWithAlert(javaInformations.getUsedConnectionPercentage()), null); usedConnectionCountImage.scalePercent(50); usedConnectionCountPhrase.add(new Chunk(usedConnectionCountImage, 0, 0)); currentTable.addCell(usedConnectionCountPhrase); } } if (javaInformations.getSystemLoadAverage() >= 0) { addCell(getString("Charge_systeme") + ':'); addCell(decimalFormat.format(javaInformations.getSystemLoadAverage())); } if (javaInformations.getSystemCpuLoad() >= 0) { addCell(getString("systemCpuLoad") + ':'); final Phrase systemCpuLoadPhrase = new Phrase( decimalFormat.format(javaInformations.getSystemCpuLoad()) + BAR_SEPARATOR, cellFont); final Image systemCpuLoadImage = Image .getInstance(Bar.toBarWithAlert(javaInformations.getSystemCpuLoad()), null); systemCpuLoadImage.scalePercent(50); systemCpuLoadPhrase.add(new Chunk(systemCpuLoadImage, 0, 0)); currentTable.addCell(systemCpuLoadPhrase); } }
From source file:net.bull.javamelody.internal.web.pdf.PdfJavaInformationsReport.java
License:Apache License
private void writeFileDescriptorCounts(JavaInformations javaInformations) throws BadElementException, IOException { final long unixOpenFileDescriptorCount = javaInformations.getUnixOpenFileDescriptorCount(); final long unixMaxFileDescriptorCount = javaInformations.getUnixMaxFileDescriptorCount(); addCell(getString("nb_fichiers") + ':'); final Phrase fileDescriptorCountPhrase = new Phrase(integerFormat.format(unixOpenFileDescriptorCount) + DIVIDE + integerFormat.format(unixMaxFileDescriptorCount) + BAR_SEPARATOR, cellFont); final Image fileDescriptorCountImage = Image .getInstance(Bar.toBarWithAlert(javaInformations.getUnixOpenFileDescriptorPercentage()), null); fileDescriptorCountImage.scalePercent(50); fileDescriptorCountPhrase.add(new Chunk(fileDescriptorCountImage, 0, 0)); currentTable.addCell(fileDescriptorCountPhrase); }
From source file:net.bull.javamelody.internal.web.pdf.PdfJavaInformationsReport.java
License:Apache License
private void writeTomcatInformations(List<TomcatInformations> tomcatInformationsList) throws BadElementException, IOException { for (final TomcatInformations tomcatInformations : tomcatInformationsList) { if (tomcatInformations.getRequestCount() <= 0) { continue; }//from w w w. j av a2s. c o m addCell("Tomcat " + tomcatInformations.getName() + ':'); // rq: on n'affiche pas pour l'instant getCurrentThreadCount final int currentThreadsBusy = tomcatInformations.getCurrentThreadsBusy(); final String equal = " = "; final Phrase phrase = new Phrase( getString("busyThreads") + equal + integerFormat.format(currentThreadsBusy) + DIVIDE + integerFormat.format(tomcatInformations.getMaxThreads()) + BAR_SEPARATOR, cellFont); final Image threadsImage = Image.getInstance( Bar.toBarWithAlert(100d * currentThreadsBusy / tomcatInformations.getMaxThreads()), null); threadsImage.scalePercent(50); phrase.add(new Chunk(threadsImage, 0, 0)); phrase.add(new Chunk('\n' + getString("bytesReceived") + equal + integerFormat.format(tomcatInformations.getBytesReceived()) + '\n' + getString("bytesSent") + equal + integerFormat.format(tomcatInformations.getBytesSent()) + '\n' + getString("requestCount") + equal + integerFormat.format(tomcatInformations.getRequestCount()) + '\n' + getString("errorCount") + equal + integerFormat.format(tomcatInformations.getErrorCount()) + '\n' + getString("processingTime") + equal + integerFormat.format(tomcatInformations.getProcessingTime()) + '\n' + getString("maxProcessingTime") + equal + integerFormat.format(tomcatInformations.getMaxTime()))); currentTable.addCell(phrase); } }
From source file:net.bull.javamelody.internal.web.pdf.PdfJavaInformationsReport.java
License:Apache License
private void writeMemoryInformations(MemoryInformations memoryInformations) throws BadElementException, IOException { addCell(memoryInformations.getMemoryDetails().replace(" Mo", ' ' + getString("Mo"))); final long usedPermGen = memoryInformations.getUsedPermGen(); if (usedPermGen > 0) { // perm gen est 0 sous jrockit final long maxPermGen = memoryInformations.getMaxPermGen(); addCell(getString("Memoire_Perm_Gen") + ':'); if (maxPermGen > 0) { final Phrase permGenPhrase = new Phrase(integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo") + DIVIDE + integerFormat.format(maxPermGen / 1024 / 1024) + ' ' + getString("Mo") + BAR_SEPARATOR, cellFont); final Image permGenImage = Image .getInstance(Bar.toBarWithAlert(memoryInformations.getUsedPermGenPercentage()), null); permGenImage.scalePercent(50); permGenPhrase.add(new Chunk(permGenImage, 0, 0)); currentTable.addCell(permGenPhrase); } else {//from w w w. j ava 2 s .com addCell(integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo")); } } }
From source file:net.bull.javamelody.internal.web.pdf.PdfJobInformationsReport.java
License:Apache License
private void writeJobTimes(JobInformations jobInformations, CounterRequest counterRequest) throws BadElementException, IOException { final long elapsedTime = jobInformations.getElapsedTime(); if (elapsedTime >= 0) { final Phrase elapsedTimePhrase = new Phrase(durationFormat.format(elapsedTime), cellFont); final Image memoryImage = Image.getInstance(Bar.toBar(100d * elapsedTime / counterRequest.getMean()), null);//from w w w.j av a 2 s. c om memoryImage.scalePercent(47); elapsedTimePhrase.add("\n"); elapsedTimePhrase.add(new Chunk(memoryImage, 0, 0)); addCell(elapsedTimePhrase); } else { addCell(""); } if (jobInformations.getPreviousFireTime() != null) { addCell(fireTimeFormat.format(jobInformations.getPreviousFireTime())); } else { addCell(""); } if (jobInformations.getNextFireTime() != null) { addCell(fireTimeFormat.format(jobInformations.getNextFireTime())); } else { addCell(""); } // on n'affiche pas la priode si >= 1 jour car ce formateur ne saurait pas l'afficher if (jobInformations.getRepeatInterval() > 0 && jobInformations.getRepeatInterval() < ONE_DAY_MILLIS) { addCell(durationFormat.format(new Date(jobInformations.getRepeatInterval()))); } else if (jobInformations.getCronExpression() != null) { addCell(jobInformations.getCronExpression()); } else { addCell(""); } }
From source file:net.bull.javamelody.PdfJavaInformationsReport.java
License:Apache License
private void writeSummary(JavaInformations javaInformations) throws BadElementException, IOException { addCell(getString("Host") + ':'); currentTable.addCell(new Phrase(javaInformations.getHost(), boldCellFont)); addCell(getString("memoire_utilisee") + ':'); final MemoryInformations memoryInformations = javaInformations.getMemoryInformations(); final long usedMemory = memoryInformations.getUsedMemory(); final long maxMemory = memoryInformations.getMaxMemory(); final Phrase memoryPhrase = new Phrase( integerFormat.format(usedMemory / 1024 / 1024) + ' ' + getString("Mo") + DIVIDE + integerFormat.format(maxMemory / 1024 / 1024) + ' ' + getString("Mo") + BAR_SEPARATOR, cellFont);/*from w w w .j a v a2s . co m*/ final Image memoryImage = Image .getInstance(Bar.toBarWithAlert(memoryInformations.getUsedMemoryPercentage()), null); memoryImage.scalePercent(50); memoryPhrase.add(new Chunk(memoryImage, 0, 0)); currentTable.addCell(memoryPhrase); if (javaInformations.getSessionCount() >= 0) { addCell(getString("nb_sessions_http") + ':'); addCell(integerFormat.format(javaInformations.getSessionCount())); } addCell(getString("nb_threads_actifs") + "\n(" + getString("Requetes_http_en_cours") + "):"); addCell(integerFormat.format(javaInformations.getActiveThreadCount())); if (!noDatabase) { addCell(getString("nb_connexions_actives") + ':'); addCell(integerFormat.format(javaInformations.getActiveConnectionCount())); addCell(getString("nb_connexions_utilisees") + "\n(" + getString("ouvertes") + "):"); final int usedConnectionCount = javaInformations.getUsedConnectionCount(); final int maxConnectionCount = javaInformations.getMaxConnectionCount(); if (maxConnectionCount <= 0) { addCell(integerFormat.format(usedConnectionCount)); } else { final Phrase usedConnectionCountPhrase = new Phrase(integerFormat.format(usedConnectionCount) + DIVIDE + integerFormat.format(maxConnectionCount) + BAR_SEPARATOR, cellFont); final Image usedConnectionCountImage = Image .getInstance(Bar.toBarWithAlert(javaInformations.getUsedConnectionPercentage()), null); usedConnectionCountImage.scalePercent(50); usedConnectionCountPhrase.add(new Chunk(usedConnectionCountImage, 0, 0)); currentTable.addCell(usedConnectionCountPhrase); } } if (javaInformations.getSystemLoadAverage() >= 0) { addCell(getString("Charge_systeme") + ':'); addCell(decimalFormat.format(javaInformations.getSystemLoadAverage())); } }
From source file:net.laubenberger.bogatyr.helper.HelperPdf.java
License:Open Source License
/** * Writes a PDF from multiple {@link java.awt.Image} to a {@link File}. * /* ww w .j ava 2 s . com*/ * @param pageSize * of the PDF * @param scale * images to fit the page size * @param file * output as PDF * @param images * for the PDF * @throws DocumentException * @throws IOException * @see File * @see java.awt.Image * @see Rectangle * @since 0.9.2 */ public static void writePdfFromImages(final Rectangle pageSize, final boolean scale, final File file, final java.awt.Image... images) throws DocumentException, IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(pageSize, scale, file, images)); if (null == pageSize) { throw new RuntimeExceptionIsNull("pageSize"); //$NON-NLS-1$ } if (null == file) { throw new RuntimeExceptionIsNull("file"); //$NON-NLS-1$ } if (null == images) { throw new RuntimeExceptionIsNull("images"); //$NON-NLS-1$ } if (!HelperArray.isValid(images)) { throw new RuntimeExceptionIsEmpty("images"); //$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 java.awt.Image tempImage : images) { if (null == tempImage) { throw new RuntimeExceptionIsNull("tempImage"); //$NON-NLS-1$ } final Image image = Image.getInstance(tempImage, null); 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()); }