@@ -30,25 +30,26 @@ You should have received a copy of the GNU Affero General Public License
30
30
using iText . Kernel . Pdf . Navigation ;
31
31
using iText . Kernel . Utils ;
32
32
using iText . Test ;
33
+ using iText . Test . Attributes ;
33
34
34
35
namespace iText . Kernel . Pdf . Copy {
35
36
public class PdfAnnotationCopyingTest : ExtendedITextTest {
36
- public static readonly String destinationFolder = NUnit . Framework . TestContext . CurrentContext . TestDirectory
37
+ public static readonly String DESTINATION_FOLDER = NUnit . Framework . TestContext . CurrentContext . TestDirectory
37
38
+ "/test/itext/kernel/pdf/PdfAnnotationCopyingTest/" ;
38
39
39
- public static readonly String sourceFolder = iText . Test . TestUtil . GetParentProjectDirectory ( NUnit . Framework . TestContext
40
+ public static readonly String SOURCE_FOLDER = iText . Test . TestUtil . GetParentProjectDirectory ( NUnit . Framework . TestContext
40
41
. CurrentContext . TestDirectory ) + "/resources/itext/kernel/pdf/PdfAnnotationCopyingTest/" ;
41
42
42
43
[ NUnit . Framework . OneTimeSetUp ]
43
44
public static void BeforeClass ( ) {
44
- CreateOrClearDestinationFolder ( destinationFolder ) ;
45
+ CreateOrClearDestinationFolder ( DESTINATION_FOLDER ) ;
45
46
}
46
47
47
48
[ NUnit . Framework . Test ]
48
49
[ NUnit . Framework . Ignore ( "Unignore when DEVSIX-3585 would be implemented" ) ]
49
50
public virtual void TestCopyingPageWithAnnotationContainingPopupKey ( ) {
50
- String inFilePath = sourceFolder + "annotation-with-popup.pdf" ;
51
- String outFilePath = destinationFolder + "copy-annotation-with-popup.pdf" ;
51
+ String inFilePath = SOURCE_FOLDER + "annotation-with-popup.pdf" ;
52
+ String outFilePath = DESTINATION_FOLDER + "copy-annotation-with-popup.pdf" ;
52
53
PdfDocument originalDocument = new PdfDocument ( new PdfReader ( inFilePath ) ) ;
53
54
PdfDocument outDocument = new PdfDocument ( new PdfWriter ( outFilePath ) ) ;
54
55
originalDocument . CopyPagesTo ( 1 , 1 , outDocument ) ;
@@ -88,8 +89,8 @@ public virtual void TestCopyingPageWithAnnotationContainingPopupKey() {
88
89
[ NUnit . Framework . Test ]
89
90
[ NUnit . Framework . Ignore ( "Unignore when DEVSIX-3585 would be implemented" ) ]
90
91
public virtual void TestCopyingPageWithAnnotationContainingIrtKey ( ) {
91
- String inFilePath = sourceFolder + "annotation-with-irt.pdf" ;
92
- String outFilePath = destinationFolder + "copy-annotation-with-irt.pdf" ;
92
+ String inFilePath = SOURCE_FOLDER + "annotation-with-irt.pdf" ;
93
+ String outFilePath = DESTINATION_FOLDER + "copy-annotation-with-irt.pdf" ;
93
94
PdfDocument originalDocument = new PdfDocument ( new PdfReader ( inFilePath ) ) ;
94
95
PdfDocument outDocument = new PdfDocument ( new PdfWriter ( outFilePath ) ) ;
95
96
originalDocument . CopyPagesTo ( 1 , 1 , outDocument ) ;
@@ -126,33 +127,62 @@ public virtual void TestCopyingPageWithAnnotationContainingIrtKey() {
126
127
[ NUnit . Framework . Test ]
127
128
public virtual void CopySameLinksWithGoToSmartModeTest ( ) {
128
129
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
129
- String cmpFilePath = sourceFolder + "cmp_copySameLinksWithGoToSmartMode.pdf" ;
130
- String outFilePath = destinationFolder + "copySameLinksWithGoToSmartMode.pdf" ;
130
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copySameLinksWithGoToSmartMode.pdf" ;
131
+ String outFilePath = DESTINATION_FOLDER + "copySameLinksWithGoToSmartMode.pdf" ;
131
132
CopyLinksGoToActionTest ( outFilePath , true , false ) ;
132
- NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFilePath , cmpFilePath , destinationFolder
133
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFilePath , cmpFilePath , DESTINATION_FOLDER
133
134
) ) ;
134
135
}
135
136
136
137
[ NUnit . Framework . Test ]
137
138
public virtual void CopyDiffDestLinksWithGoToSmartModeTest ( ) {
138
139
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
139
- String cmpFilePath = sourceFolder + "cmp_copyDiffDestLinksWithGoToSmartMode.pdf" ;
140
- String outFilePath = destinationFolder + "copyDiffDestLinksWithGoToSmartMode.pdf" ;
140
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyDiffDestLinksWithGoToSmartMode.pdf" ;
141
+ String outFilePath = DESTINATION_FOLDER + "copyDiffDestLinksWithGoToSmartMode.pdf" ;
141
142
CopyLinksGoToActionTest ( outFilePath , false , false ) ;
142
- NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFilePath , cmpFilePath , destinationFolder
143
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFilePath , cmpFilePath , DESTINATION_FOLDER
143
144
) ) ;
144
145
}
145
146
146
147
[ NUnit . Framework . Test ]
147
148
public virtual void CopyDiffDisplayLinksWithGoToSmartModeTest ( ) {
148
149
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
149
- String cmpFilePath = sourceFolder + "cmp_copyDiffDisplayLinksWithGoToSmartMode.pdf" ;
150
- String outFilePath = destinationFolder + "copyDiffDisplayLinksWithGoToSmartMode.pdf" ;
150
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyDiffDisplayLinksWithGoToSmartMode.pdf" ;
151
+ String outFilePath = DESTINATION_FOLDER + "copyDiffDisplayLinksWithGoToSmartMode.pdf" ;
151
152
CopyLinksGoToActionTest ( outFilePath , false , true ) ;
152
- NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFilePath , cmpFilePath , destinationFolder
153
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFilePath , cmpFilePath , DESTINATION_FOLDER
153
154
) ) ;
154
155
}
155
156
157
+ [ NUnit . Framework . Test ]
158
+ // TODO: DEVSIX-6090 (update cmp file after fixing the issue)
159
+ [ LogMessage ( iText . IO . Logs . IoLogMessageConstant . SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY ) ]
160
+ public virtual void CopyPagesWithWidgetAnnotGoToActionExplicitDestTest ( ) {
161
+ String srcFilePath = SOURCE_FOLDER + "pageToCopyWithWidgetAnnotGoToActionExplicitDest.pdf" ;
162
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithWidgetAnnotGoToActionExplicitDest.pdf" ;
163
+ String outFilePath = DESTINATION_FOLDER + "copyPagesWithWidgetAnnotGoToActionExplicitDest.pdf" ;
164
+ CopyPages ( srcFilePath , outFilePath , cmpFilePath ) ;
165
+ }
166
+
167
+ [ NUnit . Framework . Test ]
168
+ // TODO: DEVSIX-6090 (update cmp file after fixing the issue)
169
+ [ LogMessage ( iText . IO . Logs . IoLogMessageConstant . SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY ) ]
170
+ public virtual void CopyPagesWithWidgetAnnotGoToActionNamedDestTest ( ) {
171
+ String srcFilePath = SOURCE_FOLDER + "pageToCopyWithWidgetAnnotGoToActionNamedDest.pdf" ;
172
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithWidgetAnnotGoToActionNamedDest.pdf" ;
173
+ String outFilePath = DESTINATION_FOLDER + "copyPagesWithWidgetAnnotGoToActionNamedDest.pdf" ;
174
+ CopyPages ( srcFilePath , outFilePath , cmpFilePath ) ;
175
+ }
176
+
177
+ [ NUnit . Framework . Test ]
178
+ public virtual void CopyPagesWithScreenAnnotGoToActionExplicitDestTest ( ) {
179
+ // TODO: DEVSIX-6090 (update cmp file after fixing the issue)
180
+ String srcFilePath = SOURCE_FOLDER + "pageToCopyWithScreenAnnotGoToActionExplicitDest.pdf" ;
181
+ String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithScreenAnnotGoToActionExplicitDest.pdf" ;
182
+ String outFilePath = DESTINATION_FOLDER + "copyPagesWithScreenAnnotGoToActionExplicitDest.pdf" ;
183
+ CopyPages ( srcFilePath , outFilePath , cmpFilePath ) ;
184
+ }
185
+
156
186
private void CopyLinksGoToActionTest ( String dest , bool isTheSameLinks , bool diffDisplayOptions ) {
157
187
PdfDocument destDoc = new PdfDocument ( new PdfWriter ( dest ) . SetSmartMode ( true ) ) ;
158
188
MemoryStream sourceBaos1 = CreatePdfWithGoToAnnot ( isTheSameLinks , diffDisplayOptions ) ;
@@ -162,6 +192,22 @@ private void CopyLinksGoToActionTest(String dest, bool isTheSameLinks, bool diff
162
192
destDoc . Close ( ) ;
163
193
}
164
194
195
+ private void CopyPages ( String sourceFile , String outFilePath , String cmpFilePath ) {
196
+ using ( PdfWriter writer = new PdfWriter ( outFilePath ) ) {
197
+ using ( PdfDocument pdfDoc = new PdfDocument ( writer ) ) {
198
+ pdfDoc . AddNewPage ( ) ;
199
+ pdfDoc . AddNewPage ( ) ;
200
+ using ( PdfReader reader = new PdfReader ( sourceFile ) ) {
201
+ using ( PdfDocument srcDoc = new PdfDocument ( reader ) ) {
202
+ srcDoc . CopyPagesTo ( 1 , srcDoc . GetNumberOfPages ( ) , pdfDoc ) ;
203
+ }
204
+ }
205
+ }
206
+ }
207
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFilePath , cmpFilePath , DESTINATION_FOLDER
208
+ ) ) ;
209
+ }
210
+
165
211
private MemoryStream CreatePdfWithGoToAnnot ( bool isTheSameLink , bool diffDisplayOptions ) {
166
212
MemoryStream stream = new MemoryStream ( ) ;
167
213
PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( stream ) ) ;
0 commit comments