Search in sources :

Example 96 with COSDictionary

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;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 97 with COSDictionary

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;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 98 with COSDictionary

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;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) Filter(com.tom_roush.pdfbox.filter.Filter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 99 with COSDictionary

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;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 100 with COSDictionary

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);
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) Filter(com.tom_roush.pdfbox.filter.Filter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)221 COSArray (com.tom_roush.pdfbox.cos.COSArray)68 COSBase (com.tom_roush.pdfbox.cos.COSBase)68 IOException (java.io.IOException)25 ArrayList (java.util.ArrayList)24 COSName (com.tom_roush.pdfbox.cos.COSName)23 COSObject (com.tom_roush.pdfbox.cos.COSObject)22 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)15 HashMap (java.util.HashMap)14 COSStream (com.tom_roush.pdfbox.cos.COSStream)13 Map (java.util.Map)12 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)10 COSString (com.tom_roush.pdfbox.cos.COSString)7 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)6 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 List (java.util.List)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 Test (org.junit.Test)5