Java Code Examples for org.apache.pdfbox.util.Matrix#getScalingFactorX()

The following examples show how to use org.apache.pdfbox.util.Matrix#getScalingFactorX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphicsParser.java    From tephra with MIT License 6 votes vote down vote up
private boolean clip(Matrix matrix, PDImageXObject pdImageXObject) throws IOException {
    if (clipTypes.isEmpty() || (clipTypes.size() == 1 && clipTypes.get(0).equals("rect")
            && Math.abs(matrix.getScaleX() / matrix.getScalingFactorY()
            - (clipArea[2] - clipArea[0]) / (clipArea[3] - clipArea[1])) <= 0.01D))
        return false;

    SVGGraphics2D svgGraphics2D = new SVGGraphics2D(GenericDOMImplementation.getDOMImplementation()
            .createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null));
    if (pdImageXObject != null) {
        int w = (int) matrix.getScalingFactorX();
        int h = (int) matrix.getScalingFactorY();
        svgGraphics2D.clip(getPath(clipTypes, clipPoints, clipArea));
        svgGraphics2D.drawImage(pdImageXObject.getImage().getScaledInstance(w, h, Image.SCALE_SMOOTH),
                (int) (matrix.getTranslateX() - clipArea[0]), (int) (matrix.getTranslateY() - clipArea[1]), w, h, null);
    }
    save(svgGraphics2D, clipArea[0], clipArea[1], (clipArea[2] - clipArea[0]), (clipArea[3] - clipArea[1]));

    return true;
}
 
Example 2
Source File: ImageExtractor.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override protected void processOperator(Operator operator, List<COSBase> operands)
    throws IOException
{
    String operation = operator.getName();
    if ("Do".equals(operation)) {
        COSName objectName = (COSName) operands.get(0);
        PDXObject xobject = getResources().getXObject(objectName);

        if (xobject instanceof PDImageXObject) {
            PDImageXObject image = (PDImageXObject) xobject;
            Matrix ctmNew = getGraphicsState().getCurrentTransformationMatrix();
            PDRectangle pageRect = this.getCurrentPage().getCropBox();
            float w = ctmNew.getScalingFactorX();
            float h = ctmNew.getScalingFactorY();
            float x = ctmNew.getTranslateX();
            float y = pageRect.getHeight() - ctmNew.getTranslateY() - h;
            buffer.add(new ImageOperator(x, y, w, h));
        }
        else if (xobject instanceof PDFormXObject) {
            PDFormXObject form = (PDFormXObject) xobject;
            showForm(form);
        }
    }
    else {
        super.processOperator(operator, operands);
    }
}