Hi all. I added an extension element that allows to set entries in the PDF document information map. The extenstion element is a root extension element and it has two attributes: document-info-key and document-info-value. A usage example is:
<fox:document-info document-info-key="CreationDate"
document-info-value="2003-03-19"/>
I hope someone has time to look on it and can commit it into the CVS. The
supplied patch is taken from the current CVS (fop-0_20_2-maintain branch).
--Stefan
PS: The following diff is the same as in the attachment:
Only in projekte/infotakt/vdp/xml-fop: build
diff -x .nbattrs -ru fop/xml-fop/src/codegen/extproperties.xml
projekte/infotakt/vdp/xml-fop/src/codegen/extproperties.xml
--- fop/xml-fop/src/codegen/extproperties.xml Wed Mar 19 08:46:33 2003
+++ projekte/infotakt/vdp/xml-fop/src/codegen/extproperties.xml Wed Mar 19
09:27:48 2003
@@ -19,5 +19,17 @@
<datatype>String</datatype>
<default></default>
</property>
+ <property>
+ <name>document-info-key</name>
+ <inherited>false</inherited>
+ <datatype>String</datatype>
+ <default/>
+ </property>
+ <property>
+ <name>document-info-value</name>
+ <inherited>false</inherited>
+ <datatype>String</datatype>
+ <default/>
+ </property>
</generic-property-list>
</property-list>
diff -x .nbattrs -ru fop/xml-fop/src/codegen/foproperties.xml
projekte/infotakt/vdp/xml-fop/src/codegen/foproperties.xml
--- fop/xml-fop/src/codegen/foproperties.xml Wed Mar 19 08:46:33 2003
+++ projekte/infotakt/vdp/xml-fop/src/codegen/foproperties.xml Wed Mar 19
08:54:36 2003
@@ -1650,6 +1650,20 @@
<datatype>String</datatype>
<default></default>
</property>
+ <!-- property of document-info extension element -->
+ <property>
+ <name>document-info-key</name>
+ <inherited>false</inherited>
+ <datatype>String</datatype>
+ <default/>
+ </property>
+ <!-- property of document-info extension element -->
+ <property>
+ <name>document-info-value</name>
+ <inherited>false</inherited>
+ <datatype>String</datatype>
+ <default/>
+ </property>
<property>
<name>show-destination</name>
<inherited>false</inherited>
Only in projekte/infotakt/vdp/xml-fop/src/org/apache/fop/extensions:
DocumentInfo.java
diff -x .nbattrs -ru
fop/xml-fop/src/org/apache/fop/extensions/ExtensionElementMapping.java
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/extensions/ExtensionElementMapping.java
---
fop/xml-fop/src/org/apache/fop/extensions/ExtensionElementMapping.java Wed Mar 19
08:46:33 2003
+++
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/extensions/ExtensionElementMapping.java
Wed Mar 19 09:01:15 2003
@@ -70,6 +70,7 @@
foObjs.put("label", Label.maker());
foObjs.put("continued-label", ContinuedLabel.maker());
foObjs.put("destination", Destination.maker());
+ foObjs.put("document-info", DocumentInfo.maker());
}
}
diff -x .nbattrs -ru fop/xml-fop/src/org/apache/fop/pdf/PDFDocument.java
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/pdf/PDFDocument.java
--- fop/xml-fop/src/org/apache/fop/pdf/PDFDocument.java Wed Mar 19 08:46:33
2003
+++
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/pdf/PDFDocument.java Wed Mar 19
09:08:25 2003
@@ -314,7 +314,11 @@
PDFInfo pdfInfo = new PDFInfo(++this.objectcount);
// set the default producer
pdfInfo.setProducer(org.apache.fop.apps.Version.getVersion());
- this.objects.add(pdfInfo);
+
+ // The document info is a trailer object. Extension elements have
+ // a chance to add document info before it is rendered.
+ addTrailerObject(pdfInfo);
+
return pdfInfo;
}
@@ -1436,4 +1440,12 @@
root.getDestinations().add(obj);
}
+ /**
+ * Sets an entry in the document information map.
+ * @param aKey (required).
+ * @param aValue (required).
+ */
+ public void setInfoEntry(String aKey, String aValue) {
+ info.setEntry(aKey, aValue);
+ }
}
diff -x .nbattrs -ru fop/xml-fop/src/org/apache/fop/pdf/PDFInfo.java
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/pdf/PDFInfo.java
--- fop/xml-fop/src/org/apache/fop/pdf/PDFInfo.java Wed Mar 19 08:46:33 2003
+++ projekte/infotakt/vdp/xml-fop/src/org/apache/fop/pdf/PDFInfo.java Wed
Mar 19 09:26:39 2003
@@ -52,6 +52,7 @@
// Java
import java.io.UnsupportedEncodingException;
+import java.util.*;
/**
* class representing an /Info object
@@ -59,10 +60,10 @@
public class PDFInfo extends PDFObject {
/**
- * the application producing the PDF
+ * Maps entry names (like "CreationDate" or "Producer" to string
values.
*/
- protected String producer;
-
+ private Map entries = new HashMap();
+
/**
* create an Info object
*
@@ -78,7 +79,7 @@
* @param producer the producer string
*/
public void setProducer(String producer) {
- this.producer = producer;
+ setEntry("Producer", producer);
}
/**
@@ -87,14 +88,26 @@
* @return the PDF
*/
public byte[] toPDF() {
- String p = this.number + " " + this.generation
- + " obj\n<< /Type /Info\n/Producer (" + this.producer
- + ") >>\nendobj\n";
+ StringBuffer b = new StringBuffer();
+ b.append(number).append(" ").append(generation).append(" obj\n<<");
+ b.append(" /Type /Info\n");
+ for (Iterator i = entries.entrySet().iterator(); i.hasNext(); ) {
+ Map.Entry me = (Map.Entry)i.next();
+ b.append(" /").append(me.getKey()).append("
(").append(me.getValue()).append(")\n");
+ }
+ b.append(">>\nendobj\n");
try {
- return p.getBytes(PDFDocument.ENCODING);
+ return b.toString().getBytes(PDFDocument.ENCODING);
} catch (UnsupportedEncodingException ue) {
- return p.getBytes();
+ return b.toString().getBytes();
}
+ }
+
+ /**
+ * Sets an entry in the information map.
+ */
+ public void setEntry(String aKey, String aValue) {
+ entries.put(aKey, aValue);
}
}
diff -x .nbattrs -ru
fop/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
--- fop/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java Wed Mar 19
08:46:33 2003
+++
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java Wed
Mar 19 09:20:27 2003
@@ -985,6 +985,9 @@
} else if (ext instanceof Destination) {
Destination d = (Destination)ext;
pdfDoc.addDestination(d.getDestinationName(),
d.getInternalDestination());
+ } else if (ext instanceof DocumentInfo) {
+ DocumentInfo info = (DocumentInfo)ext;
+ pdfDoc.setInfoEntry(info.getDocumentInfoKey(),
info.getDocumentInfoValue());
}
}
}Only in projekte/infotakt/vdp/xml-fop: build
diff -x .nbattrs -ru fop/xml-fop/src/codegen/extproperties.xml
projekte/infotakt/vdp/xml-fop/src/codegen/extproperties.xml
--- fop/xml-fop/src/codegen/extproperties.xml Wed Mar 19 08:46:33 2003
+++ projekte/infotakt/vdp/xml-fop/src/codegen/extproperties.xml Wed Mar 19 09:27:48
2003
@@ -19,5 +19,17 @@
<datatype>String</datatype>
<default></default>
</property>
+ <property>
+ <name>document-info-key</name>
+ <inherited>false</inherited>
+ <datatype>String</datatype>
+ <default/>
+ </property>
+ <property>
+ <name>document-info-value</name>
+ <inherited>false</inherited>
+ <datatype>String</datatype>
+ <default/>
+ </property>
</generic-property-list>
</property-list>
diff -x .nbattrs -ru fop/xml-fop/src/codegen/foproperties.xml
projekte/infotakt/vdp/xml-fop/src/codegen/foproperties.xml
--- fop/xml-fop/src/codegen/foproperties.xml Wed Mar 19 08:46:33 2003
+++ projekte/infotakt/vdp/xml-fop/src/codegen/foproperties.xml Wed Mar 19 08:54:36
2003
@@ -1650,6 +1650,20 @@
<datatype>String</datatype>
<default></default>
</property>
+ <!-- property of document-info extension element -->
+ <property>
+ <name>document-info-key</name>
+ <inherited>false</inherited>
+ <datatype>String</datatype>
+ <default/>
+ </property>
+ <!-- property of document-info extension element -->
+ <property>
+ <name>document-info-value</name>
+ <inherited>false</inherited>
+ <datatype>String</datatype>
+ <default/>
+ </property>
<property>
<name>show-destination</name>
<inherited>false</inherited>
Only in projekte/infotakt/vdp/xml-fop/src/org/apache/fop/extensions: DocumentInfo.java
diff -x .nbattrs -ru
fop/xml-fop/src/org/apache/fop/extensions/ExtensionElementMapping.java
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/extensions/ExtensionElementMapping.java
--- fop/xml-fop/src/org/apache/fop/extensions/ExtensionElementMapping.java Wed
Mar 19 08:46:33 2003
+++
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/extensions/ExtensionElementMapping.java
Wed Mar 19 09:01:15 2003
@@ -70,6 +70,7 @@
foObjs.put("label", Label.maker());
foObjs.put("continued-label", ContinuedLabel.maker());
foObjs.put("destination", Destination.maker());
+ foObjs.put("document-info", DocumentInfo.maker());
}
}
diff -x .nbattrs -ru fop/xml-fop/src/org/apache/fop/pdf/PDFDocument.java
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/pdf/PDFDocument.java
--- fop/xml-fop/src/org/apache/fop/pdf/PDFDocument.java Wed Mar 19 08:46:33 2003
+++ projekte/infotakt/vdp/xml-fop/src/org/apache/fop/pdf/PDFDocument.java Wed
Mar 19 09:08:25 2003
@@ -314,7 +314,11 @@
PDFInfo pdfInfo = new PDFInfo(++this.objectcount);
// set the default producer
pdfInfo.setProducer(org.apache.fop.apps.Version.getVersion());
- this.objects.add(pdfInfo);
+
+ // The document info is a trailer object. Extension elements have
+ // a chance to add document info before it is rendered.
+ addTrailerObject(pdfInfo);
+
return pdfInfo;
}
@@ -1436,4 +1440,12 @@
root.getDestinations().add(obj);
}
+ /**
+ * Sets an entry in the document information map.
+ * @param aKey (required).
+ * @param aValue (required).
+ */
+ public void setInfoEntry(String aKey, String aValue) {
+ info.setEntry(aKey, aValue);
+ }
}
diff -x .nbattrs -ru fop/xml-fop/src/org/apache/fop/pdf/PDFInfo.java
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/pdf/PDFInfo.java
--- fop/xml-fop/src/org/apache/fop/pdf/PDFInfo.java Wed Mar 19 08:46:33 2003
+++ projekte/infotakt/vdp/xml-fop/src/org/apache/fop/pdf/PDFInfo.java Wed Mar 19
09:26:39 2003
@@ -52,6 +52,7 @@
// Java
import java.io.UnsupportedEncodingException;
+import java.util.*;
/**
* class representing an /Info object
@@ -59,10 +60,10 @@
public class PDFInfo extends PDFObject {
/**
- * the application producing the PDF
+ * Maps entry names (like "CreationDate" or "Producer" to string values.
*/
- protected String producer;
-
+ private Map entries = new HashMap();
+
/**
* create an Info object
*
@@ -78,7 +79,7 @@
* @param producer the producer string
*/
public void setProducer(String producer) {
- this.producer = producer;
+ setEntry("Producer", producer);
}
/**
@@ -87,14 +88,26 @@
* @return the PDF
*/
public byte[] toPDF() {
- String p = this.number + " " + this.generation
- + " obj\n<< /Type /Info\n/Producer (" + this.producer
- + ") >>\nendobj\n";
+ StringBuffer b = new StringBuffer();
+ b.append(number).append(" ").append(generation).append(" obj\n<<");
+ b.append(" /Type /Info\n");
+ for (Iterator i = entries.entrySet().iterator(); i.hasNext(); ) {
+ Map.Entry me = (Map.Entry)i.next();
+ b.append(" /").append(me.getKey()).append("
(").append(me.getValue()).append(")\n");
+ }
+ b.append(">>\nendobj\n");
try {
- return p.getBytes(PDFDocument.ENCODING);
+ return b.toString().getBytes(PDFDocument.ENCODING);
} catch (UnsupportedEncodingException ue) {
- return p.getBytes();
+ return b.toString().getBytes();
}
+ }
+
+ /**
+ * Sets an entry in the information map.
+ */
+ public void setEntry(String aKey, String aValue) {
+ entries.put(aKey, aValue);
}
}
diff -x .nbattrs -ru fop/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
projekte/infotakt/vdp/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
--- fop/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java Wed Mar 19 08:46:33
2003
+++ projekte/infotakt/vdp/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
Wed Mar 19 09:20:27 2003
@@ -985,6 +985,9 @@
} else if (ext instanceof Destination) {
Destination d = (Destination)ext;
pdfDoc.addDestination(d.getDestinationName(),
d.getInternalDestination());
+ } else if (ext instanceof DocumentInfo) {
+ DocumentInfo info = (DocumentInfo)ext;
+ pdfDoc.setInfoEntry(info.getDocumentInfoKey(),
info.getDocumentInfoValue());
}
}
}
DocumentInfo.java
Description: Binary data
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
