Beispiel #1
0
        /**
         * Add an imported page to our output
         * @param iPage an imported page
         * @throws IOException, BadPdfFormatException
         */
        public void AddPage(PdfImportedPage iPage)
        {
            int pageNum = SetFromIPage(iPage);

            PdfDictionary       thePage = reader.GetPageN(pageNum);
            PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);

            reader.ReleasePage(pageNum);
            RefKey key = new RefKey(origRef);
            PdfIndirectReference pageRef;
            IndirectReferences   iRef = (IndirectReferences)indirects[key];

            if (iRef != null && !iRef.Copied)
            {
                pageReferences.Add(iRef.Ref);
                iRef.SetCopied();
            }
            pageRef = CurrentPage;
            if (iRef == null)
            {
                iRef           = new IndirectReferences(pageRef);
                indirects[key] = iRef;
            }
            iRef.SetCopied();
            PdfDictionary newPage = CopyDictionary(thePage);

            root.AddPage(newPage);
            ++currentPageNumber;
        }
Beispiel #2
0
        /**
         * Create a page stamp. New content and annotations, including new fields, are allowed.
         * The fields added cannot have parents in another pages. This method modifies the PdfReader instance.<p>
         * The general usage to stamp something in a page is:
         * <p>
         * <pre>
         * PdfImportedPage page = copy.getImportedPage(reader, 1);
         * PdfCopy.PageStamp ps = copy.createPageStamp(page);
         * ps.addAnnotation(PdfAnnotation.createText(copy, new Rectangle(50, 180, 70, 200), "Hello", "No Thanks", true, "Comment"));
         * PdfContentByte under = ps.getUnderContent();
         * under.addImage(img);
         * PdfContentByte over = ps.getOverContent();
         * over.beginText();
         * over.setFontAndSize(bf, 18);
         * over.setTextMatrix(30, 30);
         * over.showText("total page " + totalPage);
         * over.endText();
         * ps.alterContents();
         * copy.addPage(page);
         * </pre>
         * @param iPage an imported page
         * @return the <CODE>PageStamp</CODE>
         */
        public PageStamp CreatePageStamp(PdfImportedPage iPage)
        {
            int           pageNum = iPage.PageNumber;
            PdfReader     reader  = iPage.PdfReaderInstance.Reader;
            PdfDictionary pageN   = reader.GetPageN(pageNum);

            return(new PageStamp(reader, pageN, this));
        }
Beispiel #3
0
        /**
         * convenience method. Given an importedpage, set our "globals"
         */
        protected int SetFromIPage(PdfImportedPage iPage)
        {
            int pageNum            = iPage.PageNumber;
            PdfReaderInstance inst = currentPdfReaderInstance = iPage.PdfReaderInstance;

            reader = inst.Reader;
            SetFromReader(reader);
            return(pageNum);
        }
        /**
         * Gets the content stream of a page as a PdfStream object.
         * @param   pageNumber          the page of which you want the stream
         * @param   compressionLevel    the compression level you want to apply to the stream
         * @return  a PdfStream object
         * @since   2.1.3 (the method already existed without param compressionLevel)
         */
        internal PdfStream GetFormXObject(int pageNumber, int compressionLevel)
        {
            PdfDictionary page     = reader.GetPageNRelease(pageNumber);
            PdfObject     contents = PdfReader.GetPdfObjectRelease(page.Get(PdfName.CONTENTS));
            PdfDictionary 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);
            PdfImportedPage impPage = (PdfImportedPage)importedPages[pageNumber];

            dic.Put(PdfName.BBOX, new PdfRectangle(impPage.BoundingBox));
            PdfArray 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);
        }
        internal PdfImportedPage GetImportedPage(int pageNumber)
        {
            if (!reader.IsOpenedWithFullPermissions)
            {
                throw new ArgumentException("PdfReader not opened with owner password");
            }
            if (pageNumber < 1 || pageNumber > reader.NumberOfPages)
            {
                throw new ArgumentException("Invalid page number: " + pageNumber);
            }
            PdfImportedPage pageT = (PdfImportedPage)importedPages[pageNumber];

            if (pageT == null)
            {
                pageT = new PdfImportedPage(this, writer, pageNumber);
                importedPages[pageNumber] = pageT;
            }
            return(pageT);
        }
Beispiel #6
0
 /**
 * convenience method. Given an importedpage, set our "globals"
 */
 protected int SetFromIPage(PdfImportedPage iPage)
 {
     int pageNum = iPage.PageNumber;
     PdfReaderInstance inst = currentPdfReaderInstance = iPage.PdfReaderInstance;
     reader = inst.Reader;
     SetFromReader(reader);
     return pageNum;
 }
Beispiel #7
0
 /**
 * Create a page stamp. New content and annotations, including new fields, are allowed.
 * The fields added cannot have parents in another pages. This method modifies the PdfReader instance.<p>
 * The general usage to stamp something in a page is:
 * <p>
 * <pre>
 * PdfImportedPage page = copy.getImportedPage(reader, 1);
 * PdfCopy.PageStamp ps = copy.createPageStamp(page);
 * ps.addAnnotation(PdfAnnotation.createText(copy, new Rectangle(50, 180, 70, 200), "Hello", "No Thanks", true, "Comment"));
 * PdfContentByte under = ps.getUnderContent();
 * under.addImage(img);
 * PdfContentByte over = ps.getOverContent();
 * over.beginText();
 * over.setFontAndSize(bf, 18);
 * over.setTextMatrix(30, 30);
 * over.showText("total page " + totalPage);
 * over.endText();
 * ps.alterContents();
 * copy.addPage(page);
 * </pre>
 * @param iPage an imported page
 * @return the <CODE>PageStamp</CODE>
 */
 public PageStamp CreatePageStamp(PdfImportedPage iPage)
 {
     int pageNum = iPage.PageNumber;
     PdfReader reader = iPage.PdfReaderInstance.Reader;
     PdfDictionary pageN = reader.GetPageN(pageNum);
     return new PageStamp(reader, pageN, this);
 }
Beispiel #8
0
        /**
        * Add an imported page to our output
        * @param iPage an imported page
        * @throws IOException, BadPdfFormatException
        */
        public void AddPage(PdfImportedPage iPage)
        {
            int pageNum = SetFromIPage(iPage);

            PdfDictionary thePage = reader.GetPageN(pageNum);
            PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);
            reader.ReleasePage(pageNum);
            RefKey key = new RefKey(origRef);
            PdfIndirectReference pageRef;
            IndirectReferences iRef = (IndirectReferences)indirects[key] ;
            if (iRef != null && !iRef.Copied) {
                pageReferences.Add(iRef.Ref);
                iRef.SetCopied();
            }
            pageRef = CurrentPage;
            if (iRef == null) {
                iRef = new IndirectReferences(pageRef);
                indirects[key] = iRef;
            }
            iRef.SetCopied();
            PdfDictionary newPage = CopyDictionary(thePage);
            root.AddPage(newPage);
            ++currentPageNumber;
        }
 internal PdfImportedPage GetImportedPage(int pageNumber)
 {
     if (!reader.IsOpenedWithFullPermissions)
         throw new ArgumentException("PdfReader not opened with owner password");
     if (pageNumber < 1 || pageNumber > reader.NumberOfPages)
         throw new ArgumentException("Invalid page number: " + pageNumber);
     PdfImportedPage pageT = (PdfImportedPage)importedPages[pageNumber];
     if (pageT == null) {
         pageT = new PdfImportedPage(this, writer, pageNumber);
         importedPages[pageNumber] = pageT;
     }
     return pageT;
 }