com.lowagie.text.BadElementException Java Examples

The following examples show how to use com.lowagie.text.BadElementException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RasterLayerComponentImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Add image in the document.
 *
 * @param context
 *            PDF context
 * @param imageResult
 *            image
 * @throws BadElementException
 *             PDF construction problem
 * @throws IOException
 *             PDF construction problem
 */
protected void addImage(PdfContext context, ImageResult imageResult) throws BadElementException, IOException {
	Bbox imageBounds = imageResult.getRasterImage().getBounds();
	float scaleFactor = (float) (72 / getMap().getRasterResolution());
	float width = (float) imageBounds.getWidth() * scaleFactor;
	float height = (float) imageBounds.getHeight() * scaleFactor;
	// subtract screen position of lower-left corner
	float x = (float) (imageBounds.getX() - rasterScale * bbox.getMinX()) * scaleFactor;
	// shift y to lowerleft corner, flip y to user space and subtract
	// screen position of lower-left
	// corner
	float y = (float) (-imageBounds.getY() - imageBounds.getHeight() - rasterScale * bbox.getMinY()) * scaleFactor;
	if (log.isDebugEnabled()) {
		log.debug("adding image, width=" + width + ",height=" + height + ",x=" + x + ",y=" + y);
	}
	// opacity
	log.debug("before drawImage");
	context.drawImage(Image.getInstance(imageResult.getImage()), new Rectangle(x, y, x + width, y + height),
			getSize(), getOpacity());
	log.debug("after drawImage");
}
 
Example #2
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
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 {
			addCell(integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo"));
		}
	}
}
 
Example #3
Source File: PdfJndiReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeJndiBinding(JndiBinding jndiBinding) throws BadElementException, IOException {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	final String name = jndiBinding.getName();
	final String className = jndiBinding.getClassName();
	final String contextPath = jndiBinding.getContextPath();
	final String value = jndiBinding.getValue();
	if (contextPath != null) {
		final Image image = getFolderImage();
		final Phrase phrase = new Phrase("", cellFont);
		phrase.add(new Chunk(image, 0, 0));
		phrase.add(new Chunk(" " + name));
		addCell(phrase);
	} else {
		addCell(name);
	}
	addCell(className != null ? className : "");
	addCell(value != null ? value : "");
}
 
Example #4
Source File: PdfCreator.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
Image cutImage(byte[] bytes, boolean cutImageHeight, boolean cutImageWidth, int tableHeight, int tableWidth, int imgWidth, int imgHeight)
		throws IOException, BadElementException {
	logger.debug("IN");

	BufferedImage image = null; // Read from a file
	BufferedImage region = null;

	int pxWidthToCut = (cutImageWidth == true) ? tableWidth : imgWidth;
	int pxHeightToCut = (cutImageHeight == true) ? tableHeight : imgHeight;

	InputStream inputStream = new ByteArrayInputStream(bytes);

	image = ImageIO.read(inputStream); // Read from an input stream
	try {
		region = image.getSubimage(0, 0, pxWidthToCut, pxHeightToCut);
	} catch (Exception e) {
		e.printStackTrace();
	}
	byte[] newBytes = getBytes(region);
	Image cutImg = Image.getInstance(newBytes);
	// ImageIO.write(region,"PNG",new File("C:/nuovaImmagine222.PNG"));
	logger.debug("OUT");

	return cutImg;
}
 
Example #5
Source File: PdfJobInformationsReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeJobInformations(JobInformations jobInformations)
		throws BadElementException, IOException {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	addCell(jobInformations.getGroup());
	addCell(jobInformations.getName());
	addCell(jobInformations.getJobClassName());
	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	final CounterRequest counterRequest = getCounterRequest(jobInformations);
	// counterRequest ne peut pas être null ici
	if (counterRequest.getMean() >= 0) {
		addCell(formatDuration(counterRequest.getMean()));
	} else {
		addCell("");
	}
	// rq: on n'affiche pas ici le nb d'exécutions, le maximum, l'écart-type
	// ou le pourcentage d'erreurs, uniquement car cela ferait trop de colonnes dans la page
	writeJobTimes(jobInformations, counterRequest);
	defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
	if (jobInformations.isPaused()) {
		addCell(getString("oui"));
	} else {
		addCell(getString("non"));
	}
}
 
