Skip to content

Commit ee9b8f0

Browse files
committed
verapdf-interface: switched to pdf/ua-2
1 parent a571e0a commit ee9b8f0

1 file changed

Lines changed: 50 additions & 43 deletions

File tree

  • services/aws-lambda-verapdf-interface/src/main/java/com/equalifyuic/app

services/aws-lambda-verapdf-interface/src/main/java/com/equalifyuic/app/handler.java

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
//import org.verapdf.processor.reports.multithread.writer.JsonReportWriter;
3232
import org.verapdf.pdfa.PDFAValidator;
3333
//import org.verapdf.pdfa.flavours.PDFAFlavour;
34+
import org.verapdf.pdfa.flavours.PDFAFlavour;
3435

3536
public class handler implements RequestHandler<String, String> {
3637
@Override
@@ -69,59 +70,65 @@ public String handleRequest(String input, Context context) {
6970

7071
VeraGreenfieldFoundryProvider.initialise();
7172
String output = "";
72-
try (PDFAParser parser = Foundries.defaultInstance().createParser(new FileInputStream(filePath))) {
73-
PDFAValidator validator = Foundries.defaultInstance().createValidator(parser.getFlavour(), false);
73+
PDFAFlavour flavour = PDFAFlavour.PDFUA_2;
74+
try (PDFAParser parser = Foundries.defaultInstance().createParser(new FileInputStream("mydoc.pdf"), flavour)) {
75+
PDFAValidator validator = Foundries.defaultInstance().createValidator(flavour, false);
7476
ValidationResult result = validator.validate(parser);
75-
77+
7678
// Use Jackson ObjectMapper to write the ValidationResult object as JSON
7779
ObjectMapper mapper = new ObjectMapper();
7880
output = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(result.getFailedChecks());
7981

80-
/* if (result.isCompliant()) {
81-
// File is a valid PDF/A 1b
82-
} else {
83-
// it isn't
84-
} */
82+
/*
83+
* if (result.isCompliant()) {
84+
* // File is a valid PDF/A 1b
85+
* } else {
86+
* // it isn't
87+
* }
88+
*/
8589
} catch (IOException | ValidationException | ModelParsingException | EncryptedPdfException exception) {
8690
// Exception during validation
8791
logger.log(exception.toString());
8892
}
89-
// if the file doesn't end in PDF, pass the --nonpdfext flag
90-
/* String nonpdfextFlag = filePath.toString().endsWith(".pdf")
91-
? ""
92-
: "--nonpdfext ";
93-
ProcessBuilder pb = new ProcessBuilder(
94-
"/opt/java/lib/vera/verapdf",
95-
"-f",
96-
"ua2",
97-
"--format",
98-
"json",
99-
nonpdfextFlag,
100-
filePath.toString());
101-
pb.redirectErrorStream(true); // also get errors
10293

103-
String output = "";
104-
try {
105-
Process process = pb.start();
106-
StringBuilder outputSb = new StringBuilder();
107-
try (BufferedReader reader = new BufferedReader(
108-
new InputStreamReader(process.getInputStream()))) {
109-
String line;
110-
// 3. Read line by line until the stream ends
111-
while ((line = reader.readLine()) != null) {
112-
outputSb.append(line).append(System.lineSeparator());
113-
}
114-
}
115-
int exitCode = process.waitFor();
116-
117-
if (exitCode != 0) {
118-
logger.log("Command exited with non-zero code: " + exitCode);
119-
}
120-
output = outputSb.toString();
121-
122-
} catch (IOException | InterruptedException e) {
123-
logger.log(e.toString());
124-
} */
94+
// if the file doesn't end in PDF, pass the --nonpdfext flag
95+
/*
96+
* String nonpdfextFlag = filePath.toString().endsWith(".pdf")
97+
* ? ""
98+
* : "--nonpdfext ";
99+
* ProcessBuilder pb = new ProcessBuilder(
100+
* "/opt/java/lib/vera/verapdf",
101+
* "-f",
102+
* "ua2",
103+
* "--format",
104+
* "json",
105+
* nonpdfextFlag,
106+
* filePath.toString());
107+
* pb.redirectErrorStream(true); // also get errors
108+
*
109+
* String output = "";
110+
* try {
111+
* Process process = pb.start();
112+
* StringBuilder outputSb = new StringBuilder();
113+
* try (BufferedReader reader = new BufferedReader(
114+
* new InputStreamReader(process.getInputStream()))) {
115+
* String line;
116+
* // 3. Read line by line until the stream ends
117+
* while ((line = reader.readLine()) != null) {
118+
* outputSb.append(line).append(System.lineSeparator());
119+
* }
120+
* }
121+
* int exitCode = process.waitFor();
122+
*
123+
* if (exitCode != 0) {
124+
* logger.log("Command exited with non-zero code: " + exitCode);
125+
* }
126+
* output = outputSb.toString();
127+
*
128+
* } catch (IOException | InterruptedException e) {
129+
* logger.log(e.toString());
130+
* }
131+
*/
125132

126133
logger.log("Processing complete for " + input);
127134
logger.log(output);

0 commit comments

Comments
 (0)