📄 pdf.java
字号:
public void setOpenAction(PDFAction action) { pdf.setAction(org.faceless.pdf2.Event.OPEN, action==null ? null : action.action); } /** * Return the action that is performed when the document is first * opened. * @return the action that is performed when the document is first * opened, or <tt>null</tt> if no action is performed * @since 1.1.12 */ public PDFAction getOpenAction() { return (PDFAction)PeeredObject.getPeer(pdf.getAction(org.faceless.pdf2.Event.OPEN)); } /** * <p> * Create a "named" action, which can be referenced from outside the * current PDF, useful to (for example) open the generated PDF at a * specific position from an HTML link. Here's how to do this: * </p> * In the PDF, add the following code: * <pre> * pdf.setNamedAction("Myaction", PDFAction.goTo(somepage)) * </pre> * Then in your HTML document, add the following code: * <pre> * <a href="http://www.mycompany.com/mypdf.pdf#Myaction"> * </pre> * <p> * The action name is case sensitive. Adding a <tt>null</tt> action * causes the specified named action to be deleted. The action <i>must</i> * be a standard "goTo" action, jumping to a page in the document. * </p> * @param name The name to give this action. * @param action The action to perform on opening, or <tt>null</tt> to * delete the action * @since 1.1.5 */ public void setNamedAction(String name, PDFAction action) { if (action==null) { pdf.getNamedActions().remove(name); } else { pdf.getNamedActions().put(name, action.action); } } /** * Return a Map of all the "named actions" in the document, * as set by {@link #setNamedAction}. * @return A Map of all the named actions in the document. The key is * the {@link java.lang.String} which is the name of the action, the * value is the {@link PDFAction} to be performed. If no named actions * are specified, an empty map is returned. * @since 1.1.12 */ public Map getNamedActions() { // Return a copy, because in v1 changing the returned map has no effect. TreeMap map = new TreeMap(); for (Iterator i = pdf.getNamedActions().entrySet().iterator();i.hasNext();) { Map.Entry entry = (Map.Entry)i.next(); map.put(entry.getKey(), PeeredObject.getPeer(entry.getValue())); } return map; } /** * Return the list of Bookmarks at the top level of the document. The List * contains zero or more elements of type {@link PDFBookmark}. The List can * be altered using any of the standard {@link java.util.List} methods to * order the documents bookmarks in any way you see fit. By default, all * documents start with an empty List. * @see PDFBookmark * @return The List of bookmarks at the top level of the document */ public List getBookmarks() { return new ListPeer(pdf.getBookmarks()); } // --------------------------------------------------------------------------------- /** * <p> * Set the "security" password for the PDF document - the password * required to change the security settings of the document (the access * level and the open password). If you don't anticipate changing * the security settings at a later date, you can leave this blank. * </p><p> * If no encryption type has been set by calling {@link #setEncryptionAlgorithm}, * the algorithm is set to the standard 40 bit encryption. * </p> * @since 1.1 */ public void setSecurityPassword(String s) { org.faceless.pdf2.StandardEncryptionHandler handler = (org.faceless.pdf2.StandardEncryptionHandler)pdf.getEncryptionHandler(); if (s==null) s=""; if (handler==null) { handler = new org.faceless.pdf2.StandardEncryptionHandler(); pdf.setEncryptionHandler(handler); } handler.setOwnerPassword(s); } /** * <p> * Set the password required to open the PDF document. * (also called the "User" password). It can be left blank, * in which case the document can be opened by anyone. * </p><p> * If no encryption type has been set by calling {@link #setEncryptionAlgorithm}, * the algorithm is set to the standard 40 bit encryption. * </p> * @since 1.1 */ public void setPassword(String s) { org.faceless.pdf2.StandardEncryptionHandler handler = (org.faceless.pdf2.StandardEncryptionHandler)pdf.getEncryptionHandler(); if (s==null) s=""; if (handler==null) { handler = new org.faceless.pdf2.StandardEncryptionHandler(); pdf.setEncryptionHandler(handler); } handler.setUserPassword(s); } /** * <p> * Set the encryption algorithm used to encrypt the document. * Currently limited to either {@link #ENCRYPT_NONE} to disable * encryption, {@link #ENCRYPT_40BIT} to use the standard 40-bit * algorithm accepted by most modern versions of Acrobat, or * {@link #ENCRYPT_128BIT} to use the expanded 128-bit algorithm * introduced in PDF1.4 (Acrobat 5). * </p> * @since 1.1.12 */ public void setEncryptionAlgorithm(int type) { if (type==ENCRYPT_NONE) { pdf.setEncryptionHandler(null); } else { org.faceless.pdf2.StandardEncryptionHandler handler = (org.faceless.pdf2.StandardEncryptionHandler)pdf.getEncryptionHandler(); if (handler==null) { handler = new org.faceless.pdf2.StandardEncryptionHandler(); pdf.setEncryptionHandler(handler); } if (type==ENCRYPT_128BIT) { handler.setAcrobat5Level(handler.PRINT_HIGHRES, handler.EXTRACT_ALL, handler.CHANGE_ALL); } else { handler.setAcrobat3Level(true, true, true, true); } } } /** * <p> * Set the level of access available to the user. The user can be granted any * of the {@link #ACCESS_PRINT}, {@link #ACCESS_EDIT}, {@link #ACCESS_COPY} * or {@link #ACCESS_ANNOTATE} rights. Additionally, if 128 bit encryption * is used the {@link #ACCESS_FORMS}, {@link #ACCESS_ASSEMBLE}, {@link #ACCESS_EXTRACT} * and {@link #ACCESS_HQPRINT} options can be used. * </p><p> * Please remember it is <i>up to the PDF viewer software</i> to enforce this, and * that there are plenty of applications available on the 'net to allow full access * to a PDF document. Consequently this setting should be considered a <b>recommendation * only</b>. * </p><p> * Setting this value involves encrypting the document, even if no password has been * set. If no encryption type has been set by calling {@link #setEncryptionAlgorithm}, * the algorithm is set to the standard 40 bit encryption. * </p><p> * The default is that the user has full access to the document. * </p> * @param level a logical-OR of any of the above flags * @since 1.1 */ public void setAccessLevel(int level) { org.faceless.pdf2.StandardEncryptionHandler handler = (org.faceless.pdf2.StandardEncryptionHandler)pdf.getEncryptionHandler(); if (handler==null) { handler = new org.faceless.pdf2.StandardEncryptionHandler(); pdf.setEncryptionHandler(handler); } if (handler.getVersion()==2) { boolean print = (level&ACCESS_PRINT)!=0; boolean annotate = (level&ACCESS_ANNOTATE)!=0; boolean edit = (level&ACCESS_EDIT)!=0; boolean copy = (level&ACCESS_COPY)!=0; boolean forms = (level&ACCESS_FORMS)!=0; boolean extract = (level&ACCESS_EXTRACT)!=0; boolean assemble = (level&ACCESS_ASSEMBLE)!=0; boolean hqprint = (level&ACCESS_HQPRINT)!=0; int newchange=handler.CHANGE_NONE, newprint=handler.PRINT_NONE, newextract=handler.EXTRACT_NONE; if (print && hqprint) { newprint=handler.PRINT_HIGHRES; } else if (print) { newprint=handler.PRINT_LOWRES; } else { newprint=handler.PRINT_NONE; } if (extract && copy) { newprint=handler.EXTRACT_ALL; } else if (extract) { newprint=handler.EXTRACT_ACCESSIBILITY; } else { newprint=handler.EXTRACT_NONE; } if (assemble && annotate && edit) { newchange = handler.CHANGE_ALL; } else if (assemble && annotate) { newchange = handler.CHANGE_ANNOTATIONS; } else if (forms) { newchange = handler.CHANGE_FORMS; } else if (assemble) { newchange = handler.CHANGE_LAYOUT; } else { newchange = handler.CHANGE_NONE; } handler.setAcrobat5Level(newprint, newextract, newchange); } else { boolean print = (level&ACCESS_PRINT)!=0; boolean annotate = (level&ACCESS_ANNOTATE)!=0; boolean edit = (level&ACCESS_EDIT)!=0; boolean copy = (level&ACCESS_COPY)!=0; handler.setAcrobat3Level(print, annotate, copy, edit); } } //-------------------------------------------------------------------- /** * Return the Interactive {@link Form} or "AcroForm" object which is part * of each PDF document. * <b>Note that using interactive forms requires the "Extended Edition" * of the library</b> - although the classes are supplied with the package an "Extended * Edition" license must be purchased to activate this functionality. * @since 1.1.13 */ public Form getForm() { return (Form)PeeredObject.getPeer(pdf.getForm()); } /** * Set the document-wide JavaScript. This JavaScript is executed when * the document is first loaded - this is normally used to define * functions and the like, in the same way as JavaScript defined in the * <HEAD> of an HTML document. * @param javascript the JavaScript to use for the entire document * @since 1.1.23 * @see #getJavaScript * @see PDFAction#formJavaScript */ public void setJavaScript(String javascript) { pdf.setJavaScript(javascript); } /** * Return the document-wide JavaScript, as set by {@link #setJavaScript}, * or <code>null</code> if no JavaScript is defined for this document. * @since 1.1.23 * @see #setJavaScript * @see PDFAction#formJavaScript */ public String getJavaScript() { return pdf.getJavaScript(); } /** * <p> * This method renders the completed PDF to an OutputStream. The * stream is left open on completion. A document may be rendered * more than once. Rendering the document merges all the revisions * of a document, so after rendering the {@link #getNumberOfRevisions} * method will always return zero. * </p> * @param out the output stream to write the PDF to. * @throws IOException if the rendering process could not be completed */ public synchronized void render(OutputStream out) throws IOException { pdf.render(out); } /** * Set the license key for the library. When the library is purchased, * the Big Faceless Organization supplies a key which removes the "DEMO" * stamp on each of the documents * @param key the license key */ public static void setLicenseKey(String key) { org.faceless.pdf2.PDF.setLicenseKey(key); } /** * Import the contents of the specified {@link FDF} into the PDF document. * Although the FDF file may contain a wide variety of information, the * only part of it actually used by this method are the form values, which * are used to set the corresponding form fields in the PDF. If a field * doesn't exist, a warning is printed and the field is ignored * @since 1.2.1 */ public void importFDF(FDF fdf) { pdf.importFDF((org.faceless.pdf2.FDF)fdf.fdf); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -