/** * Displays a summary of the entries in the XObject dictionary for the stream * @param resourceDic the resource dictionary for the stream * @return a string with the summary of the entries * @throws IOException * @since 5.0.2 */ public static String GetXObjectDetail(PdfDictionary resourceDic) { StringBuilder sb = new StringBuilder(); PdfDictionary xobjects = resourceDic.GetAsDict(PdfName.XOBJECT); if (xobjects == null) { return("No XObjects"); } foreach (PdfName entryName in xobjects.Keys) { PdfStream xobjectStream = xobjects.GetAsStream(entryName); sb.Append("------ " + entryName + " - subtype = " + xobjectStream.Get(PdfName.SUBTYPE) + " = " + xobjectStream.GetAsNumber(PdfName.LENGTH) + " bytes ------\n"); if (!xobjectStream.Get(PdfName.SUBTYPE).Equals(PdfName.IMAGE)) { byte[] contentBytes = ContentByteUtils.GetContentBytesFromContentObject(xobjectStream); foreach (byte b in contentBytes) { sb.Append((char)b); } sb.Append("------ " + entryName + " - subtype = " + xobjectStream.Get(PdfName.SUBTYPE) + "End of Content" + "------\n"); } } return(sb.ToString()); }
public void HandleXObject(PdfContentStreamProcessor processor, PdfStream stream, PdfIndirectReference refi) { PdfDictionary resources = stream.GetAsDict(PdfName.RESOURCES); // we read the content bytes up here so if it fails we don't leave the graphics state stack corrupted // this is probably not necessary (if we fail on this, probably the entire content stream processing // operation should be rejected byte[] contentBytes; contentBytes = ContentByteUtils.GetContentBytesFromContentObject(stream); PdfArray matrix = stream.GetAsArray(PdfName.MATRIX); new PushGraphicsState().Invoke(processor, null, null); if (matrix != null) { float a = matrix.GetAsNumber(0).FloatValue; float b = matrix.GetAsNumber(1).FloatValue; float c = matrix.GetAsNumber(2).FloatValue; float d = matrix.GetAsNumber(3).FloatValue; float e = matrix.GetAsNumber(4).FloatValue; float f = matrix.GetAsNumber(5).FloatValue; Matrix formMatrix = new Matrix(a, b, c, d, e, f); processor.Gs().ctm = formMatrix.Multiply(processor.Gs().ctm); } processor.ProcessContent(contentBytes, resources); new PopGraphicsState().Invoke(processor, null, null); }
/** * Gets the content bytes of a page from a reader * @param reader the reader to get content bytes from * @param pageNum the page number of page you want get the content stream from * @return a byte array with the effective content stream of a page * @throws IOException * @since 5.0.1 */ public static byte[] GetContentBytesForPage(PdfReader reader, int pageNum) { PdfDictionary pageDictionary = reader.GetPageN(pageNum); PdfObject contentObject = pageDictionary.Get(PdfName.CONTENTS); if (contentObject == null) { return(new byte[0]); } byte[] contentBytes = ContentByteUtils.GetContentBytesFromContentObject(contentObject); return(contentBytes); }