pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1599026 - in /pdfbox/trunk: examples/ examples/src/main/java/org/apache/pdfbox/examples/pdfa/ examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ pdfbox/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/
Date Sun, 01 Jun 2014 19:12:22 GMT
Author: msahyoun
Date: Sun Jun  1 19:12:20 2014
New Revision: 1599026

URL: http://svn.apache.org/r1599026
Log:
PDFBOX-2107 Make PDFBox XMP library agnostic

Modified:
    pdfbox/trunk/examples/pom.xml
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractMetadata.java
    pdfbox/trunk/pdfbox/pom.xml
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java

Modified: pdfbox/trunk/examples/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/pom.xml?rev=1599026&r1=1599025&r2=1599026&view=diff
==============================================================================
--- pdfbox/trunk/examples/pom.xml (original)
+++ pdfbox/trunk/examples/pom.xml Sun Jun  1 19:12:20 2014
@@ -54,6 +54,11 @@
         <version>${project.version}</version>
     </dependency>
     <dependency>
+		<groupId>org.apache.pdfbox</groupId>
+        <artifactId>jempbox</artifactId>
+        <version>${project.version}</version>
+    </dependency>
+    <dependency>
         <groupId>org.apache.lucene</groupId>
         <artifactId>lucene-core</artifactId>
         <version>${lucene.version}</version>

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java?rev=1599026&r1=1599025&r2=1599026&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java Sun
Jun  1 19:12:20 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.pdfbox.examples.pdfa;
 
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
 import org.apache.jempbox.xmp.XMPMetadata;
@@ -58,7 +59,7 @@ public class CreatePDFA
      *
      * @throws Exception If something bad occurs
      */