Example #6
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Get the PDF Table containing trip information like trip id, date, and destination
 *
 * @returns {@link Table} used for a PDF
 */
protected Table getTripInfo() throws BadElementException {
    final Table retval = new Table(3);
    retval.setWidth(100f);
    retval.setBorder(NO_BORDER);
    retval.addCell(getHeaderCell("Trip/Event ID"));

    final Cell dateHeaderCell = getHeaderCell("Date");

    retval.addCell(dateHeaderCell);
    retval.addCell(getHeaderCell("Destination/Event Name"));
    retval.endHeaders();
    retval.addCell(getBorderlessCell(getTripId()));

    final Cell dateCell = getBorderlessCell(getDate());

    retval.addCell(dateCell);
    retval.addCell(getBorderlessCell(getDestination()));
    return retval;
}
 
Example #7
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Get the PDF Table with personal information about the initiator and traveler
 *
 * @returns {@link Table} used for a PDF
 */
protected Table getPersonalInfo() throws BadElementException {
    final Table retval = new Table(2);
    retval.setWidth(100f);
    retval.setBorder(NO_BORDER);
    retval.addCell(getHeaderCell("Traveler"));

    final Cell initiatorHeaderCell = getHeaderCell("Request Submitted By");

    retval.addCell(initiatorHeaderCell);
    retval.endHeaders();
    retval.addCell(getTravelerInfo());

    final Cell initiatorCell = getInitiatorInfo();

    retval.addCell(initiatorCell);
    return retval;
}
 
Example #8
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
public Table getExpenses() throws BadElementException {
    final Table retval = new Table(3);
    retval.setWidth(100f);
    retval.setBorder(NO_BORDER);
    retval.addCell(getHeaderCell("Expenses"));
    retval.addCell(getHeaderCell("Amount"));
    retval.addCell(getHeaderCell("Receipt Required?"));
    retval.endHeaders();

    for (final Map<String, String> expense : expenses) {
        retval.addCell(getBorderlessCell(expense.get("expenseType")));
        retval.addCell(getBorderlessCell(expense.get("amount")));
        retval.addCell(getBorderlessCell(expense.get("receipt")));
    }
    return retval;
}
 
Example #9
Source File: InvestmentSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
    Document pdf = (Document) document; 
    pdf.setPageSize(PageSize.A3); 
    pdf.open();  
     
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png";  
    Image image=Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image); 
    // add a couple of blank lines
       pdf.add( Chunk.NEWLINE );
       pdf.add( Chunk.NEWLINE );
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);;
    pdf.add(new Paragraph("Investment Summary",fontbold));
    // add a couple of blank lines
    pdf.add( Chunk.NEWLINE );
    pdf.add( Chunk.NEWLINE );
}
 
Example #10
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
    Document pdf = (Document) document;  
    pdf.setPageSize(PageSize.A3);
    pdf.open(); 
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png";  
    Image image=Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image); 
    // add a couple of blank lines
       pdf.add( Chunk.NEWLINE );
       pdf.add( Chunk.NEWLINE );
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);;
    pdf.add(new Paragraph("Account Summary",fontbold));
    // add a couple of blank lines
    pdf.add( Chunk.NEWLINE );
    pdf.add( Chunk.NEWLINE );
}
 
Example #11
Source File: TransactionSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void preProcessPDF(Object document) throws IOException,
		BadElementException, DocumentException {
	Document pdf = (Document) document;
	pdf.setPageSize(PageSize.A4);
	pdf.open();

	ServletContext servletContext = (ServletContext) FacesContext
			.getCurrentInstance().getExternalContext().getContext();
	String logo = servletContext.getRealPath("") + File.separator
			+ "resources" + File.separator + "images" + File.separator
			+ "logo" + File.separator + "logo.png";
	Image image = Image.getInstance(logo);
	image.scaleAbsolute(100f, 50f);
	pdf.add(image);
	// add a couple of blank lines
	pdf.add(Chunk.NEWLINE);
	pdf.add(Chunk.NEWLINE);
	Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
	fontbold.setColor(55, 55, 55);
	;
	pdf.add(new Paragraph("Transaction Summary", fontbold));
	// add a couple of blank lines
	pdf.add(Chunk.NEWLINE);
	pdf.add(Chunk.NEWLINE);
}
 
