001/* 002 * $Id: PdfTargetDictionary.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.collection; 045 046import com.itextpdf.text.pdf.PdfDictionary; 047import com.itextpdf.text.pdf.PdfName; 048import com.itextpdf.text.pdf.PdfNumber; 049import com.itextpdf.text.pdf.PdfObject; 050import com.itextpdf.text.pdf.PdfString; 051 052public class PdfTargetDictionary extends PdfDictionary { 053 054 /** 055 * Creates dictionary referring to a target document that is the parent of the current document. 056 * @param nested null if this is the actual target, another target if this is only an intermediate target. 057 */ 058 public PdfTargetDictionary(PdfTargetDictionary nested) { 059 super(); 060 put(PdfName.R, PdfName.P); 061 if (nested != null) 062 setAdditionalPath(nested); 063 } 064 065 /** 066 * Creates a dictionary referring to a target document. 067 * @param child if false, this refers to the parent document; if true, this refers to a child document, and you'll have to specify where to find the child using the other methods of this class 068 */ 069 public PdfTargetDictionary(boolean child) { 070 super(); 071 if (child) { 072 put(PdfName.R, PdfName.C); 073 } 074 else { 075 put(PdfName.R, PdfName.P); 076 } 077 } 078 079 /** 080 * If this dictionary refers to a child that is a document level attachment, 081 * you need to specify the name that was used to attach the document. 082 * @param target the name in the EmbeddedFiles name tree 083 */ 084 public void setEmbeddedFileName(String target) { 085 put(PdfName.N, new PdfString(target, null)); 086 } 087 088 /** 089 * If this dictionary refers to a child that is a file attachment added to a page, 090 * you need to specify the name of the page (or use setFileAttachmentPage to specify the page number). 091 * Once you have specified the page, you still need to specify the attachment using another method. 092 * @param name the named destination referring to the page with the file attachment. 093 */ 094 public void setFileAttachmentPagename(String name) { 095 put(PdfName.P, new PdfString(name, null)); 096 } 097 098 /** 099 * If this dictionary refers to a child that is a file attachment added to a page, 100 * you need to specify the page number (or use setFileAttachmentPagename to specify a named destination). 101 * Once you have specified the page, you still need to specify the attachment using another method. 102 * @param page the page number of the page with the file attachment. 103 */ 104 public void setFileAttachmentPage(int page) { 105 put(PdfName.P, new PdfNumber(page)); 106 } 107 108 /** 109 * If this dictionary refers to a child that is a file attachment added to a page, 110 * you need to specify the page with setFileAttachmentPage or setFileAttachmentPageName, 111 * and then specify the name of the attachment added to this page (or use setFileAttachmentIndex). 112 * @param name the name of the attachment 113 */ 114 public void setFileAttachmentName(String name) { 115 put(PdfName.A, new PdfString(name, PdfObject.TEXT_UNICODE)); 116 } 117 118 /** 119 * If this dictionary refers to a child that is a file attachment added to a page, 120 * you need to specify the page with setFileAttachmentPage or setFileAttachmentPageName, 121 * and then specify the index of the attachment added to this page (or use setFileAttachmentName). 122 * @param annotation the number of the attachment 123 */ 124 public void setFileAttachmentIndex(int annotation) { 125 put(PdfName.A, new PdfNumber(annotation)); 126 } 127 128 /** 129 * If this dictionary refers to an intermediate target, you can 130 * add the next target in the sequence. 131 * @param nested the next target in the sequence 132 */ 133 public void setAdditionalPath(PdfTargetDictionary nested) { 134 put(PdfName.T, nested); 135 } 136}