pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1855651 - /pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
Date Sat, 16 Mar 2019 14:31:59 GMT
Author: tilman
Date: Sat Mar 16 14:31:59 2019
New Revision: 1855651

URL: http://svn.apache.org/viewvc?rev=1855651&view=rev
Log:
PDFBOX-4485: improve example for backwards, cross-platform and cross-language compatibility;
improve format; enable show attachments panel; remove typo

Modified:
    pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java

Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java?rev=1855651&r1=1855650&r2=1855651&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
(original)
+++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
Sat Mar 16 14:31:59 2019
@@ -27,11 +27,10 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
 import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
 import org.apache.pdfbox.pdmodel.PDPage;
-
 import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
 import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
 import org.apache.pdfbox.pdmodel.PDPageContentStream;
-
+import org.apache.pdfbox.pdmodel.PageMode;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
 
@@ -47,7 +46,6 @@ public class EmbeddedFiles
      */
     public EmbeddedFiles()
     {
-        super();
     }
 
     /**
@@ -59,7 +57,6 @@ public class EmbeddedFiles
      */
     public void doIt( String file) throws IOException
     {
-        // the document
         PDDocument doc = null;
         try
         {
@@ -89,16 +86,18 @@ public class EmbeddedFiles
 
             //create a dummy file stream, this would probably normally be a FileInputStream
             byte[] data = "This is the contents of the embedded file".getBytes("ISO-8859-1");
-            ByteArrayInputStream fakeFile =
-                new ByteArrayInputStream( data );
+            ByteArrayInputStream fakeFile = new ByteArrayInputStream(data);
             PDEmbeddedFile ef = new PDEmbeddedFile(doc, fakeFile );
             //now lets some of the optional parameters
-            ef.setSubtype( "test/plain" );
+            ef.setSubtype( "text/plain" );
             ef.setSize( data.length );
             ef.setCreationDate( new GregorianCalendar() );
+
+            // use both methods for backwards, cross-platform and cross-language compatibility.
             fs.setEmbeddedFile( ef );
+            fs.setEmbeddedFileUnicode(ef);
 
-            // create a new tree node and add the embedded file 
+            // create a new tree node and add the embedded file
             PDEmbeddedFilesNameTreeNode treeNode = new PDEmbeddedFilesNameTreeNode();
             treeNode.setNames( Collections.singletonMap( "My first attachment",  fs ) );
             // add the new node as kid to the root node
@@ -110,6 +109,8 @@ public class EmbeddedFiles
             names.setEmbeddedFiles( efTree );
             doc.getDocumentCatalog().setNames( names );
 
+            // show attachments panel in some viewers 
+            doc.getDocumentCatalog().setPageMode(PageMode.USE_ATTACHMENTS);
 
             doc.save( file );
         }



Mime
View raw message