Example #12
Source File: PatchRtfTableTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testImportTableRemovesUnusedRow() throws BadElementException {
  Table table = Mockito.mock( Table.class );
  Row row = Mockito.mock( Row.class );
  RtfDocument rtfDocument = new RtfDocument();
  List<Row> rows = new ArrayList<>( 5 );
  for ( int i = 0; i < 5; i++ ) {
    rows.add( row );
  }
  Iterator<Row> iterator = rows.iterator();

  Mockito.when( table.iterator() ).thenReturn( iterator );

  new PatchRtfTable( rtfDocument, table );
  Assert.assertFalse( iterator.hasNext() );
  Assert.assertEquals( 0, rows.size() );
}
 
Example #13
Source File: BarcodeDatamatrix.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Gets an <CODE>Image</CODE> with the barcode. A successful call to the method
 * <CODE>generate()</CODE> before calling this method is required.
 * 
 * @return the barcode <CODE>Image</CODE>
 * @throws BadElementException on error
 */
public Image createImage() throws BadElementException {
	if (image == null) {
		return null;
	}
	byte g4[] = CCITTG4Encoder.compress(image, width + 2 * ws, height + 2 * ws);
	return Image.getInstance(width + 2 * ws, height + 2 * ws, false, Element.CCITTG4, 0, g4, null);
}
 
Example #14
Source File: ImageLayout.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * get intrinsic dimension of image in pixels. Now only support png, bmp,
 * jpg, gif.
 * 
 * @return
 * @throws IOException
 * @throws MalformedURLException
 * @throws BadElementException
 */
protected Dimension getIntrinsicDimension( IImageContent content,
		Image image ) throws BadElementException, MalformedURLException,
		IOException
{
	if ( image != null )
	{
		// The DPI resolution of the image.
		// the preference of the DPI setting is:
		// 1. the resolution restored in content.
		// 2. the resolution in image file.
		// 3. use the DPI in render options.
		// 4. the DPI in report designHandle.
		// 5. the JRE screen resolution.
		// 6. the default DPI (96).
		int contentResolution = content.getResolution( );
		if ( contentResolution != 0 )
		{
			resolutionX = contentResolution;
			resolutionY = contentResolution;
		}
		else
		{
			resolutionX = PropertyUtil.getImageDpi( content, image
					.getDpiX( ), context.getDpi( ) );
			resolutionY = PropertyUtil.getImageDpi( content, image
					.getDpiY( ), context.getDpi( ) );
		}
		return new Dimension( (int) ( image.getPlainWidth( ) * 1000
				/ resolutionX * 72 ), (int) ( image.getPlainHeight( ) * 1000
				/ resolutionY * 72 ) );
	}
	return null;
}
 
Example #15
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 5 votes vote down vote up
public void postProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
	 Document pdf = (Document) document; 
	 pdf.add( Chunk.NEWLINE );
	 Font fontbold = FontFactory.getFont("Times-Roman", 14, Font.BOLD);
	 pdf.add(new Paragraph("Disclaimer",fontbold));
	 pdf.add( Chunk.NEWLINE );
	 pdf.add(new Paragraph("The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice."));
	 pdf.add(new Paragraph("This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. "));
}
 
Example #16
Source File: TransactionSummaryController.java    From primefaces-blueprints with The Unlicense 5 votes vote down vote up
public void postProcessPDF(Object document) throws IOException,
		BadElementException, DocumentException {
	Document pdf = (Document) document;
	pdf.add(Chunk.NEWLINE);
	Font fontbold = FontFactory.getFont("Times-Roman", 14, Font.BOLD);
	pdf.add(new Paragraph("Disclaimer", fontbold));
	pdf.add(Chunk.NEWLINE);
	pdf.add(new Paragraph(
			"The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice."));
	pdf.add(new Paragraph(
			"This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. "));
}
 
