use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDStream method createInputStream.
/**
* This will get a stream with some filters applied but not others. This is
* useful when doing images, ie filters = [flate,dct], we want to remove
* flate but leave dct
*
* @param stopFilters A list of filters to stop decoding at.
* @return A stream with decoded data.
* @throws IOException If there is an error processing the stream.
*/
public InputStream createInputStream(List<String> stopFilters) throws IOException {
InputStream is = stream.createRawInputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
List<COSName> filters = getFilters();
if (filters != null) {
for (int i = 0; i < filters.size(); i++) {
COSName nextFilter = filters.get(i);
if ((stopFilters != null) && stopFilters.contains(nextFilter.getName())) {
break;
} else {
Filter filter = FilterFactory.INSTANCE.getFilter(nextFilter);
filter.decode(is, os, stream, i);
IOUtils.closeQuietly(is);
is = new ByteArrayInputStream(os.toByteArray());
os.reset();
}
}
}
return is;
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDStream method addCompression.
/**
* If there are not compression filters on the current stream then this will
* add a compression filter, flate compression for example.
*
* @deprecated This method is inefficient. To copying an existing InputStream, use
* {@link #PDStream(PDDocument, InputStream, COSName)} instead, with
* COSName.FLATE_DECODE as the final argument.
*
* Otherwise, to write new compressed data, use {@link #createOutputStream(COSName)},
* with COSName.FLATE_DECODE as the argument.
*/
@Deprecated
public void addCompression() {
List<COSName> filters = getFilters();
if (filters == null) {
if (stream.getLength() > 0) {
OutputStream out = null;
try {
byte[] bytes = IOUtils.toByteArray(stream.createInputStream());
out = stream.createOutputStream(COSName.FLATE_DECODE);
out.write(bytes);
} catch (IOException e) {
// not much else we can do here without breaking the existing API, sorry.
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(out);
}
} else {
filters = new ArrayList<COSName>();
filters.add(COSName.FLATE_DECODE);
setFilters(filters);
}
}
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDStream method getFileFilters.
/**
* This will get the list of filters that are associated with this stream.
* Or null if there are none.
*
* @return A list of all encoding filters to apply to this stream.
*/
public List<String> getFileFilters() {
List<String> retval = null;
COSBase filters = stream.getDictionaryObject(COSName.F_FILTER);
if (filters instanceof COSName) {
COSName name = (COSName) filters;
retval = new COSArrayList<String>(name.getName(), name, stream, COSName.F_FILTER);
} else if (filters instanceof COSArray) {
retval = COSArrayList.convertCOSNameCOSArrayToList((COSArray) filters);
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDResources method add.
/**
* Adds the given resource if it does not already exist.
*/
private COSName add(COSName kind, String prefix, COSObjectable object) {
// return the existing key if the item exists already
COSDictionary dict = (COSDictionary) resources.getDictionaryObject(kind);
if (dict != null && dict.containsValue(object.getCOSObject())) {
return dict.getKeyForValue(object.getCOSObject());
}
// AcroForm default resources of a loaded PDF.
if (dict != null && COSName.FONT.equals(kind)) {
for (Map.Entry<COSName, COSBase> entry : dict.entrySet()) {
if (entry.getValue() instanceof COSObject && object.getCOSObject() == ((COSObject) entry.getValue()).getObject()) {
return entry.getKey();
}
}
}
// add the item with a new key
COSName name = createKey(kind, prefix);
put(kind, name, object);
return name;
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDFontDescriptor method setFontStretch.
/**
* This will set the font stretch.
*
* @param fontStretch The new stretch for the font.
*/
public void setFontStretch(String fontStretch) {
COSName name = null;
if (fontStretch != null) {
name = COSName.getPDFName(fontStretch);
}
dic.setItem(COSName.FONT_STRETCH, name);
}
Aggregations