-    public void doIt( String file, String message) throws Exception
+    public void doIt( final String file, final String message, final String fontfile) throws
Exception
     {
         // the document
         PDDocument doc = null;
@@ -69,9 +70,8 @@ public class CreatePDFA
             PDPage page = new PDPage();
             doc.addPage( page );
 
-            // load the font from pdfbox.jar
-            InputStream fontStream = CreatePDFA.class.getResourceAsStream("/org/apache/pdfbox/resources/ttf/ArialMT.ttf");
-            PDFont font = PDTrueTypeFont.loadTTF(doc, fontStream);
+            // load the font as this needs to be embedded as part of PDF/A
+            PDFont font = PDTrueTypeFont.loadTTF(doc, fontfile);
             
             // create a page with the message where needed
             PDPageContentStream contentStream = new PDPageContentStream(doc, page);
@@ -94,8 +94,9 @@ public class CreatePDFA
             pdfaid.setConformance("B");
             pdfaid.setPart(1);
             pdfaid.setAbout("");
-            metadata.importXMPMetadata(xmp);
-    
+            
+            metadata.importXMPMetadata( xmp.asByteArray() );
+            
             InputStream colorProfile = CreatePDFA.class.getResourceAsStream("/org/apache/pdfbox/resources/pdfa/sRGB
Color Space Profile.icm");
             // create output intent
             PDOutputIntent oi = new PDOutputIntent(doc, colorProfile); 
@@ -129,13 +130,13 @@ public class CreatePDFA
         CreatePDFA app = new CreatePDFA();
         try
         {
-            if( args.length != 2 )
+            if( args.length != 3 )
             {
                 app.usage();
             }
             else
             {
-                app.doIt( args[0], args[1] );
+                app.doIt( args[0], args[1], args[2] );
             }
         }
         catch (Exception e)
@@ -149,6 +150,6 @@ public class CreatePDFA
      */
     private void usage()
     {
-        System.err.println( "usage: " + this.getClass().getName() + " <output-file>
<Message>" );
+        System.err.println( "usage: " + this.getClass().getName() + " <output-file>
<Message> <ttf-file>" );
     }
 }

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.java?rev=1599026&r1=1599025&r2=1599026&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.java
Sun Jun  1 19:12:20 2014
@@ -26,6 +26,7 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.pdmodel.PDDocumentInformation;
 import org.apache.pdfbox.pdmodel.common.PDMetadata;
 
+import java.io.ByteArrayOutputStream;
 import java.util.GregorianCalendar;
 
 /**
@@ -70,7 +71,7 @@ public class AddMetadataFromDocInfo
                 }
                 PDDocumentCatalog catalog = document.getDocumentCatalog();
                 PDDocumentInformation info = document.getDocumentInformation();
-
+                
                 XMPMetadata metadata = new XMPMetadata();
 
                 XMPSchemaPDF pdfSchema = metadata.addPDFSchema();
@@ -89,7 +90,7 @@ public class AddMetadataFromDocInfo
                 dcSchema.setDescription( info.getSubject() );
 
                 PDMetadata metadataStream = new PDMetadata(document);
-                metadataStream.importXMPMetadata( metadata );
+                metadataStream.importXMPMetadata( metadata.asByteArray() );
                 catalog.setMetadata( metadataStream );
 
                 document.save( args[1] );

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractMetadata.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractMetadata.java?rev=1599026&r1=1599025&r2=1599026&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractMetadata.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractMetadata.java
Sun Jun  1 19:12:20 2014
@@ -31,7 +31,12 @@ import java.text.DateFormat;
 import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial;
+import org.w3c.dom.Document;
 
 /**
  * This is an example on how to extract metadata from a PDF document.
@@ -84,7 +89,10 @@ public class ExtractMetadata
                 PDMetadata meta = catalog.getMetadata();
                 if ( meta != null)
                 {
-                    XMPMetadata metadata = meta.exportXMPMetadata();
+                	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+                    DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
+                	Document xmpDocument = documentBuilder.parse(meta.createInputStream());
+                    XMPMetadata metadata = new XMPMetadata(xmpDocument);
     
                     XMPSchemaDublinCore dc = metadata.getDublinCoreSchema();
                     if (dc != null)

Modified: pdfbox/trunk/pdfbox/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/pom.xml?rev=1599026&r1=1599025&r2=1599026&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/pom.xml (original)
+++ pdfbox/trunk/pdfbox/pom.xml Sun Jun  1 19:12:20 2014
@@ -43,11 +43,6 @@
             <version>${project.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.pdfbox</groupId>
-            <artifactId>jempbox</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
         </dependency>

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java?rev=1599026&r1=1599025&r2=1599026&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java Sun
Jun  1 19:12:20 2014
@@ -18,10 +18,10 @@ package org.apache.pdfbox.pdmodel.common
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 
 import javax.xml.transform.TransformerException;
 
-import org.apache.jempbox.xmp.XMPMetadata;
 import org.apache.pdfbox.cos.COSStream;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
@@ -74,16 +74,16 @@ public class PDMetadata extends PDStream
     }
 
     /**
-     * Extract the XMP metadata and create and build an in memory object.
+     * Extract the XMP metadata.
      * To persist changes back to the PDF you must call importXMPMetadata.
      *
-     * @return A parsed XMP object.
+     * @return A stream to get the xmp data from.
      *
      * @throws IOException If there is an error parsing the XMP data.
      */
-    public XMPMetadata exportXMPMetadata() throws IOException
+    public InputStream exportXMPMetadata() throws IOException
     {
-        return XMPMetadata.load( createInputStream() );
+        return createInputStream();
     }
 
     /**
@@ -94,9 +94,11 @@ public class PDMetadata extends PDStream
      * @throws IOException If there is an error generating the XML document.
      * @throws TransformerException If there is an error generating the XML document.
      */
-    public void importXMPMetadata( XMPMetadata xmp )
-        throws IOException, TransformerException
+    public void importXMPMetadata( byte[] xmp )
+        throws IOException
     {
-        xmp.save( createOutputStream() );
+    	OutputStream os = createOutputStream();
+    	os.write(xmp);
+    	os.close();
     }
 }



Mime
View raw message