Search in sources :

Example 26 with PDResources

use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.

the class PDAcroForm method verifyOrCreateDefaults.

/*
     * Verify that there are default entries for required
     * properties.
     *
     * If these are missing create default entries similar to
     * Adobe Reader / Adobe Acrobat
     *
     */
private void verifyOrCreateDefaults() {
    final String adobeDefaultAppearanceString = "/Helv 0 Tf 0 g ";
    // DA entry is required
    if (getDefaultAppearance().length() == 0) {
        setDefaultAppearance(adobeDefaultAppearanceString);
        dictionary.setNeedToBeUpdated(true);
    }
    // DR entry is required
    PDResources defaultResources = getDefaultResources();
    if (defaultResources == null) {
        defaultResources = new PDResources();
        setDefaultResources(defaultResources);
        dictionary.setNeedToBeUpdated(true);
    }
    // PDFBOX-3732: Adobe Acrobat uses Helvetica as a default font and
    // stores that under the name '/Helv' in the resources dictionary
    // Zapf Dingbats is included per default for check boxes and
    // radio buttons as /ZaDb.
    // PDFBOX-4393: the two fonts are added by Adobe when signing
    // and this breaks a previous signature. (Might be an Adobe bug)
    COSDictionary fontDict = defaultResources.getCOSObject().getCOSDictionary(COSName.FONT);
    if (fontDict == null) {
        fontDict = new COSDictionary();
        defaultResources.getCOSObject().setItem(COSName.FONT, fontDict);
    }
    if (!fontDict.containsKey(COSName.HELV)) {
        defaultResources.put(COSName.HELV, PDType1Font.HELVETICA);
        defaultResources.getCOSObject().setNeedToBeUpdated(true);
        fontDict.setNeedToBeUpdated(true);
    }
    if (!fontDict.containsKey(COSName.ZA_DB)) {
        defaultResources.put(COSName.ZA_DB, PDType1Font.ZAPF_DINGBATS);
        defaultResources.getCOSObject().setNeedToBeUpdated(true);
        fontDict.setNeedToBeUpdated(true);
    }
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources)

Example 27 with PDResources

use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.

the class PDAcroForm method resolveNeedsTranslation.

/**
 * Check if there is a translation needed to place the annotations content.
 *
 * @param appearanceStream
 * @return the need for a translation transformation.
 */
private boolean resolveNeedsTranslation(PDAppearanceStream appearanceStream) {
    boolean needsTranslation = true;
    PDResources resources = appearanceStream.getResources();
    if (resources != null && resources.getXObjectNames().iterator().hasNext()) {
        Iterator<COSName> xObjectNames = resources.getXObjectNames().iterator();
        while (xObjectNames.hasNext()) {
            try {
                // if the BBox of the PDFormXObject does not start at 0,0
                // there is no need do translate as this is done by the BBox definition.
                PDXObject xObject = resources.getXObject(xObjectNames.next());
                if (xObject instanceof PDFormXObject) {
                    PDRectangle bbox = ((PDFormXObject) xObject).getBBox();
                    float llX = bbox.getLowerLeftX();
                    float llY = bbox.getLowerLeftY();
                    if (Float.compare(llX, 0) != 0 && Float.compare(llY, 0) != 0) {
                        needsTranslation = false;
                    }
                }
            } catch (IOException e) {
            // we can safely ignore the exception here
            // as this might only cause a misplacement
            }
        }
        return needsTranslation;
    }
    return true;
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) PDFormXObject(com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) IOException(java.io.IOException) PDXObject(com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)

Example 28 with PDResources

use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.

the class PDVisibleSigBuilder method createInnerFormResource.

@Override
public void createInnerFormResource() {
    PDResources innerFormResources = new PDResources();
    pdfStructure.setInnerFormResources(innerFormResources);
    Log.i("PdfBox-Android", "Resources of another form (inner form - it will be inside holder form)" + "have been created");
}
Also used : PDResources(com.tom_roush.pdfbox.pdmodel.PDResources)

Example 29 with PDResources

use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.

the class PDVisibleSigBuilder method createHolderFormResources.

@Override
public void createHolderFormResources() {
    PDResources holderFormResources = new PDResources();
    pdfStructure.setHolderFormResources(holderFormResources);
    Log.i("PdfBox-Android", "Holder form resources have been created");
}
Also used : PDResources(com.tom_roush.pdfbox.pdmodel.PDResources)

Example 30 with PDResources

use of com.tom_roush.pdfbox.pdmodel.PDResources in project PdfBox-Android by TomRoush.

the class PDVisibleSigBuilder method createImageFormResources.

@Override
public void createImageFormResources() {
    PDResources imageFormResources = new PDResources();
    pdfStructure.setImageFormResources(imageFormResources);
    Log.i("PdfBox-Android", "Created image form resources");
}
Also used : PDResources(com.tom_roush.pdfbox.pdmodel.PDResources)

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