Search in sources :

Example 1 with PDStream

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();
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSArray(com.tom_roush.pdfbox.cos.COSArray) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDStream(com.tom_roush.pdfbox.pdmodel.common.PDStream)

Example 2 with PDStream

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

Example 3 with PDStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PDStream(com.tom_roush.pdfbox.pdmodel.common.PDStream)

Example 4 with PDStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PDStream(com.tom_roush.pdfbox.pdmodel.common.PDStream) IOException(java.io.IOException) TTFParser(com.tom_roush.fontbox.ttf.TTFParser)

Example 5 with PDStream

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

Aggregations

PDStream (com.tom_roush.pdfbox.pdmodel.common.PDStream)18 COSStream (com.tom_roush.pdfbox.cos.COSStream)6 COSBase (com.tom_roush.pdfbox.cos.COSBase)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 COSArray (com.tom_roush.pdfbox.cos.COSArray)3 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)3 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)3 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)3 IOException (java.io.IOException)3 AffineTransform (com.tom_roush.harmony.awt.geom.AffineTransform)2 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)2 COSName (com.tom_roush.pdfbox.cos.COSName)2 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)2 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 TTFParser (com.tom_roush.fontbox.ttf.TTFParser)1 BoundingBox (com.tom_roush.fontbox.util.BoundingBox)1 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)1 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)1