import org.apache.fop.render.Renderer;
import org.apache.fop.render.RendererFactory;
import org.apache.fop.render.XMLHandlerRegistry;
+import org.apache.fop.render.pdf.PDFRenderer;
/**
* This is the user agent for FOP.
/** Our default resolver if none is set */
private URIResolver foURIResolver = new FOURIResolver();
- private PDFEncryptionParams pdfEncryptionParams;
private float targetResolution = DEFAULT_TARGET_RESOLUTION;
private Map rendererOptions = new java.util.HashMap();
private File outputFile = null;
/**
* Returns the parameters for PDF encryption.
* @return the PDF encryption parameters, null if not applicable
+ * @deprecated Use (PDFEncryptionParams)getRendererOptions().get("encryption-params")
+ * instead.
*/
public PDFEncryptionParams getPDFEncryptionParams() {
- return pdfEncryptionParams;
+ return (PDFEncryptionParams)getRendererOptions().get(PDFRenderer.ENCRYPTION_PARAMS);
}
/**
* Sets the parameters for PDF encryption.
* @param pdfEncryptionParams the PDF encryption parameters, null to
* disable PDF encryption
+ * @deprecated Use getRendererOptions().put("encryption-params",
+ * new PDFEncryptionParams(..)) instead or set every parameter separately:
+ * getRendererOptions().put("noprint", Boolean.TRUE).
*/
public void setPDFEncryptionParams(PDFEncryptionParams pdfEncryptionParams) {
- this.pdfEncryptionParams = pdfEncryptionParams;
+ getRendererOptions().put(PDFRenderer.ENCRYPTION_PARAMS, pdfEncryptionParams);
}
import org.apache.fop.pdf.PDFEncryptionParams;
import org.apache.fop.render.awt.AWTRenderer;
import org.apache.fop.render.Renderer;
+import org.apache.fop.render.pdf.PDFRenderer;
import org.apache.fop.render.xml.XMLRenderer;
import org.apache.fop.util.CommandLineLogger;
}
private PDFEncryptionParams getPDFEncryptionParams() throws FOPException {
- if (foUserAgent.getPDFEncryptionParams() == null) {
+ PDFEncryptionParams params = (PDFEncryptionParams)foUserAgent.getRendererOptions().get(
+ PDFRenderer.ENCRYPTION_PARAMS);
+ if (params == null) {
if (!PDFEncryptionManager.checkAvailableAlgorithms()) {
throw new FOPException("PDF encryption requested but it is not available."
+ " Please make sure MD5 and RC4 algorithms are available.");
}
- foUserAgent.setPDFEncryptionParams(new PDFEncryptionParams());
+ params = new PDFEncryptionParams();
+ foUserAgent.getRendererOptions().put(PDFRenderer.ENCRYPTION_PARAMS, params);
}
- return foUserAgent.getPDFEncryptionParams();
+ return params;
}
private int parsePDFOwnerPassword(String[] args, int i) throws FOPException {
import org.apache.fop.pdf.PDFColor;
import org.apache.fop.pdf.PDFDocument;
import org.apache.fop.pdf.PDFEncryptionManager;
+import org.apache.fop.pdf.PDFEncryptionParams;
import org.apache.fop.pdf.PDFFilterList;
import org.apache.fop.pdf.PDFInfo;
import org.apache.fop.pdf.PDFLink;
*/
public static final String MIME_TYPE = MimeConstants.MIME_PDF;
+ /** PDF encryption parameter: all parameters as object, datatype: PDFEncryptionParams */
+ public static final String ENCRYPTION_PARAMS = "encryption-params";
+ /** PDF encryption parameter: user password, datatype: String */
+ public static final String USER_PASSWORD = "user-password";
+ /** PDF encryption parameter: owner password, datatype: String */
+ public static final String OWNER_PASSWORD = "owner-password";
+ /** PDF encryption parameter: Forbids printing, datatype: Boolean or "true"/"false" */
+ public static final String NO_PRINT = "noprint";
+ /** PDF encryption parameter: Forbids copying content, datatype: Boolean or "true"/"false" */
+ public static final String NO_COPY_CONTENT = "nocopy";
+ /** PDF encryption parameter: Forbids editing content, datatype: Boolean or "true"/"false" */
+ public static final String NO_EDIT_CONTENT = "noedit";
+ /** PDF encryption parameter: Forbids annotations, datatype: Boolean or "true"/"false" */
+ public static final String NO_ANNOTATIONS = "noannotations";
+
/** Controls whether comments are written to the PDF stream. */
protected static final boolean WRITE_COMMENTS = true;
*/
protected PDFPage currentPage;
+ /** the (optional) encryption parameters */
+ protected PDFEncryptionParams encryptionParams;
+
/** The current Transform */
protected AffineTransform currentBasicTransform;
}
}
+ private boolean booleanValueOf(Object obj) {
+ if (obj instanceof Boolean) {
+ return ((Boolean)obj).booleanValue();
+ } else if (obj instanceof String) {
+ return Boolean.valueOf((String)obj).booleanValue();
+ } else {
+ throw new IllegalArgumentException("Boolean or \"true\" or \"false\" expected.");
+ }
+ }
+
/**
* @see org.apache.fop.render.Renderer#setUserAgent(FOUserAgent)
*/
public void setUserAgent(FOUserAgent agent) {
super.setUserAgent(agent);
+ PDFEncryptionParams params
+ = (PDFEncryptionParams)agent.getRendererOptions().get(ENCRYPTION_PARAMS);
+ if (params != null) {
+ this.encryptionParams = params; //overwrite if available
+ }
+ String pwd;
+ pwd = (String)agent.getRendererOptions().get(USER_PASSWORD);
+ if (pwd != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setUserPassword(pwd);
+ }
+ pwd = (String)agent.getRendererOptions().get(OWNER_PASSWORD);
+ if (pwd != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setOwnerPassword(pwd);
+ }
+ Object setting;
+ setting = agent.getRendererOptions().get(NO_PRINT);
+ if (setting != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setAllowPrint(!booleanValueOf(setting));
+ }
+ setting = agent.getRendererOptions().get(NO_COPY_CONTENT);
+ if (setting != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setAllowCopyContent(!booleanValueOf(setting));
+ }
+ setting = agent.getRendererOptions().get(NO_EDIT_CONTENT);
+ if (setting != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setAllowEditContent(!booleanValueOf(setting));
+ }
+ setting = agent.getRendererOptions().get(NO_ANNOTATIONS);
+ if (setting != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setAllowEditAnnotations(!booleanValueOf(setting));
+ }
}
/**
this.pdfDoc.outputHeader(stream);
//Setup encryption if necessary
- PDFEncryptionManager.setupPDFEncryption(
- userAgent.getPDFEncryptionParams(), this.pdfDoc);
+ PDFEncryptionManager.setupPDFEncryption(encryptionParams, this.pdfDoc);
}
/**