Skip to content

Commit 7355c13

Browse files
author
Andrei Stryhelski
committed
Add veraPDF log handling, update veraPDF to 1.22.2 version
DEVSIX-3496
1 parent ddb8af6 commit 7355c13

File tree

6 files changed

+160
-4
lines changed

6 files changed

+160
-4
lines changed

pdftest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<url>https://itextpdf.com/</url>
1212
<properties>
1313
<sonar.skip>true</sonar.skip>
14-
<verapdf.version>1.20.1</verapdf.version>
14+
<verapdf.version>1.22.2</verapdf.version>
1515
</properties>
1616
<dependencies>
1717
<dependency>

pdftest/src/main/java/com/itextpdf/test/pdfa/VeraPdfValidator.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@ This file is part of the iText (R) project.
4343
*/
4444
package com.itextpdf.test.pdfa;
4545

46+
import java.util.logging.Level;
47+
import org.verapdf.component.Log;
48+
import org.verapdf.component.LogsSummary;
49+
import org.verapdf.component.LogsSummaryImpl;
4650
import org.verapdf.core.VeraPDFException;
4751
import org.verapdf.features.FeatureExtractorConfig;
52+
import org.verapdf.gf.foundry.VeraGreenfieldFoundryProvider;
4853
import org.verapdf.metadata.fixer.MetadataFixerConfig;
49-
import org.verapdf.pdfa.VeraGreenfieldFoundryProvider;
54+
import org.verapdf.pdfa.flavours.PDFAFlavour;
5055
import org.verapdf.pdfa.validation.validators.ValidatorConfig;
56+
import org.verapdf.pdfa.validation.validators.ValidatorFactory;
5157
import org.verapdf.processor.BatchProcessor;
5258
import org.verapdf.processor.ProcessorConfig;
5359
import org.verapdf.processor.ProcessorFactory;
@@ -74,7 +80,8 @@ public String validate(String filePath) {
7480
// Initializes default VeraPDF configurations
7581
ProcessorConfig customProfile = ProcessorFactory.defaultConfig();
7682
FeatureExtractorConfig featuresConfig = customProfile.getFeatureConfig();
77-
ValidatorConfig valConfig = customProfile.getValidatorConfig();
83+
ValidatorConfig valConfig = ValidatorFactory.createConfig(PDFAFlavour.NO_FLAVOUR, false, -1, false, true,
84+
Level.WARNING);
7885
PluginsCollectionConfig plugConfig = customProfile.getPluginsCollectionConfig();
7986
MetadataFixerConfig metaConfig = customProfile.getFixerConfig();
8087
ProcessorConfig resultConfig = ProcessorFactory.fromValues(valConfig, featuresConfig,
@@ -85,8 +92,9 @@ public String validate(String filePath) {
8592

8693
BatchSummary summary = processor.process(Collections.singletonList(new File(filePath)),
8794
ProcessorFactory.getHandler(FormatOption.XML, true,
88-
new FileOutputStream(String.valueOf(xmlReport)), 125, false));
95+
new FileOutputStream(String.valueOf(xmlReport)), false));
8996

97+
LogsSummary logsSummary = LogsSummaryImpl.getSummary();
9098
String xmlReportPath = "file://" + xmlReport.toURI().normalize().getPath();
9199

92100
if (summary.getFailedParsingJobs() != 0) {
@@ -95,6 +103,12 @@ public String validate(String filePath) {
95103
errorMessage = "VeraPDF execution failed - specified file is encrypted. See report: " + xmlReportPath;
96104
} else if (summary.getValidationSummary().getNonCompliantPdfaCount() != 0) {
97105
errorMessage = "VeraPDF verification failed. See verification results: " + xmlReportPath;
106+
} else if (logsSummary.getLogsCount() != 0) {
107+
errorMessage = "The following warnings and errors occurred while parsing current file:";
108+
for (Log log : logsSummary.getLogs()) {
109+
errorMessage += "\n" + log.getLevel() + ": " + log.getMessage();
110+
}
111+
errorMessage += "\nSee verification results:" + xmlReportPath;
98112
} else {
99113
System.out.println("VeraPDF verification finished. See verification report: " + xmlReportPath);
100114
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2022 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.test.utils;
44+
45+
import java.io.IOException;
46+
import java.nio.file.Files;
47+
import java.nio.file.Paths;
48+
import java.nio.file.StandardCopyOption;
49+
50+
public final class FileUtil {
51+
/**
52+
* Creates a copy of a file.
53+
*
54+
* @param inputFile the path to the file to be copied
55+
* @param outputFile the path, to which the passed file should be copied
56+
*
57+
* @throws IOException signals that an I/O exception has occurred.
58+
*/
59+
public static void copy(String inputFile, String outputFile)
60+
throws IOException {
61+
Files.copy(Paths.get(inputFile), Paths.get(outputFile), StandardCopyOption.REPLACE_EXISTING);
62+
}
63+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2022 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.test;
44+
45+
import com.itextpdf.test.annotations.type.UnitTest;
46+
import com.itextpdf.test.pdfa.VeraPdfValidator;
47+
import com.itextpdf.test.utils.FileUtil;
48+
49+
import java.io.IOException;
50+
import org.junit.Assert;
51+
import org.junit.BeforeClass;
52+
import org.junit.Test;
53+
import org.junit.experimental.categories.Category;
54+
55+
56+
@Category(UnitTest.class)
57+
public class VeraPdfLoggerValidationTest extends ExtendedITextTest {
58+
59+
static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/pdftest/cmp/VeraPdfLoggerValidationTest/";
60+
static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/pdftest/VeraPdfLoggerValidationTest/";
61+
62+
@BeforeClass
63+
public static void beforeClass() {
64+
createDestinationFolder(DESTINATION_FOLDER);
65+
}
66+
67+
@Test
68+
public void checkValidatorLogsTest() throws IOException {
69+
70+
String fileNameWithWarnings = "cmp_pdfA2b_checkValidatorLogsTest_with_warnings.pdf";
71+
String fileNameWithoutWarnings = "cmp_pdfA2b_checkValidatorLogsTest.pdf";
72+
FileUtil.copy(SOURCE_FOLDER + fileNameWithWarnings, DESTINATION_FOLDER + fileNameWithWarnings);
73+
FileUtil.copy(SOURCE_FOLDER + fileNameWithoutWarnings, DESTINATION_FOLDER + fileNameWithoutWarnings);
74+
75+
Assert.assertNotNull(new VeraPdfValidator().validate(DESTINATION_FOLDER + fileNameWithWarnings));
76+
//We check that the logs are empty after the first check
77+
Assert.assertNull(new VeraPdfValidator().validate(DESTINATION_FOLDER + fileNameWithoutWarnings));
78+
}
79+
}

0 commit comments

Comments
 (0)