You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ju...@apache.org on 2010/10/06 11:22:29 UTC
svn commit: r1004935 - in /pdfbox/trunk/pdfbox/src:
main/java/org/apache/pdfbox/pdmodel/PDDocumentInformation.java
test/java/org/apache/pdfbox/TestAll.java
test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java
Author: jukka
Date: Wed Oct 6 09:22:27 2010
New Revision: 1004935
URL: http://svn.apache.org/viewvc?rev=1004935&view=rev
Log:
PDFBOX-764: Access to metadata keys in the PD model
Patch by Neil McErlean, with slight modifications
Added:
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java (with props)
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentInformation.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentInformation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentInformation.java?rev=1004935&r1=1004934&r2=1004935&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentInformation.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentInformation.java Wed Oct 6 09:22:27 2010
@@ -19,6 +19,8 @@ package org.apache.pdfbox.pdmodel;
import java.io.IOException;
import java.util.Calendar;
+import java.util.Set;
+import java.util.TreeSet;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
@@ -252,6 +254,21 @@ public class PDDocumentInformation imple
}
/**
+ * This will get the keys of all metadata information fields for the document.
+ *
+ * @return all metadata key strings.
+ * @since Apache PDFBox 1.3.0
+ */
+ public Set<String> getMetadataKeys()
+ {
+ Set<String> keys = new TreeSet<String>();
+ for (COSName key : info.keySet()) {
+ keys.add(key.getName());
+ }
+ return keys;
+ }
+
+ /**
* This will get the value of a custom metadata information field for the document.
* This will return null if one is not found.
*
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java?rev=1004935&r1=1004934&r2=1004935&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java Wed Oct 6 09:22:27 2010
@@ -20,6 +20,7 @@ import org.apache.pdfbox.cos.TestCOSStri
import org.apache.pdfbox.filter.TestFilters;
import org.apache.pdfbox.pdmodel.TestFDF;
import org.apache.pdfbox.pdmodel.TestPDDocumentCatalog;
+import org.apache.pdfbox.pdmodel.TestPDDocumentInformation;
import org.apache.pdfbox.pdmodel.interactive.form.TestFields;
import org.apache.pdfbox.util.TestDateUtil;
import junit.framework.Test;
@@ -70,6 +71,7 @@ public class TestAll extends TestCase
suite.addTest( TestFields.suite() );
suite.addTest( TestCOSString.suite() );
suite.addTestSuite( TestPDDocumentCatalog.class );
+ suite.addTestSuite( TestPDDocumentInformation.class );
return suite;
}
}
Added: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java?rev=1004935&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java (added)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java Wed Oct 6 09:22:27 2010
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+package org.apache.pdfbox.pdmodel;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * This class tests the extraction of document-level metadata.
+ * @author Neil McErlean
+ * @since 1.3.0
+ */
+public class TestPDDocumentInformation extends TestCase {
+
+ public void testMetadataExtraction() throws Exception {
+ PDDocument doc = null;
+ try
+ {
+ // This document has been selected for this test as it contains custom metadata.
+ doc = PDDocument.load( "src/test/resources/input/hello3.pdf");
+ PDDocumentInformation info = doc.getDocumentInformation();
+
+ assertEquals("Wrong author", "Brian Carrier", info.getAuthor());
+ assertNotNull("Wrong creationDate", info.getCreationDate());
+ assertEquals("Wrong creator", "Acrobat PDFMaker 8.1 for Word", info.getCreator());
+ assertNull ("Wrong keywords", info.getKeywords());
+ assertNotNull("Wrong modificationDate", info.getModificationDate());
+ assertEquals("Wrong producer", "Acrobat Distiller 8.1.0 (Windows)", info.getProducer());
+ assertNull ("Wrong subject", info.getSubject());
+ assertNull ("Wrong trapped", info.getTrapped());
+
+ List<String> expectedMetadataKeys = Arrays.asList(new String[] {"CreationDate", "Author", "Creator",
+ "Producer", "ModDate", "Company",
+ "SourceModified", "Title"});
+ assertEquals("Wrong metadata key count", expectedMetadataKeys.size(),
+ info.getMetadataKeys().size());
+ for (String key : expectedMetadataKeys) {
+ assertTrue("Missing metadata key:" + key, info.getMetadataKeys().contains(key));
+ }
+
+ // Custom metadata fields.
+ assertEquals("Wrong company", "Basis Technology Corp.", info.getCustomMetadataValue("Company"));
+ assertEquals("Wrong sourceModified", "D:20080819181502", info.getCustomMetadataValue("SourceModified"));
+ }
+ finally
+ {
+ if( doc != null )
+ {
+ doc.close();
+ }
+ }
+ }
+}
Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java
------------------------------------------------------------------------------
svn:eol-style = native