Skip to content

Commit f3ed837

Browse files
committed
Add PdfAIndirectResourcesTest class
DEVSIX-3735
1 parent 954d61a commit f3ed837

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

pdfa/src/test/java/com/itextpdf/pdfa/PdfA2LayoutOcgTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ This file is part of the iText (R) project.
5656
import com.itextpdf.layout.element.Image;
5757
import com.itextpdf.test.ExtendedITextTest;
5858
import com.itextpdf.test.annotations.type.IntegrationTest;
59+
import com.itextpdf.test.pdfa.VeraPdfValidator;
5960
import org.junit.Assert;
6061
import org.junit.Before;
6162
import org.junit.Test;
@@ -104,6 +105,7 @@ public void checkIfOcgForPdfA2Works() throws IOException, InterruptedException {
104105

105106
pdfDoc.close();
106107
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff01_"));
108+
Assert.assertNull(new VeraPdfValidator().validate(outFileName));
107109
}
108110

109111
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 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.pdfa;
44+
45+
import com.itextpdf.kernel.pdf.PdfIndirectReference;
46+
import com.itextpdf.kernel.pdf.PdfReader;
47+
import com.itextpdf.kernel.pdf.PdfWriter;
48+
import com.itextpdf.kernel.xmp.XMPException;
49+
import com.itextpdf.test.ExtendedITextTest;
50+
import com.itextpdf.test.annotations.LogMessage;
51+
import com.itextpdf.test.annotations.LogMessages;
52+
import com.itextpdf.test.annotations.type.IntegrationTest;
53+
import org.junit.Before;
54+
import org.junit.Test;
55+
import org.junit.experimental.categories.Category;
56+
57+
import java.io.FileNotFoundException;
58+
import java.io.IOException;
59+
import java.util.Set;
60+
61+
@Category(IntegrationTest.class)
62+
public class PdfAIndirectResourcesTest extends ExtendedITextTest {
63+
public static final String sourceFolder = "./src/test/resources/com/itextpdf/pdfa/pdfs/";
64+
public static final String destinationFolder = "./target/test/com/itextpdf/pdfa/PdfAIndirectResourcesTest/";
65+
66+
@Before
67+
public void configure() {
68+
createDestinationFolder(destinationFolder);
69+
}
70+
71+
@Test
72+
@LogMessages(messages = {
73+
@LogMessage(messageTemplate = PdfAConformanceLogMessageConstant.CATALOG_SHOULD_CONTAIN_LANG_ENTRY)
74+
})
75+
public void indirectResources01Test() throws IOException, XMPException, InterruptedException {
76+
String fileName = destinationFolder + "indirectResources01Test.pdf";
77+
PdfADocument pdfDoc = new PdfADocument(new PdfReader(sourceFolder + "indirectResources01.pdf"), new PdfWriter(fileName));
78+
pdfDoc.close();
79+
}
80+
81+
@Test
82+
public void indirectResources02Test() throws IOException, XMPException, InterruptedException {
83+
String fileName = destinationFolder + "indirectResources02Test.pdf";
84+
85+
PdfWriter writer = new CustomPdfWriter(fileName, 19);
86+
PdfADocument pdfDoc = new PdfADocument(new PdfReader(sourceFolder + "indirectResources02.pdf"), writer);
87+
pdfDoc.close();
88+
}
89+
90+
private static class CustomPdfWriter extends PdfWriter {
91+
private int objectToFlushNumber;
92+
93+
public CustomPdfWriter(String filename, int objectToFlushNumber) throws FileNotFoundException {
94+
super(filename);
95+
this.objectToFlushNumber = objectToFlushNumber;
96+
}
97+
98+
@Override
99+
protected void flushWaitingObjects(Set<PdfIndirectReference> forbiddenToFlush) {
100+
// Because of flushing order in PdfDocument is uncertain, flushWaitingObjects() method is overridden
101+
// to simulate the issue when the certain PdfObject A, that exists in the Catalog entry and in the resources
102+
// of another PdfObject B, is flushed before the flushing of the PdfObject B.
103+
super.document.getPdfObject(objectToFlushNumber).flush();
104+
super.flushWaitingObjects(forbiddenToFlush);
105+
}
106+
}
107+
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)