List of usage examples for com.itextpdf.text.pdf.parser Matrix I22
int I22
To view the source code for com.itextpdf.text.pdf.parser Matrix I22.
Click Source Link
From source file:mkl.testarea.itext5.pdfcleanup.PdfCleanUpRegionFilter.java
License:Open Source License
private Point2D[] transformPoints(Matrix transormationMatrix, boolean inverse, Point2D... points) { AffineTransform t = new AffineTransform(transormationMatrix.get(Matrix.I11), transormationMatrix.get(Matrix.I12), transormationMatrix.get(Matrix.I21), transormationMatrix.get(Matrix.I22), transormationMatrix.get(Matrix.I31), transormationMatrix.get(Matrix.I32)); Point2D[] transformed = new Point2D[points.length]; if (inverse) { try {/* w ww . j a va 2 s. c o m*/ t = t.createInverse(); } catch (NoninvertibleTransformException e) { throw new RuntimeException(e); } } t.transform(points, 0, transformed, 0, points.length); return transformed; }
From source file:org.gmdev.pdftrick.engine.ImageListenerShowThumb.java
License:Open Source License
/** * extracts the images contained in selected page and convert it in a BufferedImage to add and show to the center panel. * @param renderInfo//from www.ja va 2 s .co m */ private void render(ImageRenderInfo renderInfo) { final HashMap<Integer, String> rotationFromPages = factory.getRotationFromPages(); boolean isInline = false; PdfImageObject image = null; try { BufferedImage buffImg = null; if (renderInfo.getRef() == null) { isInline = true; inlineImageCounter += 1; } try { image = renderInfo.getImage(); } catch (UnsupportedPdfException updfe) { try { if (isInline) { buffImg = null; } else { buffImg = CustomExtraImgReader.readIndexedPNG(renderInfo.getRef().getNumber(), factory.getResultFile()); } } catch (Exception e) { logger.error("Exception", e); PdfTrickMessages.append("ERROR", Consts.SENDLOG_MSG); unsupportedImage++; return; } } if (image != null) { BufferedImage buffPic = null; try { // if image is JBIG2 type i need a custom way and using jbig2 ImageIO plugin if (image.getFileType().equalsIgnoreCase("JBIG2")) { buffPic = CustomExtraImgReader.readJBIG2(image); } else { buffPic = image.getBufferedImage(); } } catch (IIOException iioex) { byte[] imageByteArray = image.getImageAsBytes(); try { buffPic = CustomExtraImgReader.readCMYK_JPG(imageByteArray); } catch (Exception e) { logger.error("Exception", e); PdfTrickMessages.append("ERROR", Consts.SENDLOG_MSG); unsupportedImage++; return; } } catch (Exception e) { logger.error("Exception", e); PdfTrickMessages.append("ERROR", Consts.SENDLOG_MSG); unsupportedImage++; return; } // check if image contains a mask image BufferedImage buffMask = null; PdfDictionary imageDictionary = image.getDictionary(); PRStream maskStream = (PRStream) imageDictionary.getAsStream(PdfName.SMASK); if (maskStream != null) { // if i have an smak object i check that is not a jpeg format, because this may cause some problem on offscreen rendering // usually all imges with mask are png ... and there aren't problems, if image is jpg i discard the mask :) if (!image.getFileType().equalsIgnoreCase("jpg") && buffPic != null) { PdfImageObject maskImage = new PdfImageObject(maskStream); buffMask = maskImage.getBufferedImage(); Image img = PdfTrickUtils.TransformGrayToTransparency(buffMask); buffImg = PdfTrickUtils.ApplyTransparency(buffPic, img); } else { buffImg = buffPic; } } else { buffImg = buffPic; } } String flip = ""; String rotate = ""; Matrix matrix = renderInfo.getImageCTM(); String angle = "" + rotationFromPages.get(numPage); // experimental float i11 = matrix.get(Matrix.I11); // if negative -> horizontal flip float i12 = matrix.get(Matrix.I12); // if negative -> 90 degree rotation float i21 = matrix.get(Matrix.I21); // if negative -> 270 degree rotation float i22 = matrix.get(Matrix.I22); // if negative -> vertical flip // flip and rotation ... from matrix if i11 or i22 is negative i have to flip image if (("" + i11).charAt(0) == '-') { flip = "fh"; } else if (("" + i22).charAt(0) == '-') { flip = "fv"; } if (angle.equalsIgnoreCase("270") || ("" + i21).charAt(0) == '-') { rotate = "270"; } else if (angle.equalsIgnoreCase("180")) { rotate = "180"; } else if (angle.equalsIgnoreCase("90") || ("" + i12).charAt(0) == '-') { rotate = "90"; } if (buffImg != null) { buffImg = PdfTrickUtils.adjustImage(buffImg, flip, rotate); RenderedImageAttributes imageAttrs = null; if (isInline) { // set up inline image object attributes and store it in a hashmap InlineImage inImg = new InlineImage(buffImg, image != null ? image.getFileType() : "png"); imageAttrs = new RenderedImageInline(inlineImageCounter, inImg, numPage, flip, rotate); } else { // set up image object for normal images imageAttrs = new RenderedImageNormal(numPage, renderInfo.getRef().getNumber(), flip, rotate); } // scaling image with original aspect ratio (if image exceded pic box) int w = buffImg.getWidth(); int h = buffImg.getHeight(); if (w > 170 || h > 170) { double faktor; if (w > h) { faktor = 160 / (double) w; int scaledW = (int) Math.round(faktor * w); int scaledH = (int) Math.round(faktor * h); buffImg = PdfTrickUtils.getScaledImagWithScalr(buffImg, scaledW, scaledH); } else { faktor = 160 / (double) h; int scaledW = (int) Math.round(faktor * w); int scaledH = (int) Math.round(faktor * h); buffImg = PdfTrickUtils.getScaledImagWithScalr(buffImg, scaledW, scaledH); } } numImg++; // dynamic update on the center panel (under EDT thread). UpdatePanelCenter upPcenter = this.upPcenter; upPcenter.setInlineImg(isInline); upPcenter.setBuffImg(buffImg); upPcenter.setImageAttrs(imageAttrs); try { SwingUtilities.invokeAndWait(upPcenter); } catch (InterruptedException e) { logger.error("Exception", e); } catch (InvocationTargetException e) { logger.error("Exception", e); } buffImg.flush(); } else { unsupportedImage++; } } catch (IOException e) { logger.error("Exception", e); PdfTrickMessages.append("ERROR", Consts.SENDLOG_MSG); unsupportedImage++; } catch (Exception e) { logger.error("Exception", e); PdfTrickMessages.append("ERROR", Consts.SENDLOG_MSG); unsupportedImage++; } }