Akhildas Mp
Akhildas Mp

Reputation: 11

Docx4j error while running in AWS lambda, It works fine in local machine

I have implemented conversion of docx file to pdf using Docx4j, its working well in my local machine and getting exceptions in aws lambda.

Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.RuntimeException: org.docx4j.fonts.fop.apps.FOPException: java.io.FileNotFoundException: .docx4j (Read-only file system)

Please see this code

Docx4jProperties.setProperty("docx4j.openpackaging.parts.TempDir", "/tmp");
System.setProperty("java.io.tmpdir", "/tmp");
String convertedFileName = "/tmp/templFile.pdf";

File file = new File(convertedFileName);
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(contents);

FileOutputStream fout = new FileOutputStream(convertedFileName);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setApacheFopMime(MimeConstants.MIME_PDF);
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toFO(foSettings, fout, Docx4J.FLAG_EXPORT_PREFER_XSL);

FileInputStream fin = new FileInputStream(convertedFileName);
content = fin.readAllBytes();
fin.close();
file.delete();

I think lambda only allows to write files in /tmp folder , so I have added that in code still not working.

Upvotes: 1

Views: 36

Answers (0)

Related Questions