Example #17
Source File: BmpImage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Reads a BMP from a stream. The stream is not closed. The BMP may not have a header and be
 * considered as a plain DIB.
 * 
 * @param is the stream
 * @param noHeader true to process a plain DIB
 * @param size the size of the DIB. Not used for a BMP
 * @throws IOException on error
 * @return the image
 */
public static Image getImage(InputStream is, boolean noHeader, int size) throws IOException {
	BmpImage bmp = new BmpImage(is, noHeader, size);
	try {
		Image img = bmp.getImage();
		img.setDpi((int) (bmp.xPelsPerMeter * 0.0254d + 0.5d), (int) (bmp.yPelsPerMeter * 0.0254d + 0.5d));
		img.setOriginalType(Image.ORIGINAL_BMP);
		return img;
	} catch (BadElementException be) {
		throw new ExceptionConverter(be);
	}
}
 
Example #18
Source File: SpreadsheetDataFileWriterPdf.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private Cell getHeaderCell(String headerTxt) throws BadElementException{
	//set header cells:								
	Cell c = new Cell(new Chunk(headerTxt, getBoldFont()));
	c.setHeader(true);
	c.setBackgroundColor(Color.LIGHT_GRAY);
	
	return c;
}
 
Example #19
Source File: BmpImage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private Image read4Bit(int paletteEntries) throws IOException, BadElementException {
	byte bdata[] = new byte[(width + 1) / 2 * height];

	// Padding bytes at the end of each scanline
	int padding = 0;

	int bytesPerScanline = (int) Math.ceil(width / 2.0d);
	int remainder = bytesPerScanline % 4;
	if (remainder != 0) {
		padding = 4 - remainder;
	}

	int imSize = (bytesPerScanline + padding) * height;

	// Read till we have the whole image
	byte values[] = new byte[imSize];
	int bytesRead = 0;
	while (bytesRead < imSize) {
		bytesRead += inputStream.read(values, bytesRead, imSize - bytesRead);
	}

	if (isBottomUp) {

		// Convert the bottom up image to a top down format by copying
		// one scanline from the bottom to the top at a time.
		for (int i = 0; i < height; i++) {
			System.arraycopy(values, imSize - (i + 1) * (bytesPerScanline + padding), bdata, i * bytesPerScanline, bytesPerScanline);
		}
	} else {
		for (int i = 0; i < height; i++) {
			System.arraycopy(values, i * (bytesPerScanline + padding), bdata, i * bytesPerScanline, bytesPerScanline);
		}
	}
	return indexedModel(bdata, 4, paletteEntries);
}
 
Example #20
Source File: BmpImage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private Image read8Bit(int paletteEntries) throws IOException, BadElementException {
	byte bdata[] = new byte[width * height];
	// Padding bytes at the end of each scanline
	int padding = 0;

	// width * bitsPerPixel should be divisible by 32
	int bitsPerScanline = width * 8;
	if (bitsPerScanline % 32 != 0) {
		padding = (bitsPerScanline / 32 + 1) * 32 - bitsPerScanline;
		padding = (int) Math.ceil(padding / 8.0);
	}

	int imSize = (width + padding) * height;

	// Read till we have the whole image
	byte values[] = new byte[imSize];
	int bytesRead = 0;
	while (bytesRead < imSize) {
		bytesRead += inputStream.read(values, bytesRead, imSize - bytesRead);
	}

	if (isBottomUp) {

		// Convert the bottom up image to a top down format by copying
		// one scanline from the bottom to the top at a time.
		for (int i = 0; i < height; i++) {
			System.arraycopy(values, imSize - (i + 1) * (width + padding), bdata, i * width, width);
		}
	} else {
		for (int i = 0; i < height; i++) {
			System.arraycopy(values, i * (width + padding), bdata, i * width, width);
		}
	}
	return indexedModel(bdata, 8, paletteEntries);
}
 
