Java Code Examples for com.lowagie.text.pdf.PdfReader#getStreamBytes()
The following examples show how to use
com.lowagie.text.pdf.PdfReader#getStreamBytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfContentStreamProcessor.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
public static byte[] getContentBytesFromPdfObject(PdfObject object) throws IOException { switch (object.type()) { case PdfObject.INDIRECT: return getContentBytesFromPdfObject(PdfReader.getPdfObject(object)); case PdfObject.STREAM: return PdfReader.getStreamBytes((PRStream) PdfReader.getPdfObject(object)); case PdfObject.ARRAY: ByteArrayOutputStream baos = new ByteArrayOutputStream(); ListIterator<PdfObject> iter = ((PdfArray) object).listIterator(); while (iter.hasNext()) { PdfObject element = iter.next(); baos.write(getContentBytesFromPdfObject(element)); } return baos.toByteArray(); default: throw new IllegalStateException("Unsupported type: " + object.getClass().getCanonicalName()); } }
Example 2
Source File: PdfContentStreamProcessorTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
private byte[] readContentBytes(final PdfObject contentObject) throws IOException { final byte[] result; switch (contentObject.type()) { case PdfObject.INDIRECT: final PRIndirectReference ref = (PRIndirectReference) contentObject; final PdfObject directObject = PdfReader.getPdfObject(ref); result = readContentBytes(directObject); break; case PdfObject.STREAM: final PRStream stream = (PRStream) PdfReader.getPdfObject(contentObject); result = PdfReader.getStreamBytes(stream); break; case PdfObject.ARRAY: // Stitch together all content before calling processContent(), // because // processContent() resets state. final ByteArrayOutputStream allBytes = new ByteArrayOutputStream(); final PdfArray contentArray = (PdfArray) contentObject; final ListIterator<?> iter = contentArray.listIterator(); while (iter.hasNext()) { final PdfObject element = (PdfObject) iter.next(); allBytes.write(readContentBytes(element)); } result = allBytes.toByteArray(); break; default: final String msg = "Unable to handle Content of type " + contentObject.getClass(); throw new IllegalStateException(msg); } return result; }
Example 3
Source File: ITextPdfArray.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
@Override public byte[] getBytes(int i) throws IOException { return PdfReader.getStreamBytes((PRStream) wrapped.getAsStream(i)); }