📄 pdf.java
字号:
* If the page is outside this range, throw an <code>ArrayIndexOutOfBoundsException</code> * @return the specified page * @throws ArrayIndexOutOfBoundsException if the page is out of range * @since 1.1 */ public PDFPage getPage(int pagenum) throws ArrayIndexOutOfBoundsException { return (PDFPage)PeeredObject.getPeer(pdf.getPage(pagenum)); } /** * Return the number of pages currently defined in the PDF document * @since 1.1 */ public int getNumberOfPages() { return pdf.getNumberOfPages(); } /** * Return the number of revisions made to the document. This will only be * useful for documents read in using a <code>PDFReader</code> - all * other PDFs (and many of these too) will return zero. See the * {@link PDFReader} class for more information on revisions. * @since 1.2.1 */ public int getNumberOfRevisions() { return pdf.getNumberOfRevisions(); } /** * Return the list of pages in the PDF document. This list can be manipulated * to reorder, delete or append pages as necessary using the standard * <tt>java.util.List</tt> methods. * @since 1.1.12 */ public List getPages() { /* * We need to override these methods because in version 1, moving pages * between documents also moved any form fields associated with those * pages. This is a bit crude - what happens if a field has annotations * on two pages, for instance - but that's what it did, so that's what * we do here too. */ return new ListPeer(pdf.getPages()) { public void add(int i, Object o) { super.add(i,o); List l = ((PDFPage)o).page.getAnnotations(); for (i=0;i<l.size();i++) { if (l.get(i) instanceof org.faceless.pdf2.WidgetAnnotation) { org.faceless.pdf2.WidgetAnnotation annot = (org.faceless.pdf2.WidgetAnnotation)l.get(i); pdf.getForm().getElements().put(annot.getField().getForm().getName(annot.getField()), annot.getField()); } } } public Object set(int i, Object o) { Object old = super.set(i,o); List l = ((PDFPage)o).page.getAnnotations(); for (i=0;i<l.size();i++) { if (l.get(i) instanceof org.faceless.pdf2.WidgetAnnotation) { org.faceless.pdf2.WidgetAnnotation annot = (org.faceless.pdf2.WidgetAnnotation)l.get(i); pdf.getForm().getElements().put(annot.getField().getForm().getName(annot.getField()), annot.getField()); } } return old; } }; } /** * <p> * Set the current Locale of the document. The locale language alters how the document * processes text internally - for example, setting the locale to * <code>Locale.ARABIC</code> sets the default justification to right-aligned. * </p><p> * The locale may be set many times throughout the document as required. However, * changing the locale in the middle of a paragraph should be avoided. * </p><p> * The default PDF locale is the value of <code>Locale.getDefault()</code> * </p> * @since 1.1 */ public void setLocale(Locale locale) { pdf.setLocale(locale); } /** * Return the PDF's locale, as set by {@link #setLocale} * @since 1.1 */ public Locale getLocale() { return pdf.getLocale(); } /** * Controls how the document is initially laid out in the PDF viewer. * * @param layout How to display the document if there is more than one page. * Can be {@link #SINGLEPAGE} (the default), {@link #ONECOLUMN}, * {@link #TWOCOLUMNLEFT} or {@link #TWOCOLUMNRIGHT} * @param bookmarks whether to show bookmarks when the document is first * opened. The default is <i>false</i>. */ public void setLayout(String layout, boolean bookmarks) { pdf.setLayout(layout, bookmarks ? "UseOutlines" : "UseNone"); } /** * <p> * Add some meta-information on the document, like the subject or title. * Although any key or value is valid (except <code>Producer</code>, * <code>CreationDate</code> and <code>ModDate</code>, which are set * by the library internally), the following fields are recognised * by Acrobat: * </p><table> * <tr><th align=left valign=top>Title</th><td>The document's title</td></tr> * <tr><th align=left valign=top>Author</th><td>The name of the person who created the document.</td></tr> * <tr><th align=left valign=top>Subject</th><td>The subject of the document.</td></tr> * <tr><th align=left valign=top>Keywords</th><td>Keywords associated with the document.</td></tr> * <tr><th align=left valign=top>Creator</th><td>If the document was converted to PDF from another format, the * name of the application that created the original document from which it was converted.</td></tr> * </table> * <p> * Although both key and value can use Unicode characters outside the * ASCII range, whether the viewer can display them correctly is another * matter. * </p> * <p> * Note that this meta-information can be set independently of any XML * meta information as set by {@link #setMetaData}. * </p> * @param key the field to set * @param val the value to set. */ public void setInfo(String key, String val) { pdf.setInfo(key,val); } /** * <p> * Return document meta information, as set by {@link #setInfo}. * </p> * <p> * Note that this meta-information can be used independently of any XML * meta information as returned by {@link #getMetaData}. * </p> * @param key the field to get * @return the value of the specified field, or <tt>null</tt> if the field is not set */ public String getInfo(String key) { return pdf.getInfo(key); } /** * <p> * Return document meta information, as set by {@link #setInfo}. This * method returns a map containing all the meta information. If no * meta information is available, returns an empty Map. * </p><p> * Note that this meta-information can be used independently of any XML * meta information as returned by {@link #getMetaData}. * </p> * @return a Map containing any meta information specified in the document. * The keys in the Map are Strings, and the values are always Strings or * Dates. * @since 1.1.12 */ public Map getInfo() { // We have to filter out anything that's not a String or a Date, // as that's all v1 functions were expecting back. // Map m = pdf.getInfo(); Map out = new HashMap(); for (Iterator i = m.entrySet().iterator();i.hasNext();) { Map.Entry entry = (Map.Entry)i.next(); if (entry.getValue() instanceof String || entry.getValue() instanceof Date) { out.put(entry.getKey(), entry.getValue()); } } return Collections.unmodifiableMap(out); } /** * <p> * Set the page to open Full Screen or not. This is off by default, and will * probably be ignored by any PDF viewer other than Adobe's own Acrobat. * </p> * @since 1.1.2 */ public void setOpenFullScreen(boolean fullscreen) { pdf.setViewerPreference("FullScreen", fullscreen); } /** * <p> * Set the XML Metadata associated with this document. This is a PDF * 1.4 feature, so it will only be used by Acrobat 5.0 or later - although * it <i>should</i> be ignored by earlier viewers. * </p><p> * The value is specified as a String, but as it's XML it will probably be * created as a <tt>java.io.Writer</tt>. Here's an example showing how * to use this with SAX and the <tt>org.apache.xml.serialize</tt> * classes. The lines marked in bold could apply to any method of * serializing the XML. * </p> * <pre> * void addMetaData(PDF pdf, InputSource source) * { * <i>// Create a java.io.Writer</i> * <b>StringWriter meta = new StringWriter();</b> * * <i>// Create a SAX XML serializer using the apache classes</i> * <i>// We must not include the XML Declaration in the output.</i> * OutputFormat outformat = new OutputFormat(); * outformat.setOmitXMLDeclaration(true); * Serializer serial = new XMLSerializer(out, outformat); * * <i>// Create the XML parser and parse the input source</i> * XMLReader parser = XMLReaderFactory.createXMLReader(); * parser.setContentHandler(serial.asContentHandler()); * parser.parse(inputsource); * * <b>pdf.setMetaData(meta.toString());</b> * } * </pre> * <p> * For more information on XML metadata in PDF documents, see * <a href="http://www.adobe.com/products/xmp">http://www.adobe.com/products/xmp</a> * </p> * @param xmldata the XML data to embed into the document. No validation is performed * on this input. * @since 1.1.12 */ public void setMetaData(String xmldata) { pdf.setMetaData(xmldata); } /** * <p> * Return any XML Metadata associated with the document. XML Metadata * is a PDF 1.4 (Acrobat 5.x) feature, so this method will return * <tt>null</tt> for all documents matching earlier specifications or * if no metadata is specified. * </p><p> * Here's an example of how to extract the MetaData into a DOM tree. * Lines in bold could apply to any parsing method. * </p> * <pre> * <b>InputSource source = new InputSource(pdf.getMetaData());</b> * DOMParser parser = new DOMParser(); * parser.parse(source); * Document doc = parser.getDocument(); * </pre> * <p> * For more information on XML metadata in PDF documents, see * <a href="http://www.adobe.com/products/xmp">http://www.adobe.com/products/xmp</a> * </p> * @since 1.1.12 * @returns a {@link java.io.Reader} containing the source of the XML */ public Reader getMetaData() throws IOException { return pdf.getMetaData(); } /** * <p> * Set some preferences as to how the document is displayed on screen. Along with the * <code>setLayout</code> function (which set some of the * more conventional viewer preferences), this function allow you to turn on or off some * of the more obscure features of the users PDF viewer application. By default, all * these options are set to <i>false</i>. Valid options are: * </p> * <table> * <tr><th align=left valign=top>HideToolbar</th><td>A flag specifying whether to hide the viewer application's tool bars when the document is active.</td></tr> * <tr><th align=left valign=top>HideMenubar</th><td>A flag specifying whether to hide the viewer application's menu bar when the document is active.</td></tr> * <tr><th align=left valign=top>HideWindowUI</th><td>A flag specifying whether to hide user interface elements in the document' window (such as scroll bars and navigation controls), leaving only the document's contents displayed.</td></tr> * <tr><th align=left valign=top>FitWindow</th><td>A flag specifying whether to resize the document's window to fit the size of the first displayed page. Note this resizes the window to fit the document, not the other way round.</td></tr> * <tr><th align=left valign=top>CenterWindow</th><td>A flag specifying whether to position the document's window in the center of the screen. Note this moves the whole viewer to the center of the screen, not the document to the center of the viewer.</td></tr> * </table> * <p>Viewers other than Adobes own Acrobat reader will probably ignore these options.</p> * @param key the option to set, from the list above * @param val whether to turn that option on or off */ public void setViewerPreference(String key, boolean val) { pdf.setViewerPreference(key, val); } /** * Return the value of the specified viewer preference, as set by {@link #setViewerPreference}. * @param key the option to query * @return <tt>true</tt> if the option is set to "on", or <tt>false</tt> if the option is set to "off" or not set. * @since 1.1.12 */ public boolean getViewerPreference(String key) { return pdf.getViewerPreference(key); } /** * <p> * Set the action to perform when the document is first opened. Use * this method to open the PDF at a specific page, or set the initial * zoom level. * </p><p> * To run an action when a specific <i>page</i> is opened, see the * method with the same name in the {@link PDFPage} object. * </p> * @param action The action to perform on opening. Since 1.1, set to * <code>null</code> to remove the action. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -