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);
}
}
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();
}
}
}
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);
}
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;
}
Aggregations