@@ -23,6 +23,7 @@ This file is part of the iText (R) project.
23
23
package com .itextpdf .kernel .pdf .copy ;
24
24
25
25
import com .itextpdf .commons .utils .MessageFormatUtil ;
26
+ import com .itextpdf .io .logs .IoLogMessageConstant ;
26
27
import com .itextpdf .kernel .geom .Rectangle ;
27
28
import com .itextpdf .kernel .pdf .PdfArray ;
28
29
import com .itextpdf .kernel .pdf .PdfDictionary ;
@@ -39,6 +40,8 @@ This file is part of the iText (R) project.
39
40
import com .itextpdf .kernel .pdf .navigation .PdfExplicitDestination ;
40
41
import com .itextpdf .kernel .utils .CompareTool ;
41
42
import com .itextpdf .test .ExtendedITextTest ;
43
+ import com .itextpdf .test .annotations .LogMessage ;
44
+ import com .itextpdf .test .annotations .LogMessages ;
42
45
import com .itextpdf .test .annotations .type .IntegrationTest ;
43
46
44
47
import java .io .ByteArrayInputStream ;
@@ -53,19 +56,19 @@ This file is part of the iText (R) project.
53
56
@ Category (IntegrationTest .class )
54
57
public class PdfAnnotationCopyingTest extends ExtendedITextTest {
55
58
56
- public static final String destinationFolder = "./target/test/com/itextpdf/kernel/pdf/PdfAnnotationCopyingTest/" ;
57
- public static final String sourceFolder = "./src/test/resources/com/itextpdf/kernel/pdf/PdfAnnotationCopyingTest/" ;
59
+ public static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/kernel/pdf/PdfAnnotationCopyingTest/" ;
60
+ public static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/kernel/pdf/PdfAnnotationCopyingTest/" ;
58
61
59
62
@ BeforeClass
60
63
public static void beforeClass () {
61
- createOrClearDestinationFolder (destinationFolder );
64
+ createOrClearDestinationFolder (DESTINATION_FOLDER );
62
65
}
63
66
64
67
@ Test
65
68
@ Ignore ("Unignore when DEVSIX-3585 would be implemented" )
66
69
public void testCopyingPageWithAnnotationContainingPopupKey () throws IOException {
67
- String inFilePath = sourceFolder + "annotation-with-popup.pdf" ;
68
- String outFilePath = destinationFolder + "copy-annotation-with-popup.pdf" ;
70
+ String inFilePath = SOURCE_FOLDER + "annotation-with-popup.pdf" ;
71
+ String outFilePath = DESTINATION_FOLDER + "copy-annotation-with-popup.pdf" ;
69
72
PdfDocument originalDocument = new PdfDocument (new PdfReader (inFilePath ));
70
73
PdfDocument outDocument = new PdfDocument (new PdfWriter (outFilePath ));
71
74
@@ -108,8 +111,8 @@ public void testCopyingPageWithAnnotationContainingPopupKey() throws IOException
108
111
@ Test
109
112
@ Ignore ("Unignore when DEVSIX-3585 would be implemented" )
110
113
public void testCopyingPageWithAnnotationContainingIrtKey () throws IOException {
111
- String inFilePath = sourceFolder + "annotation-with-irt.pdf" ;
112
- String outFilePath = destinationFolder + "copy-annotation-with-irt.pdf" ;
114
+ String inFilePath = SOURCE_FOLDER + "annotation-with-irt.pdf" ;
115
+ String outFilePath = DESTINATION_FOLDER + "copy-annotation-with-irt.pdf" ;
113
116
PdfDocument originalDocument = new PdfDocument (new PdfReader (inFilePath ));
114
117
PdfDocument outDocument = new PdfDocument (new PdfWriter (outFilePath ));
115
118
@@ -148,34 +151,68 @@ public void testCopyingPageWithAnnotationContainingIrtKey() throws IOException {
148
151
@ Test
149
152
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
150
153
public void copySameLinksWithGoToSmartModeTest () throws IOException , InterruptedException {
151
- String cmpFilePath = sourceFolder + "cmp_copySameLinksWithGoToSmartMode.pdf" ;
152
- String outFilePath = destinationFolder + "copySameLinksWithGoToSmartMode.pdf" ;
154
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copySameLinksWithGoToSmartMode.pdf" ;
155
+ String outFilePath = DESTINATION_FOLDER + "copySameLinksWithGoToSmartMode.pdf" ;
153
156
154
157
copyLinksGoToActionTest (outFilePath , true , false );
155
158
156
- Assert .assertNull (new CompareTool ().compareByContent (outFilePath , cmpFilePath , destinationFolder ));
159
+ Assert .assertNull (new CompareTool ().compareByContent (outFilePath , cmpFilePath , DESTINATION_FOLDER ));
157
160
}
158
161
159
162
@ Test
160
163
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
161
164
public void copyDiffDestLinksWithGoToSmartModeTest () throws IOException , InterruptedException {
162
- String cmpFilePath = sourceFolder + "cmp_copyDiffDestLinksWithGoToSmartMode.pdf" ;
163
- String outFilePath = destinationFolder + "copyDiffDestLinksWithGoToSmartMode.pdf" ;
165
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyDiffDestLinksWithGoToSmartMode.pdf" ;
166
+ String outFilePath = DESTINATION_FOLDER + "copyDiffDestLinksWithGoToSmartMode.pdf" ;
164
167
165
168
copyLinksGoToActionTest (outFilePath , false , false );
166
169
167
- Assert .assertNull (new CompareTool ().compareByContent (outFilePath , cmpFilePath , destinationFolder ));
170
+ Assert .assertNull (new CompareTool ().compareByContent (outFilePath , cmpFilePath , DESTINATION_FOLDER ));
168
171
}
169
172
170
173
@ Test
171
174
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
172
175
public void copyDiffDisplayLinksWithGoToSmartModeTest () throws IOException , InterruptedException {
173
- String cmpFilePath = sourceFolder + "cmp_copyDiffDisplayLinksWithGoToSmartMode.pdf" ;
174
- String outFilePath = destinationFolder + "copyDiffDisplayLinksWithGoToSmartMode.pdf" ;
176
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyDiffDisplayLinksWithGoToSmartMode.pdf" ;
177
+ String outFilePath = DESTINATION_FOLDER + "copyDiffDisplayLinksWithGoToSmartMode.pdf" ;
175
178
176
179
copyLinksGoToActionTest (outFilePath , false , true );
177
180
178
- Assert .assertNull (new CompareTool ().compareByContent (outFilePath , cmpFilePath , destinationFolder ));
181
+ Assert .assertNull (new CompareTool ().compareByContent (outFilePath , cmpFilePath , DESTINATION_FOLDER ));
182
+ }
183
+
184
+ @ Test
185
+ // TODO: DEVSIX-6090 (update cmp file after fixing the issue)
186
+ @ LogMessages (messages = {
187
+ @ LogMessage (messageTemplate = IoLogMessageConstant .SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY )})
188
+ public void copyPagesWithWidgetAnnotGoToActionExplicitDestTest () throws IOException , InterruptedException {
189
+ String srcFilePath = SOURCE_FOLDER + "pageToCopyWithWidgetAnnotGoToActionExplicitDest.pdf" ;
190
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithWidgetAnnotGoToActionExplicitDest.pdf" ;
191
+ String outFilePath = DESTINATION_FOLDER + "copyPagesWithWidgetAnnotGoToActionExplicitDest.pdf" ;
192
+
193
+ copyPages (srcFilePath , outFilePath , cmpFilePath );
194
+ }
195
+
196
+ @ Test
197
+ // TODO: DEVSIX-6090 (update cmp file after fixing the issue)
198
+ @ LogMessages (messages = {
199
+ @ LogMessage (messageTemplate = IoLogMessageConstant .SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY )})
200
+ public void copyPagesWithWidgetAnnotGoToActionNamedDestTest () throws IOException , InterruptedException {
201
+ String srcFilePath = SOURCE_FOLDER + "pageToCopyWithWidgetAnnotGoToActionNamedDest.pdf" ;
202
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithWidgetAnnotGoToActionNamedDest.pdf" ;
203
+ String outFilePath = DESTINATION_FOLDER + "copyPagesWithWidgetAnnotGoToActionNamedDest.pdf" ;
204
+
205
+ copyPages (srcFilePath , outFilePath , cmpFilePath );
206
+ }
207
+
208
+ @ Test
209
+ // TODO: DEVSIX-6090 (update cmp file after fixing the issue)
210
+ public void copyPagesWithScreenAnnotGoToActionExplicitDestTest () throws IOException , InterruptedException {
211
+ String srcFilePath = SOURCE_FOLDER + "pageToCopyWithScreenAnnotGoToActionExplicitDest.pdf" ;
212
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithScreenAnnotGoToActionExplicitDest.pdf" ;
213
+ String outFilePath = DESTINATION_FOLDER + "copyPagesWithScreenAnnotGoToActionExplicitDest.pdf" ;
214
+
215
+ copyPages (srcFilePath , outFilePath , cmpFilePath );
179
216
}
180
217
181
218
private void copyLinksGoToActionTest (String dest , boolean isTheSameLinks , boolean diffDisplayOptions )
@@ -190,6 +227,22 @@ private void copyLinksGoToActionTest(String dest, boolean isTheSameLinks, boolea
190
227
destDoc .close ();
191
228
}
192
229
230
+ private void copyPages (String sourceFile , String outFilePath , String cmpFilePath )
231
+ throws IOException , InterruptedException {
232
+ try (PdfWriter writer = new PdfWriter (outFilePath );
233
+ PdfDocument pdfDoc = new PdfDocument (writer )) {
234
+ pdfDoc .addNewPage ();
235
+ pdfDoc .addNewPage ();
236
+
237
+ try (PdfReader reader = new PdfReader (sourceFile );
238
+ PdfDocument srcDoc = new PdfDocument (reader )) {
239
+ srcDoc .copyPagesTo (1 , srcDoc .getNumberOfPages (), pdfDoc );
240
+ }
241
+ }
242
+
243
+ Assert .assertNull (new CompareTool ().compareByContent (outFilePath , cmpFilePath , DESTINATION_FOLDER ));
244
+ }
245
+
193
246
private ByteArrayOutputStream createPdfWithGoToAnnot (boolean isTheSameLink , boolean diffDisplayOptions ) {
194
247
ByteArrayOutputStream stream = new ByteArrayOutputStream ();
195
248
PdfDocument pdfDocument = new PdfDocument (new PdfWriter (stream ));
0 commit comments