Java Code Examples for org.apache.pdfbox.cos.COSDictionary#setNeedToBeUpdated()

The following examples show how to use org.apache.pdfbox.cos.COSDictionary#setNeedToBeUpdated() . 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: PdfBoxSignatureService.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public DSSDocument addDssDictionary(DSSDocument document, List<DSSDictionaryCallback> callbacks, String pwd) {
	try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
			InputStream is = document.openStream();
			PDDocument pdDocument = PDDocument.load(is, pwd)) {

		if (Utils.isCollectionNotEmpty(callbacks)) {
			final COSDictionary cosDictionary = pdDocument.getDocumentCatalog().getCOSObject();
			cosDictionary.setItem(PAdESConstants.DSS_DICTIONARY_NAME, buildDSSDictionary(pdDocument, callbacks));
			cosDictionary.setNeedToBeUpdated(true);
		}
		
		// encryption is not required (no signature/timestamp is added on the step)
		saveDocumentIncrementally(pdDocument, baos);

		DSSDocument inMemoryDocument = new InMemoryDocument(baos.toByteArray());
		inMemoryDocument.setMimeType(MimeType.PDF);
		return inMemoryDocument;

	} catch (Exception e) {
		throw new DSSException(e);
	}
}
 
Example 2
Source File: PDDocument.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void assignAcroFormDefaultResource(PDAcroForm acroForm, COSDictionary newDict)
{
    // read and set/update AcroForm default resource dictionary /DR if available
    COSBase newBase = newDict.getDictionaryObject(COSName.DR);
    if (newBase instanceof COSDictionary)
    {
        COSDictionary newDR = (COSDictionary) newBase;
        PDResources defaultResources = acroForm.getDefaultResources();
        if (defaultResources == null)
        {
            acroForm.getCOSObject().setItem(COSName.DR, newDR);
            newDR.setDirect(true);
            newDR.setNeedToBeUpdated(true);            
        }
        else
        {
            COSDictionary oldDR = defaultResources.getCOSObject();
            COSBase newXObjectBase = newDR.getItem(COSName.XOBJECT);
            COSBase oldXObjectBase = oldDR.getItem(COSName.XOBJECT);
            if (newXObjectBase instanceof COSDictionary &&
                oldXObjectBase instanceof COSDictionary)
            {
                ((COSDictionary) oldXObjectBase).addAll((COSDictionary) newXObjectBase);
                oldDR.setNeedToBeUpdated(true);
            }
        }
    }
}
 
Example 3
Source File: PDVisibleSigBuilder.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void createWidgetDictionary(PDSignatureField signatureField,
                                   PDResources holderFormResources) throws IOException
{
    COSDictionary widgetDict = signatureField.getWidgets().get(0).getCOSObject();
    widgetDict.setNeedToBeUpdated(true);
    widgetDict.setItem(COSName.DR, holderFormResources.getCOSObject());

    pdfStructure.setWidgetDictionary(widgetDict);
    LOG.info("WidgetDictionary has been created");
}
 
Example 4
Source File: PdfBoxSignatureService.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Set the access permissions granted for this document in the DocMDP transform
 * parameters dictionary. Details are described in the table "Entries in the
 * DocMDP transform parameters dictionary" in the PDF specification.
 *
 * @param doc               The document.
 * @param signature         The signature object.
 * @param accessPermissions The permission value (1, 2 or 3).
 */
public void setMDPPermission(PDDocument doc, PDSignature signature, int accessPermissions) {
	COSDictionary sigDict = signature.getCOSObject();

	// DocMDP specific stuff
	COSDictionary transformParameters = new COSDictionary();
	transformParameters.setItem(COSName.TYPE, COSName.getPDFName("TransformParams"));
	transformParameters.setInt(COSName.P, accessPermissions);
	transformParameters.setName(COSName.V, "1.2");
	transformParameters.setNeedToBeUpdated(true);

	COSDictionary referenceDict = new COSDictionary();
	referenceDict.setItem(COSName.TYPE, COSName.getPDFName("SigRef"));
	referenceDict.setItem("TransformMethod", COSName.DOCMDP);
	referenceDict.setItem("TransformParams", transformParameters);
	referenceDict.setNeedToBeUpdated(true);

	COSArray referenceArray = new COSArray();
	referenceArray.add(referenceDict);
	sigDict.setItem("Reference", referenceArray);
	referenceArray.setNeedToBeUpdated(true);

	// Document Catalog
	COSDictionary catalogDict = doc.getDocumentCatalog().getCOSObject();
	COSDictionary permsDict = new COSDictionary();
	catalogDict.setItem(COSName.PERMS, permsDict);
	permsDict.setItem(COSName.DOCMDP, signature);
	catalogDict.setNeedToBeUpdated(true);
	permsDict.setNeedToBeUpdated(true);
}