Search in sources :

Example 1 with ImageData

use of com.itextpdf.io.image.ImageData in project i7js-highlevel by itext.

the class C03E19_PagedImages method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Image img;
    // Animated GIF
    URL url1 = UrlUtil.toURL(TEST1);
    List<ImageData> list = ImageDataFactory.createGifFrames(url1);
    for (ImageData data : list) {
        img = new Image(data);
        document.add(img);
    }
    // JBIG2
    URL url2 = UrlUtil.toURL(TEST2);
    IRandomAccessSource ras2 = new RandomAccessSourceFactory().createSource(url2);
    RandomAccessFileOrArray raf2 = new RandomAccessFileOrArray(ras2);
    int pages2 = Jbig2ImageData.getNumberOfPages(raf2);
    for (int i = 1; i <= pages2; i++) {
        img = new Image(ImageDataFactory.createJbig2(url2, i));
        document.add(img);
    }
    // TIFF
    URL url3 = UrlUtil.toURL(TEST3);
    IRandomAccessSource ras3 = new RandomAccessSourceFactory().createSource(url3);
    RandomAccessFileOrArray raf3 = new RandomAccessFileOrArray(ras3);
    int pages3 = TiffImageData.getNumberOfPages(raf3);
    for (int i = 1; i <= pages3; i++) {
        img = new Image(ImageDataFactory.createTiff(url3, true, i, true));
        document.add(img);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) RandomAccessFileOrArray(com.itextpdf.io.source.RandomAccessFileOrArray) ImageData(com.itextpdf.io.image.ImageData) TiffImageData(com.itextpdf.io.image.TiffImageData) Jbig2ImageData(com.itextpdf.io.image.Jbig2ImageData) RandomAccessSourceFactory(com.itextpdf.io.source.RandomAccessSourceFactory) IRandomAccessSource(com.itextpdf.io.source.IRandomAccessSource) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) URL(java.net.URL)

Example 2 with ImageData

use of com.itextpdf.io.image.ImageData in project pdf-editor by Pdf-Creator.

the class PDFDocument method addRectangleWithFormulaItem.

public void addRectangleWithFormulaItem(FormulaItem formulaItem) throws IOException {
    PdfCanvas canvas = new PdfCanvas(currentPage);
    Rectangle rect = new Rectangle(formulaItem.getX(), formulaItem.getY(), formulaItem.getW(), formulaItem.getW());
    canvas.setStrokeColor(formulaItem.getRectangleStrokeColor()).setFillColor(formulaItem.getRectangleStrokeColor()).rectangle(rect).fill().stroke();
    // very strange method
    TeXFormula tf = new TeXFormula(formulaItem.getFormula());
    TeXIcon ti = tf.createTeXIcon(TeXConstants.STYLE_DISPLAY, formulaItem.getFontSize());
    BufferedImage bimg = new BufferedImage(ti.getIconWidth(), ti.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
    // -- painting the formula --
    Graphics2D g2d = bimg.createGraphics();
    g2d.setColor(Color.white);
    g2d.fillRect(0, 0, ti.getIconWidth(), ti.getIconHeight());
    JLabel jl = new JLabel();
    jl.setForeground(new Color(0, 0, 0));
    ti.paintIcon(jl, g2d, 0, 0);
    // --------------------------
    // -- adding it to pdf --
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ImageIO.write(bimg, "png", byteArrayOutputStream);
    ImageData data = ImageDataFactory.create(byteArrayOutputStream.toByteArray());
    Image image = new Image(data);
    image.setFixedPosition(formulaItem.getX(), formulaItem.getY());
    image.scaleAbsolute(formulaItem.getW(), formulaItem.getH());
    new Canvas(canvas, rect).add(image);
}
Also used : ImageData(com.itextpdf.io.image.ImageData) TeXFormula(org.scilab.forge.jlatexmath.TeXFormula) 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) Image(com.itextpdf.layout.element.Image) BufferedImage(java.awt.image.BufferedImage) TeXIcon(org.scilab.forge.jlatexmath.TeXIcon)

Example 3 with ImageData

use of com.itextpdf.io.image.ImageData in project i7j-pdfsweep by itext.

the class PdfCleanUpProcessor method cleanInlineImage.

