use of com.tom_roush.pdfbox.pdmodel.common.PDStream in project PdfBox-Android by TomRoush.
the class PDPage method getContentStreams.
/**
* Returns the content streams which make up this page.
*
* @return content stream iterator
*/
public Iterator<PDStream> getContentStreams() {
List<PDStream> streams = new ArrayList<PDStream>();
COSBase base = page.getDictionaryObject(COSName.CONTENTS);
if (base instanceof COSStream) {
streams.add(new PDStream((COSStream) base));
} else if (base instanceof COSArray && ((COSArray) base).size() > 0) {
COSArray array = (COSArray) base;
for (int i = 0; i < array.size(); i++) {
COSStream stream = (COSStream) array.getObject(i);
streams.add(new PDStream(stream));
}
}
return streams.iterator();
}
use of com.tom_roush.pdfbox.pdmodel.common.PDStream in project PdfBox-Android by TomRoush.
the class PDPage method setContents.
/**
* This will set the contents of this page.
*
* @param contents Array of new contents of the page.
*/
public void setContents(List<PDStream> contents) {
COSArray array = new COSArray();
for (PDStream stream : contents) {
array.add(stream);
}
page.setItem(COSName.CONTENTS, array);
}
use of com.tom_roush.pdfbox.pdmodel.common.PDStream in project PdfBox-Android by TomRoush.
the class PDCIDFontType2Embedder method buildCIDSet.
/**
* Builds the CIDSet entry, required by PDF/A. This lists all CIDs in the font, including those
* that don't have a GID.
*/
private void buildCIDSet(Map<Integer, Integer> cidToGid) throws IOException {
int cidMax = Collections.max(cidToGid.keySet());
byte[] bytes = new byte[cidMax / 8 + 1];
for (int cid = 0; cid <= cidMax; cid++) {
int mask = 1 << 7 - cid % 8;
bytes[cid / 8] |= mask;
}
InputStream input = new ByteArrayInputStream(bytes);
PDStream stream = new PDStream(document, input, COSName.FLATE_DECODE);
fontDescriptor.setCIDSet(stream);
}
use of com.tom_roush.pdfbox.pdmodel.common.PDStream in project PdfBox-Android by TomRoush.
the class TrueTypeEmbedder method buildFontFile2.
public void buildFontFile2(InputStream ttfStream) throws IOException {
PDStream stream = new PDStream(document, ttfStream, COSName.FLATE_DECODE);
// as the stream was closed within the PDStream constructor, we have to recreate it
InputStream input = null;
try {
input = stream.createInputStream();
ttf = new TTFParser().parseEmbedded(input);
if (!isEmbeddingPermitted(ttf)) {
throw new IOException("This font does not permit embedding");
}
if (fontDescriptor == null) {
fontDescriptor = createFontDescriptor(ttf);
}
} finally {
IOUtils.closeQuietly(input);
}
stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize());
fontDescriptor.setFontFile2(stream);
}
use of com.tom_roush.pdfbox.pdmodel.common.PDStream in project PdfBox-Android by TomRoush.
the class PDFontDescriptor method getFontFile.
/**
* A stream containing a Type 1 font program.
*
* @return A stream containing a Type 1 font program.
*/
public PDStream getFontFile() {
PDStream retval = null;
COSBase obj = dic.getDictionaryObject(COSName.FONT_FILE);
if (obj instanceof COSStream) {
retval = new PDStream((COSStream) obj);
}
return retval;
}
Aggregations