use of org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project pdfbox by apache.
the class PDXObject method createXObject.
/**
* Creates a new XObject instance of the appropriate type for the COS stream.
*
* @param base The stream which is wrapped by this XObject.
* @param resources
* @return A new XObject instance.
* @throws java.io.IOException if there is an error creating the XObject.
*/
public static PDXObject createXObject(COSBase base, PDResources resources) throws IOException {
if (base == null) {
// TODO throw an exception?
return null;
}
if (!(base instanceof COSStream)) {
throw new IOException("Unexpected object type: " + base.getClass().getName());
}
COSStream stream = (COSStream) base;
String subtype = stream.getNameAsString(COSName.SUBTYPE);
if (COSName.IMAGE.getName().equals(subtype)) {
return new PDImageXObject(new PDStream(stream), resources);
} else if (COSName.FORM.getName().equals(subtype)) {
ResourceCache cache = resources != null ? resources.getResourceCache() : null;
COSDictionary group = (COSDictionary) stream.getDictionaryObject(COSName.GROUP);
if (group != null && COSName.TRANSPARENCY.equals(group.getCOSName(COSName.S))) {
return new PDTransparencyGroup(stream, cache);
}
return new PDFormXObject(stream, cache);
} else if (COSName.PS.getName().equals(subtype)) {
return new PDPostScriptXObject(stream);
} else {
throw new IOException("Invalid XObject Subtype: " + subtype);
}
}
use of org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project pdfbox by apache.
the class DrawObject method process.
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
if (operands.size() < 1) {
throw new MissingOperandException(operator, operands);
}
COSBase base0 = operands.get(0);
if (!(base0 instanceof COSName)) {
return;
}
COSName objectName = (COSName) base0;
PDXObject xobject = context.getResources().getXObject(objectName);
if (xobject == null) {
throw new MissingResourceException("Missing XObject: " + objectName.getName());
} else if (xobject instanceof PDImageXObject) {
PDImageXObject image = (PDImageXObject) xobject;
context.drawImage(image);
} else if (xobject instanceof PDTransparencyGroup) {
getContext().showTransparencyGroup((PDTransparencyGroup) xobject);
} else if (xobject instanceof PDFormXObject) {
getContext().showForm((PDFormXObject) xobject);
}
}
use of org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project pdfbox by apache.
the class DrawObject method process.
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
if (arguments.size() < 1) {
throw new MissingOperandException(operator, arguments);
}
COSBase base0 = arguments.get(0);
if (!(base0 instanceof COSName)) {
return;
}
COSName name = (COSName) base0;
if (context.getResources().isImageXObject(name)) {
// we're done here, don't decode images when doing text extraction
return;
}
PDXObject xobject = context.getResources().getXObject(name);
if (xobject instanceof PDTransparencyGroup) {
context.showTransparencyGroup((PDTransparencyGroup) xobject);
} else if (xobject instanceof PDFormXObject) {
PDFormXObject form = (PDFormXObject) xobject;
context.showForm(form);
}
}
use of org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project pdfbox by apache.
the class DrawObject method process.
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
if (arguments.size() < 1) {
throw new MissingOperandException(operator, arguments);
}
COSBase base0 = arguments.get(0);
if (!(base0 instanceof COSName)) {
return;
}
COSName name = (COSName) base0;
PDXObject xobject = context.getResources().getXObject(name);
((PDFMarkedContentExtractor) context).xobject(xobject);
if (xobject instanceof PDTransparencyGroup) {
context.showTransparencyGroup((PDTransparencyGroup) xobject);
} else if (xobject instanceof PDFormXObject) {
PDFormXObject form = (PDFormXObject) xobject;
context.showForm(form);
}
}
use of org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project pdfbox by apache.
the class PageDrawer method showTransparencyGroup.
@Override
public void showTransparencyGroup(PDTransparencyGroup form) throws IOException {
TransparencyGroup group = new TransparencyGroup(form, false, getGraphicsState().getCurrentTransformationMatrix(), null);
BufferedImage image = group.getImage();
if (image == null) {
// image is empty, don't bother
return;
}
graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
setClip();
// both the DPI xform and the CTM were already applied to the group, so all we do
// here is draw it directly onto the Graphics2D device at the appropriate position
PDRectangle bbox = group.getBBox();
AffineTransform prev = graphics.getTransform();
Matrix m = new Matrix(xform);
float xScale = Math.abs(m.getScalingFactorX());
float yScale = Math.abs(m.getScalingFactorY());
// adjust the initial translation (includes the translation used to "help" the rotation)
graphics.setTransform(AffineTransform.getTranslateInstance(xform.getTranslateX(), xform.getTranslateY()));
graphics.rotate(Math.toRadians(pageRotation));
// adjust bbox (x,y) position at the initial scale + cropbox
float x = bbox.getLowerLeftX() - pageSize.getLowerLeftX();
float y = pageSize.getUpperRightY() - bbox.getUpperRightY();
if (flipTG) {
graphics.translate(0, image.getHeight());
graphics.scale(1, -1);
} else {
graphics.translate(x * xScale, y * yScale);
}
PDSoftMask softMask = getGraphicsState().getSoftMask();
if (softMask != null) {
Paint awtPaint = new TexturePaint(image, new Rectangle2D.Float(0, 0, image.getWidth(), image.getHeight()));
awtPaint = applySoftMaskToPaint(awtPaint, softMask);
graphics.setPaint(awtPaint);
graphics.fill(new Rectangle2D.Float(0, 0, bbox.getWidth() * xScale, bbox.getHeight() * yScale));
} else {
graphics.drawImage(image, null, null);
}
graphics.setTransform(prev);
}
Aggregations