use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class PDOptionalContentProperties method setGroupEnabled.
/**
* Enables or disables all optional content groups with the given name.
*
* @param groupName the group name
* @param enable true to enable, false to disable
* @return true if at least one group with this name already had an on or off setting, false
* otherwise
*/
public boolean setGroupEnabled(String groupName, boolean enable) {
boolean result = false;
COSArray ocgs = getOCGs();
for (COSBase o : ocgs) {
COSDictionary ocg = toDictionary(o);
String name = ocg.getString(COSName.NAME);
if (groupName.equals(name) && setGroupEnabled(new PDOptionalContentGroup(ocg), enable)) {
result = true;
}
}
return result;
}
use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class PDOptionalContentProperties method getD.
private COSDictionary getD() {
COSBase base = this.dict.getDictionaryObject(COSName.D);
if (base instanceof COSDictionary) {
return (COSDictionary) base;
}
COSDictionary d = new COSDictionary();
// Name optional but required for PDF/A-3
d.setString(COSName.NAME, "Top");
// D is required
this.dict.setItem(COSName.D, d);
return d;
}
use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class CCITTFactory method prepareImageXObject.
private static PDImageXObject prepareImageXObject(PDDocument document, byte[] byteArray, int width, int height, PDColorSpace initColorSpace) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Filter filter = FilterFactory.INSTANCE.getFilter(COSName.CCITTFAX_DECODE);
COSDictionary dict = new COSDictionary();
dict.setInt(COSName.COLUMNS, width);
dict.setInt(COSName.ROWS, height);
filter.encode(new ByteArrayInputStream(byteArray), baos, dict, 0);
ByteArrayInputStream encodedByteStream = new ByteArrayInputStream(baos.toByteArray());
PDImageXObject image = new PDImageXObject(document, encodedByteStream, COSName.CCITTFAX_DECODE, width, height, 1, initColorSpace);
dict.setInt(COSName.K, -1);
image.getCOSObject().setItem(COSName.DECODE_PARMS, dict);
return image;
}
use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class CCITTFactory method createFromRandomAccessImpl.
/**
* Creates a new CCITT Fax compressed image XObject from a TIFF file.
*
* @param document the document to create the image as part of.
* @param reader the random access TIFF file which contains a suitable CCITT
* compressed image
* @param number TIFF image number, starting from 0
* @return a new Image XObject, or null if no such page
* @throws IOException if there is an error reading the TIFF data.
*/
private static PDImageXObject createFromRandomAccessImpl(PDDocument document, RandomAccess reader, int number) throws IOException {
COSDictionary decodeParms = new COSDictionary();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
extractFromTiff(reader, bos, decodeParms, number);
if (bos.size() == 0) {
return null;
}
ByteArrayInputStream encodedByteStream = new ByteArrayInputStream(bos.toByteArray());
PDImageXObject pdImage = new PDImageXObject(document, encodedByteStream, COSName.CCITTFAX_DECODE, decodeParms.getInt(COSName.COLUMNS), decodeParms.getInt(COSName.ROWS), 1, PDDeviceGray.INSTANCE);
COSDictionary dict = pdImage.getCOSObject();
dict.setItem(COSName.DECODE_PARMS, decodeParms);
return pdImage;
}
use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class LosslessFactory method prepareImageXObject.
/**
* Create a PDImageXObject using the Flate filter.
*
* @param document The document.
* @param byteArray array with data.
* @param width the image width
* @param height the image height
* @param bitsPerComponent the bits per component
* @param initColorSpace the color space
* @return the newly created PDImageXObject with the data compressed.
* @throws IOException
*/
static PDImageXObject prepareImageXObject(PDDocument document, byte[] byteArray, int width, int height, int bitsPerComponent, PDColorSpace initColorSpace) throws IOException {
// pre-size the output stream to half of the input
ByteArrayOutputStream baos = new ByteArrayOutputStream(byteArray.length / 2);
Filter filter = FilterFactory.INSTANCE.getFilter(COSName.FLATE_DECODE);
filter.encode(new ByteArrayInputStream(byteArray), baos, new COSDictionary(), 0);
ByteArrayInputStream encodedByteStream = new ByteArrayInputStream(baos.toByteArray());
return new PDImageXObject(document, encodedByteStream, COSName.FLATE_DECODE, width, height, bitsPerComponent, initColorSpace);
}
Aggregations