Search in sources :

Example 1 with PDOutputIntent

use of com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent in project PdfBox-Android by TomRoush.

the class PDFMergerUtility method mergeOutputIntents.

// copy outputIntents to destination, but avoid duplicate OutputConditionIdentifier,
// except when it is missing or is named "Custom".
private void mergeOutputIntents(PDFCloneUtility cloner, PDDocumentCatalog srcCatalog, PDDocumentCatalog destCatalog) throws IOException {
    List<PDOutputIntent> srcOutputIntents = srcCatalog.getOutputIntents();
    List<PDOutputIntent> dstOutputIntents = destCatalog.getOutputIntents();
    for (PDOutputIntent srcOI : srcOutputIntents) {
        String srcOCI = srcOI.getOutputConditionIdentifier();
        if (srcOCI != null && !"Custom".equals(srcOCI)) {
            // is that identifier already there?
            boolean skip = false;
            for (PDOutputIntent dstOI : dstOutputIntents) {
                if (dstOI.getOutputConditionIdentifier().equals(srcOCI)) {
                    skip = true;
                    break;
                }
            }
            if (skip) {
                continue;
            }
        }
        destCatalog.addOutputIntent(new PDOutputIntent((COSDictionary) cloner.cloneForNewDocument(srcOI)));
        dstOutputIntents.add(srcOI);
    }
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) PDOutputIntent(com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent)

Example 2 with PDOutputIntent

use of com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent in project PdfBox-Android by TomRoush.

the class TestPDDocumentCatalog method handleOutputIntents.

/**
 * Test OutputIntents functionality.
 *
 * Test case for
 * <a https://issues.apache.org/jira/browse/PDFBOX-2687">PDFBOX-2687</a>
 * ClassCastException when trying to get OutputIntents or add to it.
 *
 * @throws IOException in case the document can not be parsed.
 */
@Test
public void handleOutputIntents() throws IOException {
    PDDocument doc = null;
    InputStream colorProfile = null;
    try {
        doc = PDDocument.load(TestPDDocumentCatalog.class.getResourceAsStream("/pdfbox/com/tom_roush/pdfbox/pdmodel/test.unc.pdf"));
        PDDocumentCatalog catalog = doc.getDocumentCatalog();
        // retrieve OutputIntents
        List<PDOutputIntent> outputIntents = catalog.getOutputIntents();
        assertTrue(outputIntents.isEmpty());
        // add an OutputIntent
        colorProfile = TestPDDocumentCatalog.class.getResourceAsStream("/pdfbox/com/tom_roush/pdfbox/pdmodel/sRGB.icc");
        // create output intent
        PDOutputIntent oi = new PDOutputIntent(doc, colorProfile);
        oi.setInfo("sRGB IEC61966-2.1");
        oi.setOutputCondition("sRGB IEC61966-2.1");
        oi.setOutputConditionIdentifier("sRGB IEC61966-2.1");
        oi.setRegistryName("http://www.color.org");
        doc.getDocumentCatalog().addOutputIntent(oi);
        // retrieve OutputIntents
        outputIntents = catalog.getOutputIntents();
        assertEquals(1, outputIntents.size());
        // set OutputIntents
        catalog.setOutputIntents(outputIntents);
        outputIntents = catalog.getOutputIntents();
        assertEquals(1, outputIntents.size());
    } finally {
        if (doc != null) {
            doc.close();
        }
        if (colorProfile != null) {
            colorProfile.close();
        }
    }
}
Also used : InputStream(java.io.InputStream) PDOutputIntent(com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent) Test(org.junit.Test)

Example 3 with PDOutputIntent

use of com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent in project PdfBox-Android by TomRoush.

the class PDDocumentCatalog method setOutputIntents.

/**
 * Replace the list of OutputIntents of the document.
 *
 * @param outputIntents the list of OutputIntents, if the list is empty all OutputIntents are
 * removed.
 */
public void setOutputIntents(List<PDOutputIntent> outputIntents) {
    COSArray array = new COSArray();
    for (PDOutputIntent intent : outputIntents) {
        array.add(intent.getCOSObject());
    }
    root.setItem(COSName.OUTPUT_INTENTS, array);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDOutputIntent(com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent)

Example 4 with PDOutputIntent

use of com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent in project PdfBox-Android by TomRoush.

the class PDDocumentCatalog method getOutputIntents.

/**
 * Get the list of OutputIntents defined in the document.
 *
 * @return The list of PDOutputIntent
 */
public List<PDOutputIntent> getOutputIntents() {
    List<PDOutputIntent> retval = new ArrayList<PDOutputIntent>();
    COSArray array = (COSArray) root.getDictionaryObject(COSName.OUTPUT_INTENTS);
    if (array != null) {
        for (COSBase cosBase : array) {
            if (cosBase instanceof COSObject) {
                cosBase = ((COSObject) cosBase).getObject();
            }
            PDOutputIntent oi = new PDOutputIntent((COSDictionary) cosBase);
            retval.add(oi);
        }
    }
    return retval;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSObject(com.tom_roush.pdfbox.cos.COSObject) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDOutputIntent(com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent)

Aggregations

PDOutputIntent (com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent)4 COSArray (com.tom_roush.pdfbox.cos.COSArray)2 COSBase (com.tom_roush.pdfbox.cos.COSBase)1 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 COSObject (com.tom_roush.pdfbox.cos.COSObject)1 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1