Index: test/java/org/apache/fop/UtilityCodeTestSuite.java
===================================================================
--- test/java/org/apache/fop/UtilityCodeTestSuite.java	(revision 1136491)
+++ test/java/org/apache/fop/UtilityCodeTestSuite.java	(working copy)
@@ -24,6 +24,7 @@
 
 import org.apache.fop.events.BasicEventTestCase;
 import org.apache.fop.pdf.PDFObjectTestCase;
+import org.apache.fop.pdf.VersionTestCase;
 import org.apache.fop.traits.BorderPropsTestCase;
 import org.apache.fop.util.BitmapImageUtilTestCase;
 import org.apache.fop.util.ColorUtilTestCase;
@@ -46,6 +47,7 @@
         //$JUnit-BEGIN$
         suite.addTest(new TestSuite(PDFNumberTestCase.class));
         suite.addTest(new TestSuite(PDFObjectTestCase.class));
+        suite.addTest(new TestSuite(VersionTestCase.class));
         suite.addTest(new TestSuite(ColorUtilTestCase.class));
         suite.addTest(new TestSuite(BorderPropsTestCase.class));
         suite.addTest(new TestSuite(ElementListUtilsTestCase.class));
Index: test/java/org/apache/fop/pdf/VersionTestCase.java
===================================================================
--- test/java/org/apache/fop/pdf/VersionTestCase.java	(revision 0)
+++ test/java/org/apache/fop/pdf/VersionTestCase.java	(revision 0)
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import junit.framework.TestCase;
+
+/**
+ * This is a test case for ({@link Version}.
+ */
+public class VersionTestCase extends TestCase {
+    /**
+     * Test the <code>getValue()</code> method. This should return {@link Version} given a
+     * {@link String}.
+     */
+    public void testGetValue() {
+        // Ensure versions prior to 1.4 all fail! FOP produces valid PDF 1.4+
+        failGetValue("1.0");
+        failGetValue("1.1");
+        failGetValue("1.2");
+        failGetValue("1.3");
+        // Ensure subsequent versions are properly returned.
+        assertEquals(Version.V1_4, Version.getValue("1.4"));
+        assertEquals(Version.V1_5, Version.getValue("1.5"));
+        assertEquals(Version.V1_6, Version.getValue("1.6"));
+        assertEquals(Version.V1_7, Version.getValue("1.7"));
+        // Random test to ensure exceptions are thrown
+        failGetValue("blah blah");
+    }
+
+    private void failGetValue(String str) {
+        try {
+            assertEquals(Version.V1_4, Version.getValue(str));
+            fail("PDFVersion.getValue(String) should throw an exception here");
+        } catch (IllegalArgumentException e) {
+            // PASS
+        }
+    }
+
+    /**
+     * Tests that the <code>toString()</method> method returns the PDF verison string of the proper
+     * format.
+     */
+    public void testToString() {
+        // Test all the normal values
+        assertTrue("1.4".equals(Version.V1_4.toString()));
+        assertTrue("1.5".equals(Version.V1_5.toString()));
+        assertTrue("1.6".equals(Version.V1_6.toString()));
+        assertTrue("1.7".equals(Version.V1_7.toString()));
+    }
+
+    /**
+     * Tests that the <code>compareTo()</code> contract is obeyed.
+     */
+    public void testCompareTo() {
+        // Ensure that the implicit comparison contract is satisfied
+        assertEquals(-1, Version.V1_4.compareTo(Version.V1_5));
+        assertEquals(-1, Version.V1_5.compareTo(Version.V1_6));
+        assertEquals(-1, Version.V1_6.compareTo(Version.V1_7));
+
+        assertEquals(0, Version.V1_4.compareTo(Version.V1_4));
+        assertEquals(0, Version.V1_5.compareTo(Version.V1_5));
+        assertEquals(0, Version.V1_6.compareTo(Version.V1_6));
+        assertEquals(0, Version.V1_7.compareTo(Version.V1_7));
+
+        assertEquals(1, Version.V1_5.compareTo(Version.V1_4));
+        assertEquals(1, Version.V1_6.compareTo(Version.V1_5));
+        assertEquals(1, Version.V1_7.compareTo(Version.V1_6));
+
+    }
+}
Index: src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java	(revision 1136491)
+++ src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java	(working copy)
@@ -33,13 +33,6 @@
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
-import org.apache.xmlgraphics.image.loader.util.ImageUtil;
-import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
-import org.apache.xmlgraphics.xmp.Metadata;
-import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
-import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
-
 import org.apache.fop.accessibility.Accessibility;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.extensions.xmp.XMPMetadata;
@@ -64,7 +57,13 @@
 import org.apache.fop.pdf.PDFReference;
 import org.apache.fop.pdf.PDFText;
 import org.apache.fop.pdf.PDFXMode;
+import org.apache.fop.pdf.Version;
 import org.apache.fop.render.pdf.extensions.PDFEmbeddedFileExtensionAttachment;
