To all that may concern, Here it is... PDF encryption. Unfortunately, I seem to be lame when it comes to cvs. When I generate the unified using WinCVS's "cvs diff -uN", it does not include the file PDFEncryption.java. I have included it as a second attachment. It belongs in src/org/apache/fop/pdf.
Send me all of your nice and nasty comments and I'll make any adjustments necessary. Enjoy, Pat Lankswert
? xml-fop/build/fop.jar
? xml-fop/build/src
? xml-fop/build/classes/hyph
? xml-fop/build/classes/org
? xml-fop/build/classes/conf/config.dtd
? xml-fop/build/classes/conf/config.xml
? xml-fop/build/classes/conf/userconfig.xml
? xml-fop/src/org/apache/fop/pdf/.nbattrs
? xml-fop/src/org/apache/fop/pdf/PDFEncryption.java
? xml-fop/src/org/apache/fop/render/pdf/.nbattrs
Index: xml-fop/fop.bat
===================================================================
RCS file: /home/cvspublic/xml-fop/fop.bat,v
retrieving revision 1.4.2.8
diff -u -r1.4.2.8 fop.bat
--- xml-fop/fop.bat 10 Dec 2002 22:28:02 -0000 1.4.2.8
+++ xml-fop/fop.bat 14 Feb 2003 03:28:18 -0000
@@ -10,4 +10,4 @@
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jimi-1.0.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_core.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_codec.jar
-java -cp %LOCALCLASSPATH% org.apache.fop.apps.Fop %1 %2 %3 %4 %5 %6 %7 %8
\ No newline at end of file
+java -cp %LOCALCLASSPATH% org.apache.fop.apps.Fop %*
\ No newline at end of file
Index: xml-fop/src/org/apache/fop/apps/CommandLineOptions.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/apps/CommandLineOptions.java,v
retrieving revision 1.14.2.8
diff -u -r1.14.2.8 CommandLineOptions.java
--- xml-fop/src/org/apache/fop/apps/CommandLineOptions.java 19 Nov 2002 00:47:01
-0000 1.14.2.8
+++ xml-fop/src/org/apache/fop/apps/CommandLineOptions.java 14 Feb 2003 03:28:34
+-0000
@@ -177,6 +177,52 @@
outfile = new File(args[i + 1]);
i++;
}
+ } else if (args[i].equals("-o")) {
+ if (inputmode == PDF_OUTPUT) {
+ if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) {
+ rendererOptions.put("ownerPassword", "");
+ } else {
+ rendererOptions.put("ownerPassword", args[i + 1]);
+ i++;
+ }
+ } else {
+ throw new FOPException("Owner password can only be set for PDF
+output");
+ }
+ } else if (args[i].equals("-u")) {
+ if (inputmode == PDF_OUTPUT) {
+ if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) {
+ rendererOptions.put("userPassword", "");
+ } else {
+ rendererOptions.put("userPassword", args[i + 1]);
+ i++;
+ }
+ } else {
+ throw new FOPException("User password can only be set for PDF
+output");
+ }
+ } else if (args[i].equals("-noprint")) {
+ if (inputmode == PDF_OUTPUT) {
+ rendererOptions.put("allowPrint", "FALSE");
+ } else {
+ throw new FOPException("NoPrint can only be set for PDF output");
+ }
+ } else if (args[i].equals("-nocopy")) {
+ if (inputmode == PDF_OUTPUT) {
+ rendererOptions.put("allowCopyContent", "FALSE");
+ } else {
+ throw new FOPException("NoCopyContent can only be set for PDF
+output");
+ }
+ } else if (args[i].equals("-noedit")) {
+ if (inputmode == PDF_OUTPUT) {
+ rendererOptions.put("allowEditContent", "FALSE");
+ } else {
+ throw new FOPException("NoEditContent can only be set for PDF
+output");
+ }
+ } else if (args[i].equals("-noannotations")) {
+ if (inputmode == PDF_OUTPUT) {
+ rendererOptions.put("allowEditAnnotations", "FALSE");
+ } else {
+ throw new FOPException("NoAnnotations can only be set for PDF
+output");
+ }
} else if (args[i].equals("-mif")) {
setOutputMode(MIF_OUTPUT);
if ((i + 1 == args.length)
@@ -507,6 +553,12 @@
+ " [OUTPUT] \n"
+ " outfile input will be rendered as pdf
file into outfile \n"
+ " -pdf outfile input will be rendered as pdf
file (outfile req'd) \n"
+ + " -o [password] pdf file will be encrypted with
+option owner password\n"
+ + " -u [password] pdf file will be encrypted with
+option user password\n"
+ + " -noprint pdf file will be encrypted
+without printing permission\n"
+ + " -nocopy pdf file will be encrypted
+without copy content permission\n"
+ + " -noedit pdf file will be encrypted
+without edit content permission\n"
+ + " -noannotations pdf file will be encrypted
+without edit annotation permission\n"
+ " -awt input will be displayed on
screen \n"
+ " -mif outfile input will be rendered as mif
file (outfile req'd)\n"
+ " -pcl outfile input will be rendered as pcl
file (outfile req'd) \n"
Index: xml-fop/src/org/apache/fop/pdf/PDFDocument.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v
retrieving revision 1.30.2.6
diff -u -r1.30.2.6 PDFDocument.java
--- xml-fop/src/org/apache/fop/pdf/PDFDocument.java 7 Feb 2003 00:10:46 -0000
1.30.2.6
+++ xml-fop/src/org/apache/fop/pdf/PDFDocument.java 14 Feb 2003 03:28:58 -0000
@@ -118,6 +118,11 @@
protected IDReferences idReferences;
/**
+ * the documents encryption, if exists
+ */
+ protected PDFEncryption encryption;
+
+ /**
* the colorspace (0=RGB, 1=CMYK)
*/
// protected int colorspace = 0;
@@ -196,6 +201,30 @@
}
/**
+ * set the encryption object
+ *
+ * @param ownerPassword The owner password for the pdf file
+ * @param userPassword The user password for the pdf file
+ * @param allowPrint Indicates whether the printing permission will be set
+ * @param allowCopyContent Indicates whether the content extracting permission
+will be set
+ * @param allowEditContent Indicates whether the edit content permission will be
+set
+ * @param allowEditAnnotations Indicates whether the edit annotations permission
+will be set
+ */
+ public void setEncryption(String ownerPassword, String userPassword,
+ boolean allowPrint, boolean allowCopyContent,
+ boolean allowEditContent, boolean allowEditAnnotations)
+{
+ this.encryption = new PDFEncryption(++this.objectcount);
+ this.encryption.setOwnerPassword(ownerPassword);
+ this.encryption.setUserPassword(userPassword);
+ this.encryption.setAllowPrint(allowPrint);
+ this.encryption.setAllowCopyContent(allowCopyContent);
+ this.encryption.setAllowEditContent(allowEditContent);
+ this.encryption.setAllowEditAnnotation(allowEditAnnotations);
+ this.encryption.init();
+ addTrailerObject(this.encryption);
+ }
+
+ /**
* Make a /Catalog (Root) object. This object is written in
* the trailer.
*/
@@ -1128,6 +1157,9 @@
*/
PDFStream obj = new PDFStream(++this.objectcount);
obj.addDefaultFilters();
+ if (this.encryption != null) {
+ this.encryption.filter(obj);
+ }
this.objects.add(obj);
return obj;
@@ -1275,6 +1307,15 @@
by the table's length */
this.position += outputXref(stream);
+ // Determine existance of encryption dictionary
+ String encryptEntry = "";
+
+ if (this.encryption != null) {
+ encryptEntry =
+ "/Encrypt " + this.encryption.number + " " + this.encryption.generation +
+" R\n"+
+
+"/ID[<"+this.encryption.getFileID(1)+"><"+this.encryption.getFileID(2)+">]\n";
+ }
+
/* construct the trailer */
String pdf =
"trailer\n" +
@@ -1282,6 +1323,7 @@
"/Size " + (this.objectcount + 1) + "\n" +
"/Root " + this.root.number + " " + this.root.generation + " R\n" +
"/Info " + this.info.number + " " + this.info.generation + " R\n" +
+ encryptEntry +
">>\n" +
"startxref\n" +
this.xref + "\n" +
Index: xml-fop/src/org/apache/fop/pdf/PDFXObject.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/pdf/PDFXObject.java,v
retrieving revision 1.14.2.4
diff -u -r1.14.2.4 PDFXObject.java
--- xml-fop/src/org/apache/fop/pdf/PDFXObject.java 18 Nov 2002 14:37:46 -0000
1.14.2.4
+++ xml-fop/src/org/apache/fop/pdf/PDFXObject.java 14 Feb 2003 03:29:03 -0000
@@ -65,6 +65,9 @@
pdfICCStream = pdfDoc.makePDFICCStream();
pdfICCStream.setColorSpace(jpegimage.getColorSpace());
pdfICCStream.addDefaultFilters();
+ if (pdfDoc.encryption != null) {
+ pdfDoc.encryption.filter(pdfICCStream);
+ }
}
}
} catch (Exception e) {
@@ -142,6 +145,9 @@
imgStream.setData(imgData);
//imgStream.addFilter(new FlateFilter());
imgStream.addDefaultFilters();
+ if (pdfDoc.encryption != null) {
+
+imgStream.addFilter(pdfDoc.encryption.makeFilter(this.number,this.generation));
+ }
String dictEntries = imgStream.applyFilters();
@@ -198,7 +204,9 @@
} else {
imgStream.addDefaultFilters();
}
-
+ if (pdfDoc.encryption != null) {
+
+imgStream.addFilter(pdfDoc.encryption.makeFilter(this.number,this.generation));
+ }
String dictEntries = imgStream.applyFilters();
Index: xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
retrieving revision 1.91.2.11
diff -u -r1.91.2.11 PDFRenderer.java
--- xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java 7 Feb 2003 00:10:46
-0000 1.91.2.11
+++ xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java 14 Feb 2003 03:29:13
+-0000
@@ -138,6 +138,51 @@
*/
public void setOptions(java.util.Map options) {
this.options = options;
+
+ // Process encryption options, if any exist
+ boolean encrypt = false;
+ String oPassword = "";
+ String uPassword = "";
+ boolean allowPrint = true;
+ boolean allowCopyContent = true;
+ boolean allowEditContent = true;
+ boolean allowEditAnnotations = true;
+ String option;
+
+ option = (String) options.get("ownerPassword");
+ if (option != null) {
+ encrypt = true;
+ oPassword = option;
+ }
+ option = (String) options.get("userPassword");
+ if (option != null) {
+ encrypt = true;
+ uPassword = option;
+ }
+ option = (String) options.get("allowPrint");
+ if (option != null) {
+ encrypt = true;
+ allowPrint = option.equals("TRUE");
+ }
+ option = (String) options.get("allowCopyContent");
+ if (option != null) {
+ encrypt = true;
+ allowCopyContent = option.equals("TRUE");
+ }
+ option = (String) options.get("allowEditContent");
+ if (option != null) {
+ encrypt = true;
+ allowEditContent = option.equals("TRUE");
+ }
+ option = (String) options.get("allowEditAnnotations");
+ if (option != null) {
+ encrypt = true;
+ allowEditAnnotations = option.equals("TRUE");
+ }
+ if (encrypt) {
+ this.pdfDoc.setEncryption(oPassword,uPassword,allowPrint,allowCopyContent,
+ allowEditContent, allowEditAnnotations);
+ }
}
/**
Index: xml-fop/fop.bat
===================================================================
RCS file: /home/cvspublic/xml-fop/fop.bat,v
retrieving revision 1.4.2.8
diff -u -r1.4.2.8 fop.bat
--- xml-fop/fop.bat 10 Dec 2002 22:28:02 -0000 1.4.2.8
+++ xml-fop/fop.bat 14 Feb 2003 03:28:18 -0000
@@ -10,4 +10,4 @@
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jimi-1.0.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_core.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_codec.jar
-java -cp %LOCALCLASSPATH% org.apache.fop.apps.Fop %1 %2 %3 %4 %5 %6 %7 %8
\ No newline at end of file
+java -cp %LOCALCLASSPATH% org.apache.fop.apps.Fop %*
\ No newline at end of file
Index: xml-fop/src/org/apache/fop/apps/CommandLineOptions.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/apps/CommandLineOptions.java,v
retrieving revision 1.14.2.8
diff -u -r1.14.2.8 CommandLineOptions.java
--- xml-fop/src/org/apache/fop/apps/CommandLineOptions.java 19 Nov 2002 00:47:01
-0000 1.14.2.8
+++ xml-fop/src/org/apache/fop/apps/CommandLineOptions.java 14 Feb 2003 03:28:34
+-0000
@@ -177,6 +177,52 @@
outfile = new File(args[i + 1]);
i++;
}
+ } else if (args[i].equals("-o")) {
+ if (inputmode == PDF_OUTPUT) {
+ if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) {
+ rendererOptions.put("ownerPassword", "");
+ } else {
+ rendererOptions.put("ownerPassword", args[i + 1]);
+ i++;
+ }
+ } else {
+ throw new FOPException("Owner password can only be set for PDF
+output");
+ }
+ } else if (args[i].equals("-u")) {
+ if (inputmode == PDF_OUTPUT) {
+ if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) {
+ rendererOptions.put("userPassword", "");
+ } else {
+ rendererOptions.put("userPassword", args[i + 1]);
+ i++;
+ }
+ } else {
+ throw new FOPException("User password can only be set for PDF
+output");
+ }
+ } else if (args[i].equals("-noprint")) {
+ if (inputmode == PDF_OUTPUT) {
+ rendererOptions.put("allowPrint", "FALSE");
+ } else {
+ throw new FOPException("NoPrint can only be set for PDF output");
+ }
+ } else if (args[i].equals("-nocopy")) {
+ if (inputmode == PDF_OUTPUT) {
+ rendererOptions.put("allowCopyContent", "FALSE");
+ } else {
+ throw new FOPException("NoCopyContent can only be set for PDF
+output");
+ }
+ } else if (args[i].equals("-noedit")) {
+ if (inputmode == PDF_OUTPUT) {
+ rendererOptions.put("allowEditContent", "FALSE");
+ } else {
+ throw new FOPException("NoEditContent can only be set for PDF
+output");
+ }
+ } else if (args[i].equals("-noannotations")) {
+ if (inputmode == PDF_OUTPUT) {
+ rendererOptions.put("allowEditAnnotations", "FALSE");
+ } else {
+ throw new FOPException("NoAnnotations can only be set for PDF
+output");
+ }
} else if (args[i].equals("-mif")) {
setOutputMode(MIF_OUTPUT);
if ((i + 1 == args.length)
@@ -507,6 +553,12 @@
+ " [OUTPUT] \n"
+ " outfile input will be rendered as pdf
file into outfile \n"
+ " -pdf outfile input will be rendered as pdf
file (outfile req'd) \n"
+ + " -o [password] pdf file will be encrypted with
+option owner password\n"
+ + " -u [password] pdf file will be encrypted with
+option user password\n"
+ + " -noprint pdf file will be encrypted
+without printing permission\n"
+ + " -nocopy pdf file will be encrypted
+without copy content permission\n"
+ + " -noedit pdf file will be encrypted
+without edit content permission\n"
+ + " -noannotations pdf file will be encrypted
+without edit annotation permission\n"
+ " -awt input will be displayed on
screen \n"
+ " -mif outfile input will be rendered as mif
file (outfile req'd)\n"
+ " -pcl outfile input will be rendered as pcl
file (outfile req'd) \n"
Index: xml-fop/src/org/apache/fop/pdf/PDFDocument.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v
retrieving revision 1.30.2.6
diff -u -r1.30.2.6 PDFDocument.java
--- xml-fop/src/org/apache/fop/pdf/PDFDocument.java 7 Feb 2003 00:10:46 -0000
1.30.2.6
+++ xml-fop/src/org/apache/fop/pdf/PDFDocument.java 14 Feb 2003 03:28:58 -0000
@@ -118,6 +118,11 @@
protected IDReferences idReferences;
/**
+ * the documents encryption, if exists
+ */
+ protected PDFEncryption encryption;
+
+ /**
* the colorspace (0=RGB, 1=CMYK)
*/
// protected int colorspace = 0;
@@ -196,6 +201,30 @@
}
/**
+ * set the encryption object
+ *
+ * @param ownerPassword The owner password for the pdf file
+ * @param userPassword The user password for the pdf file
+ * @param allowPrint Indicates whether the printing permission will be set
+ * @param allowCopyContent Indicates whether the content extracting permission
+will be set
+ * @param allowEditContent Indicates whether the edit content permission will be
+set
+ * @param allowEditAnnotations Indicates whether the edit annotations permission
+will be set
+ */
+ public void setEncryption(String ownerPassword, String userPassword,
+ boolean allowPrint, boolean allowCopyContent,
+ boolean allowEditContent, boolean allowEditAnnotations)
+{
+ this.encryption = new PDFEncryption(++this.objectcount);
+ this.encryption.setOwnerPassword(ownerPassword);
+ this.encryption.setUserPassword(userPassword);
+ this.encryption.setAllowPrint(allowPrint);
+ this.encryption.setAllowCopyContent(allowCopyContent);
+ this.encryption.setAllowEditContent(allowEditContent);
+ this.encryption.setAllowEditAnnotation(allowEditAnnotations);
+ this.encryption.init();
+ addTrailerObject(this.encryption);
+ }
+
+ /**
* Make a /Catalog (Root) object. This object is written in
* the trailer.
*/
@@ -1128,6 +1157,9 @@
*/
PDFStream obj = new PDFStream(++this.objectcount);
obj.addDefaultFilters();
+ if (this.encryption != null) {
+ this.encryption.filter(obj);
+ }
this.objects.add(obj);
return obj;
@@ -1275,6 +1307,15 @@
by the table's length */
this.position += outputXref(stream);
+ // Determine existance of encryption dictionary
+ String encryptEntry = "";
+
+ if (this.encryption != null) {
+ encryptEntry =
+ "/Encrypt " + this.encryption.number + " " + this.encryption.generation +
+" R\n"+
+
+"/ID[<"+this.encryption.getFileID(1)+"><"+this.encryption.getFileID(2)+">]\n";
+ }
+
/* construct the trailer */
String pdf =
"trailer\n" +
@@ -1282,6 +1323,7 @@
"/Size " + (this.objectcount + 1) + "\n" +
"/Root " + this.root.number + " " + this.root.generation + " R\n" +
"/Info " + this.info.number + " " + this.info.generation + " R\n" +
+ encryptEntry +
">>\n" +
"startxref\n" +
this.xref + "\n" +
Index: xml-fop/src/org/apache/fop/pdf/PDFXObject.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/pdf/PDFXObject.java,v
retrieving revision 1.14.2.4
diff -u -r1.14.2.4 PDFXObject.java
--- xml-fop/src/org/apache/fop/pdf/PDFXObject.java 18 Nov 2002 14:37:46 -0000
1.14.2.4
+++ xml-fop/src/org/apache/fop/pdf/PDFXObject.java 14 Feb 2003 03:29:03 -0000
@@ -65,6 +65,9 @@
pdfICCStream = pdfDoc.makePDFICCStream();
pdfICCStream.setColorSpace(jpegimage.getColorSpace());
pdfICCStream.addDefaultFilters();
+ if (pdfDoc.encryption != null) {
+ pdfDoc.encryption.filter(pdfICCStream);
+ }
}
}
} catch (Exception e) {
@@ -142,6 +145,9 @@
imgStream.setData(imgData);
//imgStream.addFilter(new FlateFilter());
imgStream.addDefaultFilters();
+ if (pdfDoc.encryption != null) {
+
+imgStream.addFilter(pdfDoc.encryption.makeFilter(this.number,this.generation));
+ }
String dictEntries = imgStream.applyFilters();
@@ -198,7 +204,9 @@
} else {
imgStream.addDefaultFilters();
}
-
+ if (pdfDoc.encryption != null) {
+
+imgStream.addFilter(pdfDoc.encryption.makeFilter(this.number,this.generation));
+ }
String dictEntries = imgStream.applyFilters();
Index: xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
retrieving revision 1.91.2.11
diff -u -r1.91.2.11 PDFRenderer.java
--- xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java 7 Feb 2003 00:10:46
-0000 1.91.2.11
+++ xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java 14 Feb 2003 03:29:13
+-0000
@@ -138,6 +138,51 @@
*/
public void setOptions(java.util.Map options) {
this.options = options;
+
+ // Process encryption options, if any exist
+ boolean encrypt = false;
+ String oPassword = "";
+ String uPassword = "";
+ boolean allowPrint = true;
+ boolean allowCopyContent = true;
+ boolean allowEditContent = true;
+ boolean allowEditAnnotations = true;
+ String option;
+
+ option = (String) options.get("ownerPassword");
+ if (option != null) {
+ encrypt = true;
+ oPassword = option;
+ }
+ option = (String) options.get("userPassword");
+ if (option != null) {
+ encrypt = true;
+ uPassword = option;
+ }
+ option = (String) options.get("allowPrint");
+ if (option != null) {
+ encrypt = true;
+ allowPrint = option.equals("TRUE");
+ }
+ option = (String) options.get("allowCopyContent");
+ if (option != null) {
+ encrypt = true;
+ allowCopyContent = option.equals("TRUE");
+ }
+ option = (String) options.get("allowEditContent");
+ if (option != null) {
+ encrypt = true;
+ allowEditContent = option.equals("TRUE");
+ }
+ option = (String) options.get("allowEditAnnotations");
+ if (option != null) {
+ encrypt = true;
+ allowEditAnnotations = option.equals("TRUE");
+ }
+ if (encrypt) {
+ this.pdfDoc.setEncryption(oPassword,uPassword,allowPrint,allowCopyContent,
+ allowEditContent, allowEditAnnotations);
+ }
}
/**
PDFEncryption.java
Description: java/
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
