⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdfwriter.java

📁 处理PDF
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	/** A viewer preference */	public static final int DisplayDocTitle = 1 << 17;	/** A viewer preference */	public static final int NonFullScreenPageModeUseNone = 1 << 18;	/** A viewer preference */	public static final int NonFullScreenPageModeUseOutlines = 1 << 19;	/** A viewer preference */	public static final int NonFullScreenPageModeUseThumbs = 1 << 20;	/** A viewer preference */	public static final int NonFullScreenPageModeUseOC = 1 << 21;	/** A viewer preference */	public static final int DirectionL2R = 1 << 22;	/** A viewer preference */	public static final int DirectionR2L = 1 << 23;	/** A viewer preference */	public static final int PrintScalingNone = 1 << 24;	    /** @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#setViewerPreferences(int) */    public void setViewerPreferences(int preferences) {        pdf.setViewerPreferences(preferences);    }    /** @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#addViewerPreference(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject) */    public void addViewerPreference(PdfName key, PdfObject value) {    	pdf.addViewerPreference(key, value);    } //	[C4] Page labels        /**     * Use this method to add page labels     * @param pageLabels the page labels     */    public void setPageLabels(PdfPageLabels pageLabels) {        pdf.setPageLabels(pageLabels);    }     //	[C5] named objects: named destinations, javascript, embedded files          /**      * Use this method to add a JavaScript action at the document level.      * When the document opens, all this JavaScript runs.      * @param js The JavaScript action      */     public void addJavaScript(PdfAction js) {         pdf.addJavaScript(js);     }          /**      * Use this method to add a JavaScript action at the document level.      * When the document opens, all this JavaScript runs.      * @param code the JavaScript code      * @param unicode select JavaScript unicode. Note that the internal      * Acrobat JavaScript engine does not support unicode,      * so this may or may not work for you      */     public void addJavaScript(String code, boolean unicode) {         addJavaScript(PdfAction.javaScript(code, this, unicode));     }          /**      * Use this method to adds a JavaScript action at the document level.      * When the document opens, all this JavaScript runs.      * @param code the JavaScript code      */     public void addJavaScript(String code) {         addJavaScript(code, false);     }     /**      * Use this method to add a JavaScript action at the document level.      * When the document opens, all this JavaScript runs.      * @param name	The name of the JS Action in the name tree      * @param js The JavaScript action      */     public void addJavaScript(String name, PdfAction js) {         pdf.addJavaScript(name, js);     }          /**      * Use this method to add a JavaScript action at the document level.      * When the document opens, all this JavaScript runs.      * @param name	The name of the JS Action in the name tree      * @param code the JavaScript code      * @param unicode select JavaScript unicode. Note that the internal      * Acrobat JavaScript engine does not support unicode,      * so this may or may not work for you      */     public void addJavaScript(String name, String code, boolean unicode) {         addJavaScript(name, PdfAction.javaScript(code, this, unicode));     }          /**      * Use this method to adds a JavaScript action at the document level.      * When the document opens, all this JavaScript runs.      * @param name	The name of the JS Action in the name tree      * @param code the JavaScript code      */     public void addJavaScript(String name, String code) {         addJavaScript(name, code, false);     }          /**      * Use this method to add a file attachment at the document level.      * @param description the file description      * @param fileStore an array with the file. If it's <CODE>null</CODE>      * the file will be read from the disk      * @param file the path to the file. It will only be used if      * <CODE>fileStore</CODE> is not <CODE>null</CODE>      * @param fileDisplay the actual file name stored in the pdf      * @throws IOException on error      */         public void addFileAttachment(String description, byte fileStore[], String file, String fileDisplay) throws IOException {         addFileAttachment(description, PdfFileSpecification.fileEmbedded(this, file, fileDisplay, fileStore));     }     /**      * Use this method to add a file attachment at the document level.      * @param description the file description      * @param fs the file specification      */         public void addFileAttachment(String description, PdfFileSpecification fs) throws IOException {         pdf.addFileAttachment(description, fs);     }          /**      * Use this method to add a file attachment at the document level.      * @param fs the file specification      */         public void addFileAttachment(PdfFileSpecification fs) throws IOException {         addFileAttachment(null, fs);     }     // [C6] Actions (open and additional)     /** action value */     public static final PdfName DOCUMENT_CLOSE = PdfName.WC;     /** action value */     public static final PdfName WILL_SAVE = PdfName.WS;     /** action value */     public static final PdfName DID_SAVE = PdfName.DS;     /** action value */     public static final PdfName WILL_PRINT = PdfName.WP;     /** action value */     public static final PdfName DID_PRINT = PdfName.DP;         /** @see com.lowagie.text.pdf.interfaces.PdfDocumentActions#setOpenAction(java.lang.String) */    public void setOpenAction(String name) {         pdf.setOpenAction(name);     }    /** @see com.lowagie.text.pdf.interfaces.PdfDocumentActions#setOpenAction(com.lowagie.text.pdf.PdfAction) */    public void setOpenAction(PdfAction action) {         pdf.setOpenAction(action);     }         /** @see com.lowagie.text.pdf.interfaces.PdfDocumentActions#setAdditionalAction(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfAction) */    public void setAdditionalAction(PdfName actionType, PdfAction action) throws DocumentException {         if (!(actionType.equals(DOCUMENT_CLOSE) ||         actionType.equals(WILL_SAVE) ||         actionType.equals(DID_SAVE) ||         actionType.equals(WILL_PRINT) ||         actionType.equals(DID_PRINT))) {             throw new DocumentException("Invalid additional action type: " + actionType.toString());         }         pdf.addAdditionalAction(actionType, action);     }    // 	[C7] portable collections    /**     * Use this method to add the Collection dictionary.     * @param collection a dictionary of type PdfCollection     */    public void setCollection(PdfCollection collection) {    	setAtLeastPdfVersion(VERSION_1_7);    	pdf.setCollection(collection);    }    //	[C8] AcroForm	/** signature value */	public static final int SIGNATURE_EXISTS = 1;	/** signature value */	public static final int SIGNATURE_APPEND_ONLY = 2;	    /** @see com.lowagie.text.pdf.interfaces.PdfAnnotations#getAcroForm() */    public PdfAcroForm getAcroForm() {        return pdf.getAcroForm();    }        /** @see com.lowagie.text.pdf.interfaces.PdfAnnotations#addAnnotation(com.lowagie.text.pdf.PdfAnnotation) */    public void addAnnotation(PdfAnnotation annot) {        pdf.addAnnotation(annot);    }        void addAnnotation(PdfAnnotation annot, int page) {        addAnnotation(annot);    }        /** @see com.lowagie.text.pdf.interfaces.PdfAnnotations#addCalculationOrder(com.lowagie.text.pdf.PdfFormField) */    public void addCalculationOrder(PdfFormField annot) {        pdf.addCalculationOrder(annot);    }        /** @see com.lowagie.text.pdf.interfaces.PdfAnnotations#setSigFlags(int) */    public void setSigFlags(int f) {        pdf.setSigFlags(f);    }//	[C9] Metadata        /** XMP Metadata for the document. */    protected byte[] xmpMetadata = null;    	/**	 * Use this method to set the XMP Metadata.	 * @param xmpMetadata The xmpMetadata to set.	 */	public void setXmpMetadata(byte[] xmpMetadata) {		this.xmpMetadata = xmpMetadata;	}		/**	 * Use this method to set the XMP Metadata for each page.	 * @param xmpMetadata The xmpMetadata to set.	 */	public void setPageXmpMetadata(byte[] xmpMetadata) {		pdf.setXmpMetadata(xmpMetadata);	}		/**	 * Use this method to creates XMP Metadata based	 * on the metadata in the PdfDocument.	 */	public void createXmpMetadata() {		setXmpMetadata(createXmpMetadataBytes());	}	    /**	 * @return an XmpMetadata byte array	 */	private byte[] createXmpMetadataBytes() {		ByteArrayOutputStream baos = new ByteArrayOutputStream();	    try {	    	XmpWriter xmp = new XmpWriter(baos, pdf.getInfo(), pdfxConformance.getPDFXConformance());	        xmp.close();	    }	    catch(IOException ioe) {	        ioe.printStackTrace();	    }	    return baos.toByteArray();	}    //	[C10] PDFX Conformance    /** A PDF/X level. */    public static final int PDFXNONE = 0;    /** A PDF/X level. */    public static final int PDFX1A2001 = 1;    /** A PDF/X level. */    public static final int PDFX32002 = 2;        /** PDFA-1A level. */    public static final int PDFA1A = 3;    /** PDFA-1B level. */    public static final int PDFA1B = 4;        /** Stores the PDF/X level. */    private PdfXConformanceImp pdfxConformance = new PdfXConformanceImp();        /** @see com.lowagie.text.pdf.interfaces.PdfXConformance#setPDFXConformance(int) */    public void setPDFXConformance(int pdfx) {        if (pdfxConformance.getPDFXConformance() == pdfx)            return;        if (pdf.isOpen())            throw new PdfXConformanceException("PDFX conformance can only be set before opening the document.");        if (crypto != null)            throw new PdfXConformanceException("A PDFX conforming document cannot be encrypted.");        if (pdfx == PDFA1A || pdfx == PDFA1B)            setPdfVersion(VERSION_1_4);        else if (pdfx != PDFXNONE)            setPdfVersion(VERSION_1_3);        pdfxConformance.setPDFXConformance(pdfx);    }     /** @see com.lowagie.text.pdf.interfaces.PdfXConformance#getPDFXConformance() */    public int getPDFXConformance() {        return pdfxConformance.getPDFXConformance();    }        /** @see com.lowagie.text.pdf.interfaces.PdfXConformance#isPdfX() */    public boolean isPdfX() {    	return pdfxConformance.isPdfX();    }     //	[C11] Output intents        /**     * Use this method to set the values of the output intent dictionary.     * Null values are allowed to suppress any key.     * @param outputConditionIdentifier a value     * @param outputCondition a value     * @param registryName a value     * @param info a value     * @param destOutputProfile a value     * @throws IOException on error     */        public void setOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, byte destOutputProfile[]) throws IOException {        getExtraCatalog();        PdfDictionary out = new PdfDictionary(PdfName.OUTPUTINTENT);        if (outputCondition != null)            out.put(PdfName.OUTPUTCONDITION, new PdfString(outputCondition, PdfObject.TEXT_UNICODE));        if (outputConditionIdentifier != null)            out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString(outputConditionIdentifier, PdfObject.TEXT_UNICODE));        if (registryName != null)            out.put(PdfName.REGISTRYNAME, new PdfString(registryName, PdfObject.TEXT_UNICODE));        if (info != null)            out.put(PdfName.INFO, new PdfString(info, PdfObject.TEXT_UNICODE));        if (destOutputProfile != null) {            PdfStream stream = new PdfStream(destOutputProfile);            stream.flateCompress(compressionLevel);            out.put(PdfName.DESTOUTPUTPROFILE, addToBody(stream).getIndirectReference());        }        out.put(PdfName.S, PdfName.GTS_PDFX);        extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out));    }        /**     * Use this method to copy the output intent dictionary     * from another document to this one.     * @param reader the other document     * @param checkExistence <CODE>true</CODE> to just check for the existence of a valid output intent     * dictionary, <CODE>false</CODE> to insert the dictionary if it exists     * @throws IOException on error     * @return <CODE>true</CODE> if the output intent dictionary exists, <CODE>false</CODE>     * otherwise     */        public boolean setOutputIntents(PdfReader reader, boolean checkExistence) throws IOException {        PdfDictionary catalog = reader.getCatalog();        PdfArray outs = (PdfArray)PdfReader.getPdfObject(catalog.get(PdfName.OUTPUTINTENTS));        if (outs == null)            return false;        ArrayList arr = outs.getArrayList();        if (arr.isEmpty())            return false;        PdfDictiona

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -