When I call PDField.setValue to set the value for the form field, I get the following stack:
FileSystemFontProvider.saveDiskCache(349) | Could not write to font cache java.io.FileNotFoundException: /.pdfbox.cache (Permission denied) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:194) at java.io.FileOutputStream.<init>(FileOutputStream.java:145) at java.io.FileWriter.<init>(FileWriter.java:73) at org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.saveDiskCache(FileSystemFontProvider.java:290) at org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.<init>(FileSystemFontProvider.java:226) at org.apache.pdfbox.pdmodel.font.FontMapperImpl$DefaultFontProvider.<clinit>(FontMapperImpl.java:130) at org.apache.pdfbox.pdmodel.font.FontMapperImpl.getProvider(FontMapperImpl.java:149) at org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFont(FontMapperImpl.java:413) at org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFontBoxFont(FontMapperImpl.java:376) at org.apache.pdfbox.pdmodel.font.FontMapperImpl.getFontBoxFont(FontMapperImpl.java:350) at org.apache.pdfbox.pdmodel.font.PDType1Font.<init>(PDType1Font.java:145) at org.apache.pdfbox.pdmodel.font.PDType1Font.<clinit>(PDType1Font.java:79) at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:62) at org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:143) at org.apache.pdfbox.pdmodel.interactive.form.PDDefaultAppearanceString.processSetFont(PDDefaultAppearanceString.java:164) at org.apache.pdfbox.pdmodel.interactive.form.PDDefaultAppearanceString.processOperator(PDDefaultAppearanceString.java:131) at org.apache.pdfbox.pdmodel.interactive.form.PDDefaultAppearanceString.processAppearanceStringOperators(PDDefaultAppearanceString.java:107) at org.apache.pdfbox.pdmodel.interactive.form.PDDefaultAppearanceString.<init>(PDDefaultAppearanceString.java:85) at org.apache.pdfbox.pdmodel.interactive.form.PDVariableText.getDefaultAppearanceString(PDVariableText.java:93) at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.<init>(AppearanceGeneratorHelper.java:94) at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:262) at org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228) at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:218)
I am launching PDFBox 2.0.4, which is the newest version. My web server most likely does not have write access to .pdfbox.cache in the default location (which seems to be a JVM property of user.home ). Is there a way to disable disk caching or change the location of the cache file?
I noticed that I can set the JVM wide system property called pdfbox.fontcache , but my webapp uses jvm with other applications, so this is not an optimal solution. I also tried using this solution and installed pdfbox.fontcache in /tmp , but actually did not create the file (although now it only throws the stack once per download).
I looked at the code in FileSystemFontProvider , and the problematic code is apparently in saveDiskCache . In this method, it first tries to write a file, but instead of a SecurityException, a FileNotFoundException is thrown. FileNotFoundException inherits from IOException.
File file = getDiskCacheFile(); try { writer = new BufferedWriter(new FileWriter(file)); } catch (SecurityException e) { return; }
source share