Example #21
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Information about the traveler described in the trip for the {@link TravelReimbursementDocument}
 *
 */
protected Cell getTravelerInfo() throws BadElementException {
    final StringBuilder strBuilder = new StringBuilder();
    strBuilder.append(getTravelerName()).append("\n")
        .append(getTravelerPrincipalName()).append("\n")
        .append(getTravelerPhone()).append("\n")
        .append(getTravelerEmail()).append("\n");
    final Cell retval = getBorderlessCell(strBuilder.toString());
    return retval;
}
 
Example #22
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Information about the person that initiated the {@link TravelReimbursementDocument}
 */
protected Cell getInitiatorInfo() throws BadElementException {
    final StringBuilder strBuilder = new StringBuilder();
    strBuilder.append(getInitiatorName()).append("\n")
        .append(getInitiatorPrincipalName()).append("\n")
        .append(getInitiatorPhone()).append("\n")
        .append(getInitiatorEmail()).append("\n");
    final Cell retval = getBorderlessCell(strBuilder.toString());
    return retval;
}
 
Example #23
Source File: SpreadsheetDataFileWriterPdf.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private Cell getHeaderCell(String headerTxt) throws BadElementException{
	//set header cells:								
	Cell c = new Cell(new Chunk(headerTxt, getBoldFont()));
	c.setHeader(true);
	c.setBackgroundColor(Color.LIGHT_GRAY);
	
	return c;
}
 
Example #24
Source File: MPdfWriter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Effectue le rendu de la liste.
 *
 * @param table
 *           MBasicTable
 * @param datatable
 *           Table
 * @throws BadElementException
 *            e
 */
protected void renderList(final MBasicTable table, final Table datatable)
		throws BadElementException {
	final int columnCount = table.getColumnCount();
	final int rowCount = table.getRowCount();
	// data rows
	final Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
	datatable.getDefaultCell().setBorderWidth(1);
	datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
	// datatable.setDefaultCellGrayFill(0);
	Object value;
	String text;
	int horizontalAlignment;
	for (int k = 0; k < rowCount; k++) {
		for (int i = 0; i < columnCount; i++) {
			value = getValueAt(table, k, i);
			if (value instanceof Number || value instanceof Date) {
				horizontalAlignment = Element.ALIGN_RIGHT;
			} else if (value instanceof Boolean) {
				horizontalAlignment = Element.ALIGN_CENTER;
			} else {
				horizontalAlignment = Element.ALIGN_LEFT;
			}
			datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignment);
			text = getTextAt(table, k, i);
			datatable.addCell(new Phrase(8, text != null ? text : "", font));
		}
	}
}
 
Example #25
Source File: MPdfWriter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Effectue le rendu des headers.
 *
 * @param table
 *           MBasicTable
 * @param datatable
 *           Table
 * @throws BadElementException
 *            e
 */
protected void renderHeaders(final MBasicTable table, final Table datatable)
		throws BadElementException {
	final int columnCount = table.getColumnCount();
	final TableColumnModel columnModel = table.getColumnModel();
	// size of columns
	float totalWidth = 0;
	for (int i = 0; i < columnCount; i++) {
		totalWidth += columnModel.getColumn(i).getWidth();
	}
	final float[] headerwidths = new float[columnCount];
	for (int i = 0; i < columnCount; i++) {
		headerwidths[i] = 100f * columnModel.getColumn(i).getWidth() / totalWidth;
	}
	datatable.setWidths(headerwidths);
	datatable.setWidth(100f);

	// table header
	final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
	datatable.getDefaultCell().setBorderWidth(2);
	datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
	// datatable.setDefaultCellGrayFill(0.75f);

	String text;
	Object value;
	for (int i = 0; i < columnCount; i++) {
		value = columnModel.getColumn(i).getHeaderValue();
		text = value != null ? value.toString() : "";
		datatable.addCell(new Phrase(text, font));
	}
	// end of the table header
	datatable.endHeaders();
}
 
