Search in sources :

Example 21 with PDResources

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;
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) PDExtendedGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState) BlendMode(com.tom_roush.pdfbox.pdmodel.graphics.blend.BlendMode) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources)

Example 22 with PDResources

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);
}
Also used : PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 23 with PDResources

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");
                }
            }
        }
    }
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) PDAnnotationWidget(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget) IOException(java.io.IOException)

Example 24 with PDResources

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;
}
Also used : Matrix(com.tom_roush.pdfbox.util.Matrix) PDAppearanceStream(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream) PointF(android.graphics.PointF) AffineTransform(com.tom_roush.harmony.awt.geom.AffineTransform) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 25 with PDResources

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);
}
Also used : PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) COSString(com.tom_roush.pdfbox.cos.COSString)

Aggregations

PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)44 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)13 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)13 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)11 COSName (com.tom_roush.pdfbox.cos.COSName)9 Matrix (com.tom_roush.pdfbox.util.Matrix)9 IOException (java.io.IOException)8 PDFont (com.tom_roush.pdfbox.pdmodel.font.PDFont)7 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)7 File (java.io.File)7 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)6 COSBase (com.tom_roush.pdfbox.cos.COSBase)5 PDPageContentStream (com.tom_roush.pdfbox.pdmodel.PDPageContentStream)5 AffineTransform (com.tom_roush.harmony.awt.geom.AffineTransform)4 PDAppearanceContentStream (com.tom_roush.pdfbox.pdmodel.PDAppearanceContentStream)4 PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)4 PDGraphicsState (com.tom_roush.pdfbox.pdmodel.graphics.state.PDGraphicsState)4 PDAppearanceStream (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream)4 PDDocumentCatalog (com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog)3 PDStream (com.tom_roush.pdfbox.pdmodel.common.PDStream)3