Example usage for org.apache.pdfbox.cos COSDictionary setDirect

List of usage examples for org.apache.pdfbox.cos COSDictionary setDirect

Introduction

In this page you can find the example usage for org.apache.pdfbox.cos COSDictionary setDirect.

Prototype

public void setDirect(boolean direct) 

Source Link

Document

Set the state true, if the dictionary should be written as a direct object and not indirect.

Usage

From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java

License:EUPL

public void createAcroFormDictionary(PDAcroForm acroForm, PDSignatureField signatureField) throws IOException {
    @SuppressWarnings("unchecked")
    List<PDField> acroFormFields = acroForm.getFields();
    COSDictionary acroFormDict = acroForm.getDictionary();
    acroFormDict.setDirect(true);
    acroFormDict.setInt(COSName.SIG_FLAGS, 3);
    acroFormFields.add(signatureField);/*from   w  ww  .jav a  2s  .c  o m*/
    acroFormDict.setString(COSName.DA, "/sylfaen 0 Tf 0 g");
    getStructure().setAcroFormFields(acroFormFields);
    getStructure().setAcroFormDictionary(acroFormDict);
    logger.debug("AcroForm dictionary has been created");
}

From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.PDFAsVisualSignatureBuilder.java

License:EUPL

public void createAcroFormDictionary(PDAcroForm acroForm, PDSignatureField signatureField) throws IOException {
    @SuppressWarnings("unchecked")
    List<PDField> acroFormFields = acroForm.getFields();
    COSDictionary acroFormDict = acroForm.getCOSObject();
    acroFormDict.setDirect(true);
    acroFormDict.setInt(COSName.SIG_FLAGS, 3);
    acroFormFields.add(signatureField);// w ww  . ja v  a2s  .c  o  m
    acroFormDict.setString(COSName.DA, "/sylfaen 0 Tf 0 g");
    getStructure().setAcroFormFields(acroFormFields);
    getStructure().setAcroFormDictionary(acroFormDict);
    logger.debug("AcroForm dictionary has been created");
}

From source file:eu.europa.esig.dss.pdf.pdfbox.PdfBoxSignatureService.java

License:Open Source License

private COSDictionary buildDSSDictionary(List<DSSDictionaryCallback> callbacks) throws Exception {
    COSDictionary dss = new COSDictionary();

    Map<String, COSStream> streams = new HashMap<String, COSStream>();

    Set<CRLToken> allCrls = new HashSet<CRLToken>();
    Set<OCSPToken> allOcsps = new HashSet<OCSPToken>();
    Set<CertificateToken> allCertificates = new HashSet<CertificateToken>();

    COSDictionary vriDictionary = new COSDictionary();
    for (DSSDictionaryCallback callback : callbacks) {
        COSDictionary sigVriDictionary = new COSDictionary();
        sigVriDictionary.setDirect(true);

        if (CollectionUtils.isNotEmpty(callback.getCertificates())) {
            COSArray vriCertArray = new COSArray();
            for (CertificateToken token : callback.getCertificates()) {
                vriCertArray.add(getStream(streams, token));
                allCertificates.add(token);
            }//from w ww.j av a  2 s .com
            sigVriDictionary.setItem("Cert", vriCertArray);
        }

        if (CollectionUtils.isNotEmpty(callback.getOcsps())) {
            COSArray vriOcspArray = new COSArray();
            for (OCSPToken token : callback.getOcsps()) {
                vriOcspArray.add(getStream(streams, token));
                allOcsps.add(token);
            }
            sigVriDictionary.setItem("OCSP", vriOcspArray);
        }

        if (CollectionUtils.isNotEmpty(callback.getCrls())) {
            COSArray vriCrlArray = new COSArray();
            for (CRLToken token : callback.getCrls()) {
                vriCrlArray.add(getStream(streams, token));
                allCrls.add(token);
            }
            sigVriDictionary.setItem("CRL", vriCrlArray);
        }

        PAdESSignature signature = callback.getSignature();
        final byte[] digest = DSSUtils.digest(DigestAlgorithm.SHA1,
                signature.getCAdESSignature().getCmsSignedData().getEncoded());
        String hexHash = Hex.encodeHexString(digest).toUpperCase();

        vriDictionary.setItem(hexHash, sigVriDictionary);
    }
    dss.setItem("VRI", vriDictionary);

    if (CollectionUtils.isNotEmpty(allCertificates)) {
        COSArray arrayAllCerts = new COSArray();
        for (CertificateToken token : allCertificates) {
            arrayAllCerts.add(getStream(streams, token));
        }
        dss.setItem("Certs", arrayAllCerts);
    }

    if (CollectionUtils.isNotEmpty(allOcsps)) {
        COSArray arrayAllOcsps = new COSArray();
        for (OCSPToken token : allOcsps) {
            arrayAllOcsps.add(getStream(streams, token));
        }
        dss.setItem("OCSPs", arrayAllOcsps);
    }

    if (CollectionUtils.isNotEmpty(allCrls)) {
        COSArray arrayAllCrls = new COSArray();
        for (CRLToken token : allCrls) {
            arrayAllCrls.add(getStream(streams, token));
        }
        dss.setItem("CRLs", arrayAllCrls);
    }

    return dss;
}

From source file:pdfpicmangler.PDPng.java

License:Open Source License

/**
 * Construct from a stream.// w  w  w  . ja va  2 s  . co  m
 * 
 * @param doc The document to create the image as part of.
 * @param is The stream that contains the png data.
 * @throws IOException If there is an error reading the png data.
 */
public PDPng(PDDocument doc, InputStream is) throws IOException {
    super(doc, "png");

    System.out.println("reading in png");

    COSDictionary dic = getCOSStream();

    dic.setItem(COSName.SUBTYPE, COSName.IMAGE);
    //dic.setItem(COSName.TYPE, COSName.XOBJECT);

    data = getCOSStream().createFilteredStream();

    readPng(is);

    setWidth(imageWidth);
    setHeight(imageHeight);
    dic.setInt(COSName.BITS_PER_COMPONENT, bitDepth);

    if ((colorType & PNG_TYPE_PALETTE) != 0) {
        getCOSStream().setItem(COSName.COLORSPACE, paldata);
    } else if ((colorType & PNG_TYPE_COLOR) != 0) {
        setColorSpace(PDDeviceRGB.INSTANCE);
    } else {
        setColorSpace(new PDDeviceGray());
    }

    COSDictionary filterParams = new COSDictionary();
    filterParams.setInt(COSName.PREDICTOR, 15); // png adaptive predictor
    filterParams.setInt(COSName.COLORS,
            ((colorType & PNG_TYPE_COLOR) == 0 || (colorType & PNG_TYPE_PALETTE) != 0) ? 1 : 3);
    filterParams.setInt(COSName.BITS_PER_COMPONENT, bitDepth);
    filterParams.setInt(COSName.COLUMNS, imageWidth);
    filterParams.setDirect(true);

    dic.setItem(COSName.DECODE_PARMS, filterParams);
    dic.setItem(COSName.FILTER, COSName.FLATE_DECODE);

    dic.setInt(COSName.LENGTH, dataLen);
    dic.getDictionaryObject(COSName.LENGTH).setDirect(true);
}