You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2021/01/24 12:56:59 UTC

svn commit: r1885877 - /pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java

Author: lehmi
Date: Sun Jan 24 12:56:59 2021
New Revision: 1885877

URL: http://svn.apache.org/viewvc?rev=1885877&view=rev
Log:
PDFBOX-5086: don't write to a loaded pdf document which is still open

Modified:
    pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java

Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java?rev=1885877&r1=1885876&r2=1885877&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java (original)
+++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java Sun Jan 24 12:56:59 2021
@@ -116,7 +116,7 @@ public class SetField
                 SetField example = new SetField();
                 pdf = PDDocument.load(new File(args[0]));
                 example.setField(pdf, args[1], args[2]);
-                pdf.save(args[0]);
+                pdf.save(calculateOutputFilename(args[0]));
             }
         }
         finally
@@ -128,6 +128,21 @@ public class SetField
         }
     }
 
+    private static String calculateOutputFilename(String filename)
+    {
+        String outputFilename;
+        if (filename.toLowerCase().endsWith(".pdf"))
+        {
+            outputFilename = filename.substring(0, filename.length() - 4);
+        }
+        else
+        {
+            outputFilename = filename;
+        }
+        outputFilename += "_filled.pdf";
+        return outputFilename;
+    }
+
     /**
      * This will print out a message telling how to use this example.
      */