private void cleanInlineImage() {
    ImageRenderInfo encounteredImage = ((PdfCleanUpEventListener) getEventListener()).getEncounteredImage();
    PdfCleanUpFilter.FilterResult<ImageData> imageFilterResult = filter.filterImage(encounteredImage);
    ImageData filteredImage;
    if (imageFilterResult.isModified()) {
        filteredImage = imageFilterResult.getFilterResult();
    } else {
        filteredImage = ImageDataFactory.create(encounteredImage.getImage().getImageBytes());
    }
    if (filteredImage != null) {
        Boolean imageMaskFlag = encounteredImage.getImage().getPdfObject().getAsBool(PdfName.ImageMask);
        if (imageMaskFlag != null && (boolean) imageMaskFlag) {
            filteredImage.makeMask();
        }
        float[] ctm = pollNotAppliedCtm();
        writeNotAppliedGsParams(false, false);
        openNotWrittenTags();
        getCanvas().addImageWithTransformationMatrix(filteredImage, ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5], true);
    }
// TODO
// PdfCanvas doesn't have a method that writes inline image using pdf stream, and only have method which
// accepts Image as parameter. That's why we can't write image just as it was in original file, we convert it to Image.
// IMPORTANT: If writing of pdf stream of not changed inline image will be implemented, don't forget to ensure that
// inline image color space is present in new resources if necessary.
}
Also used : ImageData(com.itextpdf.io.image.ImageData) ImageRenderInfo(com.itextpdf.kernel.pdf.canvas.parser.data.ImageRenderInfo)

Example 4 with ImageData

use of com.itextpdf.io.image.ImageData in project MtgDesktopCompanion by nicho92.

the class PDFExport method createCell.

private Cell createCell(MagicCard card) throws IOException {
    ImageData imageData = null;
    try {
        imageData = ImageDataFactory.create(getEnabledPlugin(MTGPictureProvider.class).getFullSizePicture(card), null);
    } catch (Exception e) {
        imageData = ImageDataFactory.create(getEnabledPlugin(MTGPictureProvider.class).getBackPicture(), null);
    }
    var image = new Image(imageData);
    image.scaleAbsolute(2.49f * userPoint, 3.48f * userPoint);
    var cell = new Cell();
    if (getBoolean("PRINT_CUT_LINE")) {
        cell.setBorder(new DottedBorder(0.5f));
    } else
        cell.setBorder(Border.NO_BORDER);
    if (getInt(SPACE) != null)
        cell.setPadding(getInt(SPACE));
    cell.add(image);
    return cell;
}
Also used : MTGPictureProvider(org.magic.api.interfaces.MTGPictureProvider) ImageData(com.itextpdf.io.image.ImageData) Image(com.itextpdf.layout.element.Image) DottedBorder(com.itextpdf.layout.borders.DottedBorder) Cell(com.itextpdf.layout.element.Cell) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException)

Example 5 with ImageData

use of com.itextpdf.io.image.ImageData in project i7js-highlevel by itext.

the class C03E18_ImageTypes method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    // raw
    byte[] data = new byte[256 * 3];
    for (int i = 0; i < 256; i++) {
        data[i * 3] = (byte) (255 - i);
        data[i * 3 + 1] = (byte) (255 - i);
        data[i * 3 + 2] = (byte) i;
    }
    ImageData raw = ImageDataFactory.create(256, 1, 3, 8, data, null);
    Image img = new Image(raw);
    img.scaleAbsolute(256, 10);
    document.add(img);
    // JPEG2000
    Image img1 = new Image(ImageDataFactory.create(TEST1));
    document.add(img1);
    document.add(new AreaBreak());
    // BMP
    Image img2 = new Image(ImageDataFactory.create(TEST2));
    img2.setMarginBottom(10);
    document.add(img2);
    // PNG
    Image img3 = new Image(ImageDataFactory.create(TEST3));
    img3.setMarginBottom(10);
    document.add(img3);
    // Transparent PNG
    Image img4 = new Image(ImageDataFactory.create(TEST4));
    img4.setBorderLeft(new SolidBorder(6));
    document.add(img4);
    // GIF
    Image img5 = new Image(ImageDataFactory.create(TEST5));
    img5.setBackgroundColor(ColorConstants.LIGHT_GRAY);
    document.add(img5);
    // AWT
    java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(TEST5);
    Image awt = new Image(ImageDataFactory.create(awtImage, java.awt.Color.yellow));
    awt.setMarginTop(10);
    document.add(awt);
    // JBIG2
    Image img6 = new Image(ImageDataFactory.create(TEST6));
    document.add(img6);
    // TIFF
    Image img7 = new Image(ImageDataFactory.create(TEST7));
    document.add(img7);
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ImageData(com.itextpdf.io.image.ImageData) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) SolidBorder(com.itextpdf.layout.borders.SolidBorder) java.awt(java.awt)

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