com.itextpdf.text.BadElementException Java Examples

The following examples show how to use com.itextpdf.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: PDFSampleMain.java    From tutorials with MIT License 7 votes vote down vote up
private static void addCustomRows(PdfPTable table) throws URISyntaxException, BadElementException, IOException {
    Path path = Paths.get(ClassLoader.getSystemResource("Java_logo.png").toURI());
    Image img = Image.getInstance(path.toAbsolutePath().toString());
    img.scalePercent(10);

    PdfPCell imageCell = new PdfPCell(img);
    table.addCell(imageCell);

    PdfPCell horizontalAlignCell = new PdfPCell(new Phrase("row 2, col 2"));
    horizontalAlignCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(horizontalAlignCell);

    PdfPCell verticalAlignCell = new PdfPCell(new Phrase("row 2, col 3"));
    verticalAlignCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(verticalAlignCell);
}
 
Example #2
Source File: PDFMigrationReportWriter.java    From bonita-studio with GNU General Public License v2.0 7 votes vote down vote up
private void createLegend(Paragraph mainPara) throws BadElementException,
		MalformedURLException, IOException {
	mainPara.add(new Chunk("      ",legendFont));
	Image im = getImageForStatus(IStatus.OK);
	mainPara.add(new Chunk(im, 0, 0, false));
	mainPara.add(new Chunk(" ",legendFont));
	mainPara.add(new Chunk(Messages.noActionRequired,legendFont));
	mainPara.add(new Chunk("   ",legendFont));
	im = getImageForStatus(IStatus.WARNING);
	mainPara.add(new Chunk(im, 0, 0, false));
	mainPara.add(new Chunk(" ",legendFont));
	mainPara.add(new Chunk(Messages.reviewRequired,legendFont));
	mainPara.add(new Chunk("   ",legendFont));
	im = getImageForStatus(IStatus.ERROR);
	mainPara.add(new Chunk(im, 0, 0, false));
	mainPara.add(new Chunk(" ",legendFont));
	mainPara.add(new Chunk(Messages.actionRequired,legendFont));
}
 
Example #3
Source File: PdfCleanUpContentOperator.java    From testarea-itext5 with GNU Affero General Public License v3.0 6 votes vote down vote up
private void updateImageStream(PRStream imageStream, byte[] newData) throws BadElementException, IOException, BadPdfFormatException {
    PdfImage image = new PdfImage(Image.getInstance(newData), "", null);

    if (imageStream.contains(PdfName.SMASK)) {
        image.put(PdfName.SMASK, imageStream.get(PdfName.SMASK));
    }

    if (imageStream.contains(PdfName.MASK)) {
        image.put(PdfName.MASK, imageStream.get(PdfName.MASK));
    }

    if (imageStream.contains(PdfName.SMASKINDATA)) {
        image.put(PdfName.SMASKINDATA, imageStream.get(PdfName.SMASKINDATA));
    }

    imageStream.clear();
    imageStream.putAll(image);
    imageStream.setDataRaw(image.getBytes());
}
 
Example #4
Source File: PDFExport.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
private PdfPCell getCells(MagicCard card) throws BadElementException, IOException {

		Image image1 = null;
		try {
			image1 = Image.getInstance(MTGControler.getInstance().getEnabled(MTGPictureProvider.class).getPicture(card, null),
					null);
		} catch (Exception e) {
			image1 = Image.getInstance(MTGControler.getInstance().getEnabled(MTGPictureProvider.class).getBackPicture(), null);
		}

		int h = getInt("CARD_HEIGHT");
		int w = getInt("CARD_WIDTH");

		image1.scaleAbsolute(w, h);

		PdfPCell cell = new PdfPCell(image1, false);
		cell.setBorder(0);
		cell.setPadding(5);
	
		return cell;
	}
 
Example #5
Source File: TableWithSpan.java    From testarea-itext5 with GNU Affero General Public License v3.0 5 votes vote down vote up
PdfPCell getPiccell(int w, int h)
{
    try
    {
        Image image = Image.getInstance("src/test/resources/mkl/testarea/itext5/content/2x2colored.png");
        image.scaleAbsolute(w, h);
        return new PdfPCell(image);
    }
    catch (BadElementException | IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: BinaryTransparency.java    From testarea-itext5 with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void addBackground(PdfWriter writer)
        throws BadElementException, MalformedURLException, IOException, DocumentException {
    PdfContentByte canvas = writer.getDirectContentUnder();
    canvas.saveState();
    canvas.addImage(bkgnd);
    canvas.restoreState();
}
 
Example #7
Source File: PDF2ImageExample.java    From tutorials with MIT License 5 votes vote down vote up
private static void generatePDFFromImage(String filename, String extension)
		throws IOException, BadElementException, DocumentException {
	Document document = new Document();
	String input = filename + "." + extension;
	String output = "src/output/" + extension + ".pdf";
	FileOutputStream fos = new FileOutputStream(output);
	PdfWriter writer = PdfWriter.getInstance(document, fos);
	writer.open();
	document.open();
	document.add(Image.getInstance((new URL(input))));
	document.close();
	writer.close();
}
 
Example #8
Source File: PDFMigrationReportWriter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private com.itextpdf.text.Image getImageForStatus(int status) throws BadElementException, MalformedURLException, IOException {
	switch (status) {
	case IStatus.OK: Image im =  Image.getInstance(FileLocator.toFileURL(MigrationPlugin.getDefault().getBundle().getResource("/icons/valid.png")));im.setCompressionLevel(12);im.scaleToFit(12, 12);return im;
	case IStatus.WARNING:  im = Image.getInstance(FileLocator.toFileURL(MigrationPlugin.getDefault().getBundle().getResource("/icons/warning.gif")));im.setCompressionLevel(12);im.scaleToFit(16, 16);return im;
	case IStatus.ERROR:  im = Image.getInstance(FileLocator.toFileURL(MigrationPlugin.getDefault().getBundle().getResource("/icons/error.png")));im.setCompressionLevel(12);im.scaleToFit(12, 12);return im;
	default:break;
	}

	return null;
}