?? pdfdocument.java
字號:
/* * $Name: $ * $Id: PdfDocument.java,v 1.152 2002/11/19 08:33:36 blowagie Exp $ * * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie. * * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the License. * * The Original Code is 'iText, a free JAVA-PDF library'. * * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. * All Rights Reserved. * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. * * Contributor(s): all the names of the contributors are added in the source code * where applicable. * * Alternatively, the contents of this file may be used under the terms of the * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the * provisions of LGPL are applicable instead of those above. If you wish to * allow use of your version of this file only under the terms of the LGPL * License and not to allow others to use your version of this file under * the MPL, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the LGPL. * If you do not delete the provisions above, a recipient may use your version * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. * * This library is free software; you can redistribute it and/or modify it * under the terms of the MPL as stated above or under the terms of the GNU * Library General Public License as published by the Free Software Foundation; * either version 2 of the License, or any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more * details. * * If you didn't download this code from the following link, you should check if * you aren't using an obsolete version: * http://www.lowagie.com/iText/ */package com.lowagie.text.pdf;import com.lowagie.text.StringCompare;import com.lowagie.text.Anchor;import com.lowagie.text.Annotation;import com.lowagie.text.Cell;import com.lowagie.text.DocListener;import com.lowagie.text.Document;import com.lowagie.text.DocumentException;import com.lowagie.text.Element;import com.lowagie.text.Chunk;import com.lowagie.text.Graphic;import com.lowagie.text.HeaderFooter;import com.lowagie.text.Image;import com.lowagie.text.ImgWMF;import com.lowagie.text.List;import com.lowagie.text.ListItem;import com.lowagie.text.Meta;import com.lowagie.text.Header;import com.lowagie.text.Phrase;import com.lowagie.text.Paragraph;import com.lowagie.text.Rectangle;import com.lowagie.text.Section;import com.lowagie.text.Table;import com.lowagie.text.Watermark;import com.lowagie.text.ExceptionConverter;import java.awt.Color;import java.net.URL;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.TreeMap;import java.util.Iterator;import java.util.ListIterator;import java.io.IOException;/** * <CODE>PdfDocument</CODE> is the class that is used by <CODE>PdfWriter</CODE> * to translate a <CODE>Document</CODE> into a PDF with different pages. * <P> * A <CODE>PdfDocument</CODE> always listens to a <CODE>Document</CODE> * and adds the Pdf representation of every <CODE>Element</CODE> that is * added to the <CODE>Document</CODE>. * * @see com.lowagie.text.Document * @see com.lowagie.text.DocListener * @see PdfWriter */class PdfDocument extends Document implements DocListener { /** * <CODE>PdfInfo</CODE> is the PDF InfoDictionary. * <P> * A document's trailer may contain a reference to an Info dictionary that provides information * about the document. This optional dictionary may contain one or more keys, whose values * should be strings.<BR> * This object is described in the 'Portable Document Format Reference Manual version 1.3' * section 6.10 (page 120-121) */ public class PdfInfo extends PdfDictionary { // constructors /** * Construct a <CODE>PdfInfo</CODE>-object. */ PdfInfo() { super(); addProducer(); addCreationDate(); } /** * Constructs a <CODE>PdfInfo</CODE>-object. * * @param author name of the author of the document * @param title title of the document * @param subject subject of the document */ PdfInfo(String author, String title, String subject) { this(); addTitle(title); addSubject(subject); addAuthor(author); } /** * Adds the title of the document. * * @param title the title of the document */ void addTitle(String title) { put(PdfName.TITLE, new PdfString(title, PdfObject.TEXT_UNICODE)); } /** * Adds the subject to the document. * * @param subject the subject of the document */ void addSubject(String subject) { put(PdfName.SUBJECT, new PdfString(subject, PdfObject.TEXT_UNICODE)); } /** * Adds some keywords to the document. * * @param keywords the keywords of the document */ void addKeywords(String keywords) { put(PdfName.KEYWORDS, new PdfString(keywords, PdfObject.TEXT_UNICODE)); } /** * Adds the name of the author to the document. * * @param author the name of the author */ void addAuthor(String author) { put(PdfName.AUTHOR, new PdfString(author, PdfObject.TEXT_UNICODE)); } /** * Adds the name of the creator to the document. * * @param creator the name of the creator */ void addCreator(String creator) { put(PdfName.CREATOR, new PdfString(creator, PdfObject.TEXT_UNICODE)); } /** * Adds the name of the producer to the document. */ void addProducer() { // This line may only be changed by Bruno Lowagie or Paulo Soares put(PdfName.PRODUCER, new PdfString(getVersion())); // Do not edit the line above! } /** * Adds the date of creation to the document. */ void addCreationDate() { put(PdfName.CREATIONDATE, new PdfDate()); } void addkey(String key, String value) { if (key.equals("Producer") || key.equals("CreationDate")) return; put(new PdfName(key), new PdfString(value, PdfObject.TEXT_UNICODE)); } } /** * <CODE>PdfCatalog</CODE> is the PDF Catalog-object. * <P> * The Catalog is a dictionary that is the root node of the document. It contains a reference * to the tree of pages contained in the document, a reference to the tree of objects representing * the document's outline, a reference to the document's article threads, and the list of named * destinations. In addition, the Catalog indicates whether the document's outline or thumbnail * page images should be displayed automatically when the document is viewed and wether some location * other than the first page should be shown when the document is opened.<BR> * In this class however, only the reference to the tree of pages is implemented.<BR> * This object is described in the 'Portable Document Format Reference Manual version 1.3' * section 6.2 (page 67-71) */ class PdfCatalog extends PdfDictionary { // constructors /** * Constructs a <CODE>PdfCatalog</CODE>. * * @param pages an indirect reference to the root of the document's Pages tree. */ PdfCatalog(PdfIndirectReference pages) { super(CATALOG); put(PdfName.PAGES, pages); } /** * Constructs a <CODE>PdfCatalog</CODE>. * * @param pages an indirect reference to the root of the document's Pages tree. * @param outlines an indirect reference to the outline tree. */ PdfCatalog(PdfIndirectReference pages, PdfIndirectReference outlines) { super(CATALOG); put(PdfName.PAGES, pages); put(PdfName.PAGEMODE, PdfName.USEOUTLINES); put(PdfName.OUTLINES, outlines); } /** * Adds the names of the named destinations to the catalog. * @param localDestinations the local destinations */ void addNames(TreeMap localDestinations, ArrayList documentJavaScript, PdfWriter writer) { if (localDestinations.size() == 0 && documentJavaScript.size() == 0) return; try { PdfDictionary names = new PdfDictionary(); if (localDestinations.size() > 0) { PdfArray ar = new PdfArray(); for (Iterator i = localDestinations.keySet().iterator(); i.hasNext();) { String name = (String)i.next(); Object obj[] = (Object[])localDestinations.get(name); PdfIndirectReference ref = (PdfIndirectReference)obj[1]; ar.add(new PdfString(name)); ar.add(ref); } PdfDictionary dests = new PdfDictionary(); dests.put(PdfName.NAMES, ar); names.put(PdfName.DESTS, writer.addToBody(dests).getIndirectReference()); } if (documentJavaScript.size() > 0) { String s[] = new String[documentJavaScript.size()]; for (int k = 0; k < s.length; ++k) s[k] = Integer.toHexString(k); Arrays.sort(s, new StringCompare()); PdfArray ar = new PdfArray(); for (int k = 0; k < s.length; ++k) { ar.add(new PdfString(s[k])); ar.add((PdfIndirectReference)documentJavaScript.get(k)); } PdfDictionary js = new PdfDictionary(); js.put(PdfName.NAMES, ar); names.put(PdfName.JAVASCRIPT, writer.addToBody(js).getIndirectReference()); } put(PdfName.NAMES, writer.addToBody(names).getIndirectReference()); } catch (IOException e) { throw new ExceptionConverter(e); } } /** Sets the viewer preferences as the sum of several constants. * @param preferences the viewer preferences * @see PdfWriter#setViewerPreferences */ void setViewerPreferences(int preferences) { if ((preferences & PdfWriter.PageLayoutSinglePage) != 0) put(PdfName.PAGELAYOUT, PdfName.SINGLEPAGE); else if ((preferences & PdfWriter.PageLayoutOneColumn) != 0) put(PdfName.PAGELAYOUT, PdfName.ONECOLUMN); else if ((preferences & PdfWriter.PageLayoutTwoColumnLeft) != 0) put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNLEFT); else if ((preferences & PdfWriter.PageLayoutTwoColumnRight) != 0) put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNRIGHT); if ((preferences & PdfWriter.PageModeUseNone) != 0) put(PdfName.PAGEMODE, PdfName.USENONE); else if ((preferences & PdfWriter.PageModeUseOutlines) != 0) put(PdfName.PAGEMODE, PdfName.USEOUTLINES);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -