use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.
the class PDFRenderer method hasBlendMode.
private boolean hasBlendMode(PDPage page) {
// check the current resources for blend modes
PDResources resources = page.getResources();
if (resources == null) {
return false;
}
for (COSName name : resources.getExtGStateNames()) {
PDExtendedGraphicsState extGState = resources.getExtGState(name);
if (extGState == null) {
// see PDFBOX-3950-23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf
continue;
}
BlendMode blendMode = extGState.getBlendMode();
if (blendMode != BlendMode.NORMAL) {
return true;
}
}
return false;
}
use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.
the class PDVariableText method getDefaultAppearanceString.
/**
* Get the default appearance.
*
* This is an inheritable attribute.
*
* The default appearance contains a set of default graphics and text operators
* to define the field’s text size and color.
*
* @return the DA element of the dictionary object
*/
PDDefaultAppearanceString getDefaultAppearanceString() throws IOException {
COSString da = (COSString) getInheritableAttribute(COSName.DA);
PDResources dr = getAcroForm().getDefaultResources();
return new PDDefaultAppearanceString(da, dr);
}
use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.
the class AppearanceGeneratorHelper method validateAndEnsureAcroFormResources.
/*
* Adobe Reader/Acrobat are adding resources which are at the field/widget level
* to the AcroForm level.
*/
private void validateAndEnsureAcroFormResources() {
// to match Adobe Reader/Acrobat behavior
if (field.getAcroForm().getDefaultResources() == null) {
return;
}
PDResources acroFormResources = field.getAcroForm().getDefaultResources();
for (PDAnnotationWidget widget : field.getWidgets()) {
if (widget.getNormalAppearanceStream() != null && widget.getNormalAppearanceStream().getResources() != null) {
PDResources widgetResources = widget.getNormalAppearanceStream().getResources();
for (COSName fontResourceName : widgetResources.getFontNames()) {
try {
if (acroFormResources.getFont(fontResourceName) == null) {
Log.d("PdfBox-Android", "Adding font resource " + fontResourceName + " from widget to AcroForm");
acroFormResources.put(fontResourceName, widgetResources.getFont(fontResourceName));
}
} catch (IOException e) {
Log.w("PdfBox-Android", "Unable to match field level font with AcroForm font");
}
}
}
}
}
use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.
the class AppearanceGeneratorHelper method prepareNormalAppearanceStream.
private PDAppearanceStream prepareNormalAppearanceStream(PDAnnotationWidget widget) {
PDAppearanceStream appearanceStream = new PDAppearanceStream(field.getAcroForm().getDocument());
// Calculate the entries for the bounding box and the transformation matrix
// settings for the appearance stream
int rotation = resolveRotation(widget);
PDRectangle rect = widget.getRectangle();
Matrix matrix = Matrix.getRotateInstance(Math.toRadians(rotation), 0, 0);
PointF point2D = matrix.transformPoint(rect.getWidth(), rect.getHeight());
PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.x), Math.abs((float) point2D.y));
appearanceStream.setBBox(bbox);
AffineTransform at = calculateMatrix(bbox, rotation);
if (!at.isIdentity()) {
appearanceStream.setMatrix(at);
}
appearanceStream.setFormType(1);
appearanceStream.setResources(new PDResources());
return appearanceStream;
}
use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.
the class AppearanceGeneratorHelper method getWidgetDefaultAppearanceString.
private PDDefaultAppearanceString getWidgetDefaultAppearanceString(PDAnnotationWidget widget) throws IOException {
COSString da = (COSString) widget.getCOSObject().getDictionaryObject(COSName.DA);
PDResources dr = field.getAcroForm().getDefaultResources();
return new PDDefaultAppearanceString(da, dr);
}
Aggregations