+import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
+import org.apache.xmlgraphics.xmp.Metadata;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
 
 /**
  * Utility class which enables all sorts of features that are not directly connected to the
@@ -102,7 +101,9 @@
     /** Optional URI to an output profile to be used. */
     protected String outputProfileURI;
 
+    protected Version pdfVersion = Version.V1_4;
 
+
     PDFRenderingUtil(FOUserAgent userAgent) {
         this.userAgent = userAgent;
         initialize();
@@ -376,7 +377,7 @@
             throw new IllegalStateException("PDFDocument already set up");
         }
         this.pdfDoc = new PDFDocument(
-                userAgent.getProducer() != null ? userAgent.getProducer() : "");
+                userAgent.getProducer() != null ? userAgent.getProducer() : "", pdfVersion);
         updateInfo();
         updatePDFProfiles();
         pdfDoc.setFilterMap(filterMap);
@@ -482,4 +483,13 @@
         nameArray.add(new PDFReference(fileSpec));
     }
 
+    /**
+     * Sets the PDF version of the output document. This will set the document version by converting
+     * it to {@link Version}. See {@link Version} for the format of <code>version</code>
+     * @param version the PDF version.
+     */
+    public void setPDFVersion(String version) throws IllegalArgumentException {
+        pdfVersion = Version.getValue(version);
+    }
+
 }
Index: src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java	(revision 1136491)
+++ src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java	(working copy)
@@ -24,7 +24,6 @@
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
-
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.pdf.PDFAMode;
@@ -130,6 +129,20 @@
             pdfUtil.setDisableSRGBColorSpace(
                     disableColorSpaceConfig.getValueAsBoolean(false));
         }
+
+        Configuration pdfVersion = cfg.getChild(PDFConfigurationConstants.PDF_VERSION, false);
+        if (pdfVersion != null) {
+            String ver = pdfVersion.getValue(null);
+            if (ver != null && !ver.isEmpty()) {
+                try {
+                    pdfUtil.setPDFVersion(ver);
+                } catch (IllegalArgumentException e) {
+                    throw new FOPException(e.getMessage());
+                }
+            } else {
+                throw new FOPException("The PDF version has not been set.");
+            }
+        }
     }
 
     /**
Index: src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java	(revision 1136491)
+++ src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java	(working copy)
@@ -44,6 +44,8 @@
     String PDF_X_MODE = "pdf-x-mode";
     /** Rendering Options key for the ICC profile for the output intent. */
     String KEY_OUTPUT_PROFILE = "output-profile";
+    /** PDF version parameter: specify the version of the PDF document created, datatype: String */
+    String PDF_VERSION = "version";
     /**
      * Rendering Options key for disabling the sRGB color space (only possible if no PDF/A or
      * PDF/X profile is active).
Index: src/java/org/apache/fop/pdf/Version.java
===================================================================
--- src/java/org/apache/fop/pdf/Version.java	(revision 0)
+++ src/java/org/apache/fop/pdf/Version.java	(revision 0)
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+
+/**
+ * An enumeration of the PDF Versions 1.4 to 1.7. The order in which each entry is entered into
+ * the enum preserves the implicit compareTo() contract such that V1_4 < V1_5.
+ */
+public enum Version {
+    /** PDF v1.4 */
+    V1_4("1.4"),
+    /** PDF v1.5 */
+    V1_5("1.5"),
+    /** PDF v1.6 */
+    V1_6("1.6"),
+    /** PDF v1.7 */
+    V1_7("1.7");
+    private String version;
+
+    private Version(String version) {
+        this.version = version;
+    }
+
+    /**
+     * Given the PDF version as a String, returns the corresponding enumerated type. The String
+     * should be in the format "1.0" for PDF v1.0.
+     *
+     * @param version String of version number
+     * @return PDFVersion
+     */
+    public static Version getValue(String version) {
+        for (Version pdfVersion : Version.values()) {
+            if (pdfVersion.toString().equals(version)) {
+                return pdfVersion;
+            }
+        }
+        throw new IllegalArgumentException("Invalid PDF version given: " + version);
+    }
+
+    @Override
+    public String toString() {
+        return version;
+    }
+}
\ No newline at end of file
Index: src/java/org/apache/fop/pdf/PDFProfile.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFProfile.java	(revision 1136491)
+++ src/java/org/apache/fop/pdf/PDFProfile.java	(working copy)
@@ -180,11 +180,11 @@
     public void verifyPDFVersion() {
         final String err = "PDF version must be 1.4 for {0}";
         if (getPDFAMode().isPDFA1LevelB()
-                && getDocument().getPDFVersion() != PDFDocument.PDF_VERSION_1_4) {
+                && !Version.V1_4.equals(getDocument().getPDFVersion())) {
             throw new PDFConformanceException(format(err, getPDFAMode()));
         }
         if (getPDFXMode() == PDFXMode.PDFX_3_2003
-                && getDocument().getPDFVersion() != PDFDocument.PDF_VERSION_1_4) {
+                && !Version.V1_4.equals(getDocument().getPDFVersion())) {
             throw new PDFConformanceException(format(err, getPDFXMode()));
         }
     }
