Search in sources :

Example 6 with ImageData

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);
}
Also used : ImageData(com.itextpdf.io.image.ImageData) Canvas(com.itextpdf.layout.Canvas) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) BufferedImage(java.awt.image.BufferedImage) Image(com.itextpdf.layout.element.Image)

Example 7 with ImageData

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ImageData(com.itextpdf.io.image.ImageData)

Example 8 with ImageData

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);
}
Also used : PdfImageXObject(com.itextpdf.kernel.pdf.xobject.PdfImageXObject) ImageData(com.itextpdf.io.image.ImageData) Rectangle(com.itextpdf.kernel.geom.Rectangle) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 9 with ImageData

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;
}
Also used : PdfImageXObject(com.itextpdf.kernel.pdf.xobject.PdfImageXObject) PdfArray(com.itextpdf.kernel.pdf.PdfArray) ImageData(com.itextpdf.io.image.ImageData) PdfObject(com.itextpdf.kernel.pdf.PdfObject) Logger(org.slf4j.Logger)

Aggregations

ImageData (com.itextpdf.io.image.ImageData)9 Image (com.itextpdf.layout.element.Image)5 Rectangle (com.itextpdf.kernel.geom.Rectangle)3 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)2 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)2 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)2 PdfImageXObject (com.itextpdf.kernel.pdf.xobject.PdfImageXObject)2 Canvas (com.itextpdf.layout.Canvas)2 Document (com.itextpdf.layout.Document)2 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 Jbig2ImageData (com.itextpdf.io.image.Jbig2ImageData)1 TiffImageData (com.itextpdf.io.image.TiffImageData)1 IRandomAccessSource (com.itextpdf.io.source.IRandomAccessSource)1 RandomAccessFileOrArray (com.itextpdf.io.source.RandomAccessFileOrArray)1 RandomAccessSourceFactory (com.itextpdf.io.source.RandomAccessSourceFactory)1 PdfArray (com.itextpdf.kernel.pdf.PdfArray)1 PdfObject (com.itextpdf.kernel.pdf.PdfObject)1 ImageRenderInfo (com.itextpdf.kernel.pdf.canvas.parser.data.ImageRenderInfo)1 DottedBorder (com.itextpdf.layout.borders.DottedBorder)1