use of com.itextpdf.io.image.ImageData in project pdf-editor by Pdf-Creator.
the class PDFDocument method addRectangleWithImageItem.
public void addRectangleWithImageItem(ImageItem imageItem) throws MalformedURLException {
PdfCanvas canvas = new PdfCanvas(currentPage);
Rectangle rect = new Rectangle(imageItem.getX(), imageItem.getY(), imageItem.getW(), imageItem.getH());
canvas.setStrokeColor(imageItem.getRectangleStrokeColor()).setFillColor(imageItem.getRectangleFillColor()).rectangle(rect).fill().stroke();
ImageData data = ImageDataFactory.create(imageItem.getImagePath());
Image image = new Image(data);
image.setFixedPosition(imageItem.getX(), imageItem.getY());
image.scaleAbsolute(imageItem.getW(), imageItem.getH());
new Canvas(canvas, rect).add(image);
}
use of com.itextpdf.io.image.ImageData in project jExifToolGUI by hvdwolf.
the class ExportToPDF method topTable.
/**
* Method toptable writes the table with the filename, path and the image itself
* @param tmpfile
* @return
*/
private static Table topTable(File tmpfile) {
float[] pointColumnWidths = { 150f, 150f };
Table table = new Table(pointColumnWidths);
table.addCell(new Cell().add(new Paragraph(ResourceBundle.getBundle("translations/program_strings").getString("exppdf.name"))));
table.addCell(new Cell().add(new Paragraph(tmpfile.getName())));
table.addCell(new Cell().add(new Paragraph(ResourceBundle.getBundle("translations/program_strings").getString("exppdf.path"))));
table.addCell(new Cell().add(new Paragraph(tmpfile.getParent())));
table.addCell(new Cell().add(new Paragraph(ResourceBundle.getBundle("translations/program_strings").getString("exppdf.image"))));
String imageFile = GetConvertImage(tmpfile);
if ("/cantconvert.png".equals(imageFile)) {
ImageIcon icon = null;
try {
java.awt.Image img = ImageIO.read(mainScreen.class.getResource("/cantdisplay.png"));
ImageData data = ImageDataFactory.create(img, null);
Image newImg = new Image(data);
// icon = new ImageIcon(img);
table.addCell(new Cell().add(newImg.setAutoScale(true)));
} catch (IOException e) {
logger.error("Error loading image", e);
icon = null;
}
} else {
try {
ImageData data = ImageDataFactory.create(imageFile);
Image img = new Image(data);
table.addCell(new Cell().add(img.setAutoScale(true)));
} catch (MalformedURLException e) {
logger.error("Can't create image object for PDF {}", e);
e.printStackTrace();
}
}
return table;
}
use of com.itextpdf.io.image.ImageData in project i7j-pdfsweep by itext.
the class CleanUpImageUtilTest method cleanUpImageEmptyAreasToCleanTest.
@Test
public void cleanUpImageEmptyAreasToCleanTest() throws Exception {
ImageData data = ImageDataFactory.create(SOURCE_PATH + "cleanUpImageEmptyAreasToClean.png");
PdfImageXObject imageXObject = new PdfImageXObject(data);
byte[] sourceImageBytes = imageXObject.getImageBytes();
byte[] resultImageBytes = CleanUpImageUtil.cleanUpImage(new PdfImageXObject(data).getImageBytes(), new ArrayList<Rectangle>());
Assert.assertArrayEquals(sourceImageBytes, resultImageBytes);
}
use of com.itextpdf.io.image.ImageData in project i7j-pdfsweep by itext.
the class PdfCleanUpProcessor method getFilteredImage.
private PdfImageXObject getFilteredImage(FilteredImagesCache.FilteredImageKey filteredImageKey, Matrix ctmForMasksFiltering) {
PdfImageXObject originalImage = filteredImageKey.getImageXObject();
PdfImageXObject imageToWrite = getFilteredImagesCache().get(filteredImageKey);
if (imageToWrite == null) {
PdfCleanUpFilter.FilterResult<ImageData> imageFilterResult = filter.filterImage(filteredImageKey);
if (imageFilterResult.isModified()) {
ImageData filteredImageData = imageFilterResult.getFilterResult();
if (Boolean.TRUE.equals(originalImage.getPdfObject().getAsBool(PdfName.ImageMask))) {
if (!PdfCleanUpFilter.imageSupportsDirectCleanup(originalImage)) {
Logger logger = LoggerFactory.getLogger(PdfCleanUpProcessor.class);
logger.error(CleanUpLogMessageConstant.IMAGE_MASK_CLEAN_UP_NOT_SUPPORTED);
} else {
filteredImageData.makeMask();
}
}
if (filteredImageData != null) {
imageToWrite = new PdfImageXObject(filteredImageData);
getFilteredImagesCache().put(filteredImageKey, imageToWrite);
// then the old colorspace may produce an error with the new image data.
if (areColorSpacesDifferent(originalImage, imageToWrite) && CleanUpCsCompareUtil.isOriginalCsCompatible(originalImage, imageToWrite)) {
PdfObject originalCS = originalImage.getPdfObject().get(PdfName.ColorSpace);
if (originalCS != null) {
imageToWrite.put(PdfName.ColorSpace, originalCS);
}
}
if (ctmForMasksFiltering != null && !filteredImageData.isMask()) {
filterImageMask(originalImage, PdfName.SMask, ctmForMasksFiltering, imageToWrite);
filterImageMask(originalImage, PdfName.Mask, ctmForMasksFiltering, imageToWrite);
PdfArray colourKeyMaskingArr = originalImage.getPdfObject().getAsArray(PdfName.Mask);
if (colourKeyMaskingArr != null) {
// In general we should be careful about images that might have changed their color space
// or have been converted to lossy format during filtering.
// However we have been copying Mask entry non-conditionally before and also I'm not sure
// that cases described above indeed take place.
imageToWrite.put(PdfName.Mask, colourKeyMaskingArr);
}
if (originalImage.getPdfObject().containsKey(PdfName.SMaskInData)) {
// This entry will likely lose meaning after image conversion to bitmap and back again, but let's leave as is for now.
imageToWrite.put(PdfName.SMaskInData, originalImage.getPdfObject().get(PdfName.SMaskInData));
}
}
}
} else {
imageToWrite = originalImage;
}
}
return imageToWrite;
}
Aggregations