Index: src/java/org/apache/fop/pdf/PDFRoot.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFRoot.java	(revision 1136491)
+++ src/java/org/apache/fop/pdf/PDFRoot.java	(working copy)
@@ -201,7 +201,7 @@
      * @since PDF 1.4
      */
     public void setMetadata(PDFMetadata meta) {
-        if (getDocumentSafely().getPDFVersion() >= PDFDocument.PDF_VERSION_1_4) {
+        if (getDocumentSafely().getPDFVersion().compareTo(Version.V1_4) >= 0) {
             put("Metadata", meta.makeReference());
         }
     }
@@ -231,7 +231,7 @@
      * @since PDF 1.4
      */
     public void addOutputIntent(PDFOutputIntent outputIntent) {
-        if (getDocumentSafely().getPDFVersion() >= PDFDocument.PDF_VERSION_1_4) {
+        if (getDocumentSafely().getPDFVersion().compareTo(Version.V1_4) >= 0) {
             PDFArray outputIntents = getOutputIntents();
             if (outputIntents == null) {
                 outputIntents = new PDFArray(this);
Index: src/java/org/apache/fop/pdf/PDFDocument.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFDocument.java	(revision 1136491)
+++ src/java/org/apache/fop/pdf/PDFDocument.java	(working copy)
@@ -66,15 +66,8 @@
  *
  */
 public class PDFDocument {
-
     private static final Long LOCATION_PLACEHOLDER = new Long(0);
 
-    /** Integer constant to represent PDF 1.3 */
-    public static final int PDF_VERSION_1_3 = 3;
-
-    /** Integer constant to represent PDF 1.4 */
-    public static final int PDF_VERSION_1_4 = 4;
-
     /** the encoding to use when converting strings to PDF commands */
     public static final String ENCODING = "ISO-8859-1";
 
@@ -100,7 +93,7 @@
     private List objects = new LinkedList();
 
     /** Indicates what PDF version is active */
-    private int pdfVersion = PDF_VERSION_1_4;
+    private Version pdfVersion;
 
     /** Indicates which PDF profiles are active (PDF/A, PDF/X etc.) */
     private PDFProfile pdfProfile = new PDFProfile(this);
@@ -199,7 +192,24 @@
      * @param prod the name of the producer of this pdf document
      */
     public PDFDocument(String prod) {
+        this(prod, Version.V1_4);
+    }
 
+    /**
+     * Creates an empty PDF document.
+     *
+     * The constructor creates a /Root and /Pages object to
+     * track the document but does not write these objects until
+     * the trailer is written. Note that the object ID of the
+     * pages object is determined now, and the xref table is
+     * updated later. This allows Pages to refer to their
+     * Parent before we write it out.
+     *
+     * @param prod the name of the producer of this pdf document
+     * @param version the version of this PDF document
+     */
+    public PDFDocument(String prod, Version version) {
+
         this.factory = new PDFFactory(this);
 
         /* create the /Root, /Info and /Resources objects */
@@ -213,26 +223,21 @@
 
         // Make the /Info record
         this.info = getFactory().makeInfo(prod);
+
+        this.pdfVersion = version;
     }
 
     /**
-     * @return the integer representing the active PDF version
-     *          (one of PDFDocument.PDF_VERSION_*)
+     * Returns an enumerated type representing the active PDF version
+     * @return returns {@link Version}
      */
-    public int getPDFVersion() {
+    public Version getPDFVersion() {
         return this.pdfVersion;
     }
 
     /** @return the String representing the active PDF version */
     public String getPDFVersionString() {
-        switch (getPDFVersion()) {
-        case PDF_VERSION_1_3:
-            return "1.3";
-        case PDF_VERSION_1_4:
-            return "1.4";
-        default:
-            throw new IllegalStateException("Unsupported PDF version selected");
-        }
+        return pdfVersion.toString();
     }
 
     /** @return the PDF profile currently active. */
Index: src/documentation/content/xdocs/trunk/configuration.xml
===================================================================
--- src/documentation/content/xdocs/trunk/configuration.xml	(revision 1136491)
+++ src/documentation/content/xdocs/trunk/configuration.xml	(working copy)
@@ -375,6 +375,20 @@
          <noannotations/>
       </encryption-params>
     </renderer>]]></source>
+     <p>
+     The version of the PDF document created by FOP can be configured manually by specifying it in
+     the configuration file. This feature was added to work in conjunction with the PDF-as-an-image
+     feature, such that PDF versions greater than 1.4 can be embedded. Only versions 1.4-1.7 are
+     supported in this feature, since FOP creates PDF 1.4 (so all previous version could be
+     invalid). This does NOT mean that all versions of PDF are supported if specifically set, only
+     that the version in the header of the PDF document can be configured. This defaults to 1.4 if
+     not set.
+     <source><![CDATA[
+     <renderer mime="application/pdf">
+       <version>1.5</version>
+       <!-- versions 1.4, 1.5, 1.6 and 1.7 are supported, all other values are invalid -->
+     </renderer>]]></source>
+     </p>
       
     </section>
     <section id="ps-renderer">
