001/*
002 * $Id: PdfImportedPage.java 4784 2011-03-15 08:33:00Z blowagie $
003 *
004 * This file is part of the iText (R) project.
005 * Copyright (c) 1998-2011 1T3XT BVBA
006 * Authors: Bruno Lowagie, Paulo Soares, et al.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU Affero General Public License version 3
010 * as published by the Free Software Foundation with the addition of the
011 * following permission added to Section 15 as permitted in Section 7(a):
012 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY 1T3XT,
013 * 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
014 *
015 * This program is distributed in the hope that it will be useful, but
016 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
017 * or FITNESS FOR A PARTICULAR PURPOSE.
018 * See the GNU Affero General Public License for more details.
019 * You should have received a copy of the GNU Affero General Public License
020 * along with this program; if not, see http://www.gnu.org/licenses or write to
021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
022 * Boston, MA, 02110-1301 USA, or download the license from the following URL:
023 * http://itextpdf.com/terms-of-use/
024 *
025 * The interactive user interfaces in modified source and object code versions
026 * of this program must display Appropriate Legal Notices, as required under
027 * Section 5 of the GNU Affero General Public License.
028 *
029 * In accordance with Section 7(b) of the GNU Affero General Public License,
030 * a covered work must retain the producer line in every PDF that is created
031 * or manipulated using iText.
032 *
033 * You can be released from the requirements of the license by purchasing
034 * a commercial license. Buying such a license is mandatory as soon as you
035 * develop commercial activities involving the iText software without
036 * disclosing the source code of your own applications.
037 * These activities include: offering paid services to customers as an ASP,
038 * serving PDFs on the fly in a web application, shipping iText with a closed
039 * source product.
040 *
041 * For more information, please contact iText Software Corp. at this
042 * address: sales@itextpdf.com
043 */
044package com.itextpdf.text.pdf;
045import java.io.IOException;
046import com.itextpdf.text.error_messages.MessageLocalization;
047
048import com.itextpdf.text.DocumentException;
049import com.itextpdf.text.Image;
050
051/** Represents an imported page.
052 *
053 * @author Paulo Soares
054 */
055public class PdfImportedPage extends com.itextpdf.text.pdf.PdfTemplate {
056
057    PdfReaderInstance readerInstance;
058    int pageNumber;
059    /**
060     * True if the imported page has been copied to a writer.
061     * @since iText 5.0.4
062     */
063    protected boolean toCopy = true;
064    
065    PdfImportedPage(PdfReaderInstance readerInstance, PdfWriter writer, int pageNumber) {
066        this.readerInstance = readerInstance;
067        this.pageNumber = pageNumber;
068        this.writer = writer;
069        bBox = readerInstance.getReader().getPageSize(pageNumber);
070        setMatrix(1, 0, 0, 1, -bBox.getLeft(), -bBox.getBottom());
071        type = TYPE_IMPORTED;
072    }
073
074    /** Reads the content from this <CODE>PdfImportedPage</CODE>-object from a reader.
075     *
076     * @return self
077     *
078     */
079    public PdfImportedPage getFromReader() {
080      return this;
081    }
082
083    public int getPageNumber() {
084        return pageNumber;
085    }
086
087
088    /** Always throws an error. This operation is not allowed.
089     * @param image dummy
090     * @param a dummy
091     * @param b dummy
092     * @param c dummy
093     * @param d dummy
094     * @param e dummy
095     * @param f dummy
096     * @throws DocumentException  dummy */    
097    public void addImage(Image image, float a, float b, float c, float d, float e, float f) throws DocumentException {
098        throwError();
099    }
100    
101    /** Always throws an error. This operation is not allowed.
102     * @param template dummy
103     * @param a dummy
104     * @param b dummy
105     * @param c dummy
106     * @param d dummy
107     * @param e dummy
108     * @param f  dummy */    
109    public void addTemplate(PdfTemplate template, float a, float b, float c, float d, float e, float f) {
110        throwError();
111    }
112    
113    /** Always throws an error. This operation is not allowed.
114     * @return  dummy */    
115    public PdfContentByte getDuplicate() {
116        throwError();
117        return null;
118    }
119
120    /**
121     * Gets the stream representing this page.
122     *
123     * @param   compressionLevel        the compressionLevel
124     * @return the stream representing this page
125     * @since   2.1.3   (replacing the method without param compressionLevel)
126     */
127    PdfStream getFormXObject(int compressionLevel) throws IOException {
128         return readerInstance.getFormXObject(pageNumber, compressionLevel);
129    }
130    
131    public void setColorFill(PdfSpotColor sp, float tint) {
132        throwError();
133    }
134    
135    public void setColorStroke(PdfSpotColor sp, float tint) {
136        throwError();
137    }
138    
139    PdfObject getResources() {
140        return readerInstance.getResources(pageNumber);
141    }
142    
143    /** Always throws an error. This operation is not allowed.
144     * @param bf dummy
145     * @param size dummy */    
146    public void setFontAndSize(BaseFont bf, float size) {
147        throwError();
148    }
149    
150    /**
151     * Always throws an error. This operation is not allowed.
152     * @param group New value of property group.
153     * @since   2.1.6
154     */ 
155    public void setGroup(PdfTransparencyGroup group) {
156        throwError();
157        }
158
159        void throwError() {
160        throw new RuntimeException(MessageLocalization.getComposedMessage("content.can.not.be.added.to.a.pdfimportedpage"));
161    }
162    
163    PdfReaderInstance getPdfReaderInstance() {
164        return readerInstance;
165    }
166
167        /**
168         * Checks if the page has to be copied.
169         * @return true if the page has to be copied.
170         * @since iText 5.0.4
171         */
172        public boolean isToCopy() {
173                return toCopy;
174        }
175
176        /**
177         * Indicate that the resources of the imported page have been copied.
178         * @since iText 5.0.4
179         */
180        public void setCopied() {
181                toCopy = false;
182        }
183}