Example #26
Source File: PdfJobInformationsReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
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);
		memoryImage.scalePercent(47);
		elapsedTimePhrase.add(new Chunk("\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 période 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("");
	}
}
 
Example #27
Source File: BmpImage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private Image readRLE8() throws IOException, BadElementException {

		// If imageSize field is not provided, calculate it.
		int imSize = (int) imageSize;
		if (imSize == 0) {
			imSize = (int) (bitmapFileSize - bitmapOffset);
		}

		// Read till we have the whole image
		byte values[] = new byte[imSize];
		int bytesRead = 0;
		while (bytesRead < imSize) {
			bytesRead += inputStream.read(values, bytesRead, imSize - bytesRead);
		}

		// Since data is compressed, decompress it
		byte val[] = decodeRLE(true, values);

		// Uncompressed data does not have any padding
		imSize = width * height;

		if (isBottomUp) {

			// Convert the bottom up image to a top down format by copying
			// one scanline from the bottom to the top at a time.
			// int bytesPerScanline = (int)Math.ceil((double)width/8.0);
			byte temp[] = new byte[val.length];
			int bytesPerScanline = width;
			for (int i = 0; i < height; i++) {
				System.arraycopy(val, imSize - (i + 1) * bytesPerScanline, temp, i * bytesPerScanline, bytesPerScanline);
			}
			val = temp;
		}
		return indexedModel(val, 8, 4);
	}
 
Example #28
Source File: PdfCounterReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeRequestGraph(CounterRequest request) throws BadElementException, IOException {
	final JRobin jrobin = collector.getJRobin(request.getId());
	if (jrobin == null) {
		addCell("");
	} else {
		final byte[] img = jrobin.graph(range, 100, 50);
		final Image image = Image.getInstance(img);
		image.scalePercent(50);
		addCell(image);
	}
}
 
Example #29
Source File: PdfCounterReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeRequest(CounterRequest request) throws BadElementException, IOException {
	getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
	addCell(getShortRequestName(request));
	if (includeGraph) {
		writeRequestGraph(request);
	}
	getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
	final CounterRequest globalRequest = counterRequestAggregation.getGlobalRequest();
	if (counterRequestAggregation.isTimesDisplayed()) {
		addPercentageCell(request.getDurationsSum(), globalRequest.getDurationsSum());
		addCell(integerFormat.format(request.getHits()));
		final int mean = request.getMean();
		addCell(new Phrase(integerFormat.format(mean), getSlaFont(mean)));
		addCell(integerFormat.format(request.getMaximum()));
		addCell(integerFormat.format(request.getStandardDeviation()));
	} else {
		addCell(integerFormat.format(request.getHits()));
	}
	if (counterRequestAggregation.isCpuTimesDisplayed()) {
		addPercentageCell(request.getCpuTimeSum(), globalRequest.getCpuTimeSum());
		final int cpuTimeMean = request.getCpuTimeMean();
		addCell(new Phrase(integerFormat.format(cpuTimeMean), getSlaFont(cpuTimeMean)));
	}
	if (counterRequestAggregation.isAllocatedKBytesDisplayed()) {
		final long allocatedKBytesMean = request.getAllocatedKBytesMean();
		addCell(integerFormat.format(allocatedKBytesMean));
	}
	if (!isErrorAndNotJobCounter()) {
		addCell(systemErrorFormat.format(request.getSystemErrorPercentage()));
	}
	if (counterRequestAggregation.isResponseSizeDisplayed()) {
		addCell(integerFormat.format(request.getResponseSizeMean() / 1024L));
	}
	if (counterRequestAggregation.isChildHitsDisplayed()) {
		addCell(integerFormat.format(request.getChildHitsMean()));
		addCell(integerFormat.format(request.getChildDurationsMean()));
	}
}
 
Example #30
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Helper method to create a Header Cell from text
 *
 * @returns {@link Cell} with the header flag set
 */
protected Cell getBorderlessCell(final String text) throws BadElementException {
    final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    final Cell retval = new Cell(new Chunk(text, normalFont));
    retval.setBorder(NO_BORDER);
    return retval;
}