List of usage examples for org.apache.pdfbox.util Matrix getScaleY
public float getScaleY()
From source file:at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignaturePlaceholderExtractor.java
License:EUPL
@Override protected void processOperator(Operator operator, List<COSBase> arguments) throws IOException { String operation = operator.getName(); if (operation.equals("Do")) { COSName objectName = (COSName) arguments.get(0); PDXObject xobject = (PDXObject) getResources().getXObject(objectName); if (xobject instanceof PDImageXObject) { try { PDImageXObject image = (PDImageXObject) xobject; SignaturePlaceholderData data = checkImage(image); if (data != null) { PDPage page = getCurrentPage(); Matrix ctm = getGraphicsState().getCurrentTransformationMatrix(); int pageRotation = page.getRotation(); pageRotation = pageRotation % 360; double rotationInRadians = Math.toRadians(pageRotation);//(page.findRotation() * Math.PI) / 180; AffineTransform rotation = new AffineTransform(); rotation.setToRotation(rotationInRadians); AffineTransform rotationInverse = rotation.createInverse(); Matrix rotationInverseMatrix = new Matrix(); rotationInverseMatrix.setFromAffineTransform(rotationInverse); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(rotation); Matrix unrotatedCTM = ctm.multiply(rotationInverseMatrix); float x = unrotatedCTM.getXPosition(); float yPos = unrotatedCTM.getYPosition(); float yScale = unrotatedCTM.getScaleY(); float y = yPos + yScale; float w = unrotatedCTM.getScaleX(); ;/*from w ww . j ava 2 s . co m*/ logger.debug("Page height: {}", page.getCropBox().getHeight()); logger.debug("Page width: {}", page.getCropBox().getWidth()); if (pageRotation == 90) { y = page.getCropBox().getWidth() - (y * (-1)); } else if (pageRotation == 180) { x = page.getCropBox().getWidth() + x; y = page.getCropBox().getHeight() - (y * (-1)); } else if (pageRotation == 270) { x = page.getCropBox().getHeight() + x; } String posString = "p:" + currentPage + ";x:" + x + ";y:" + y + ";w:" + w; logger.debug("Found Placeholder at: {}", posString); try { data.setTablePos(new TablePos(posString)); data.setPlaceholderName(objectName.getName()); placeholders.add(data); } catch (PdfAsException e) { throw new IOException(); } } } catch (NoninvertibleTransformException e) { throw new IOException(e); } } } else { super.processOperator(operator, arguments); } }