/// <summary> /// Gets the content stream of a page as a PdfStream object. /// @since 2.1.3 (the method already existed without param compressionLevel) /// </summary> /// <param name="pageNumber">the page of which you want the stream</param> /// <param name="compressionLevel">the compression level you want to apply to the stream</param> /// <returns>a PdfStream object</returns> internal PdfStream GetFormXObject(int pageNumber, int compressionLevel) { var page = reader.GetPageNRelease(pageNumber); var contents = PdfReader.GetPdfObjectRelease(page.Get(PdfName.Contents)); var dic = new PdfDictionary(); byte[] bout = null; if (contents != null) { if (contents.IsStream()) { dic.Merge((PrStream)contents); } else { bout = reader.GetPageContent(pageNumber, File); } } else { bout = new byte[0]; } dic.Put(PdfName.Resources, PdfReader.GetPdfObjectRelease(page.Get(PdfName.Resources))); dic.Put(PdfName.TYPE, PdfName.Xobject); dic.Put(PdfName.Subtype, PdfName.Form); var impPage = (PdfImportedPage)ImportedPages[pageNumber]; dic.Put(PdfName.Bbox, new PdfRectangle(impPage.BoundingBox)); var matrix = impPage.Matrix; if (matrix == null) { dic.Put(PdfName.Matrix, Identitymatrix); } else { dic.Put(PdfName.Matrix, matrix); } dic.Put(PdfName.Formtype, One); PrStream stream; if (bout == null) { stream = new PrStream((PrStream)contents, dic); } else { stream = new PrStream(reader, bout); stream.Merge(dic); } return(stream); }