Skip to content

Commit

Permalink
PDFBOX-5086: don't write to a loaded pdf document which is still open
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1885878 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
lehmi committed Jan 24, 2021
1 parent 1b6aed8 commit 3d8f1a3
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void setField(String[] args) throws IOException
SetField example = new SetField();
pdf = Loader.loadPDF(new File(args[0]));
example.setField(pdf, args[1], args[2]);
pdf.save(args[0]);
pdf.save(calculateOutputFilename(args[0]));
}
}
finally
Expand All @@ -130,6 +130,21 @@ private void setField(String[] args) throws IOException
}
}

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.
*/
Expand Down

0 comments on commit 3d8f1a3

Please sign in to comment.