@@ -44,10 +44,18 @@ This file is part of the iText (R) project.
44
44
45
45
import com .itextpdf .io .source .ByteUtils ;
46
46
import com .itextpdf .io .util .DateTimeUtil ;
47
+ import com .itextpdf .kernel .events .Event ;
48
+ import com .itextpdf .kernel .events .IEventHandler ;
49
+ import com .itextpdf .kernel .events .PdfDocumentEvent ;
50
+ import com .itextpdf .kernel .font .PdfFontFactory ;
51
+ import com .itextpdf .kernel .geom .Rectangle ;
52
+ import com .itextpdf .kernel .pdf .canvas .PdfCanvas ;
53
+ import com .itextpdf .kernel .utils .CompareTool ;
47
54
import com .itextpdf .kernel .xmp .XMPException ;
48
55
import com .itextpdf .kernel .xmp .XMPMetaFactory ;
49
56
import com .itextpdf .test .ExtendedITextTest ;
50
57
import com .itextpdf .test .annotations .type .IntegrationTest ;
58
+ import org .junit .Assert ;
51
59
import org .junit .BeforeClass ;
52
60
import org .junit .Ignore ;
53
61
import org .junit .Test ;
@@ -673,7 +681,7 @@ public void stampingStreamsCompression01() throws IOException {
673
681
674
682
assertEquals (5731884 , lengthBefore );
675
683
float expected = 5731884 ;
676
- float coef = Math .abs ((expected - lengthAfter )/ expected );
684
+ float coef = Math .abs ((expected - lengthAfter ) / expected );
677
685
assertTrue (coef < 0.01 );
678
686
}
679
687
@@ -698,7 +706,7 @@ public void stampingStreamsCompression02() throws IOException {
698
706
699
707
assertEquals (5731884 , lengthBefore );
700
708
float expected = 11321910 ;
701
- float coef = Math .abs ((expected - lengthAfter )/ expected );
709
+ float coef = Math .abs ((expected - lengthAfter ) / expected );
702
710
assertTrue (coef < 0.01 );
703
711
}
704
712
@@ -721,7 +729,7 @@ public void stampingStreamsCompression03() throws IOException {
721
729
722
730
assertEquals (5731884 , lengthBefore );
723
731
float expected = 5729270 ;
724
- float coef = Math .abs ((expected - lengthAfter )/ expected );
732
+ float coef = Math .abs ((expected - lengthAfter ) / expected );
725
733
assertTrue (coef < 0.01 );
726
734
}
727
735
@@ -796,7 +804,7 @@ public void stampingXmp2() throws IOException, XMPException {
796
804
for (int i = 0 ; i < pdfDoc3 .getNumberOfPages (); i ++) {
797
805
pdfDoc3 .getPage (i + 1 );
798
806
}
799
- assertNotNull ("XmpMetadata not found" , XMPMetaFactory .parseFromBuffer (pdfDoc3 .getXmpMetadata ()));
807
+ assertNotNull ("XmpMetadata not found" , XMPMetaFactory .parseFromBuffer (pdfDoc3 .getXmpMetadata ()));
800
808
assertEquals ("Number of pages" , pageCount , pdfDoc3 .getNumberOfPages ());
801
809
assertEquals ("Rebuilt" , false , reader3 .hasRebuiltXref ());
802
810
assertEquals ("Fixed" , false , reader3 .hasFixedXref ());
@@ -1250,19 +1258,19 @@ public void stampingTestWithFullCompression01() throws IOException, InterruptedE
1250
1258
pdfDoc .close ();
1251
1259
float result = new File (destinationFolder + "stampingTestWithFullCompression01.pdf" ).length ();
1252
1260
float expected = new File (sourceFolder + "cmp_stampingTestWithFullCompression01.pdf" ).length ();
1253
- float coef = Math .abs ((expected - result )/ expected );
1261
+ float coef = Math .abs ((expected - result ) / expected );
1254
1262
assertTrue (coef < 0.01 );
1255
1263
}
1256
1264
1257
1265
@ Test
1258
1266
public void stampingTestWithFullCompression02 () throws IOException , InterruptedException {
1259
1267
PdfDocument pdfDoc = new PdfDocument (new PdfReader (sourceFolder + "fullCompressedDocument.pdf" ),
1260
1268
new PdfWriter (destinationFolder + "stampingTestWithFullCompression02.pdf" ,
1261
- new WriterProperties ().setFullCompressionMode (false )));
1269
+ new WriterProperties ().setFullCompressionMode (false )));
1262
1270
pdfDoc .close ();
1263
1271
float result = new File (destinationFolder + "stampingTestWithFullCompression02.pdf" ).length ();
1264
1272
float expected = new File (sourceFolder + "cmp_stampingTestWithFullCompression02.pdf" ).length ();
1265
- float coef = Math .abs ((expected - result )/ expected );
1273
+ float coef = Math .abs ((expected - result ) / expected );
1266
1274
assertTrue (coef < 0.01 );
1267
1275
}
1268
1276
@@ -1284,4 +1292,42 @@ static void verifyPdfPagesCount(PdfObject root) {
1284
1292
verifyPdfPagesCount (kids );
1285
1293
}
1286
1294
}
1295
+
1296
+ @ Test
1297
+ //TODO: DEVSIX-2007
1298
+ public void stampingStreamNoEndingWhitespace01 () throws IOException , InterruptedException {
1299
+ System .out .println (destinationFolder );
1300
+ PdfDocument pdfDoc = new PdfDocument (new PdfReader (sourceFolder + "stampingStreamNoEndingWhitespace01.pdf" ),
1301
+ new PdfWriter (destinationFolder + "stampingStreamNoEndingWhitespace01.pdf" ,
1302
+ new WriterProperties ().setCompressionLevel (0 )));
1303
+
1304
+ PdfDocument pdfDocInput = new PdfDocument (new PdfReader (sourceFolder + "stampingStreamNoEndingWhitespace01.pdf" ));
1305
+ PdfDocument pdfDocOutput = new PdfDocument (new PdfWriter (destinationFolder + "stampingStreamNoEndingWhitespace01.pdf" , new WriterProperties ().setCompressionLevel (0 )));
1306
+
1307
+ class WatermarkEventHandler implements IEventHandler {
1308
+
1309
+ @ Override
1310
+ public void handleEvent (Event event ) {
1311
+ PdfDocumentEvent pdfEvent = (PdfDocumentEvent ) event ;
1312
+ PdfPage page = pdfEvent .getPage ();
1313
+ PdfCanvas pdfCanvas = new PdfCanvas (page );
1314
+ try {
1315
+ pdfCanvas .beginText ()
1316
+ .setFontAndSize (PdfFontFactory .createFont (), 12.0f )
1317
+ .showText ("Text" )
1318
+ .endText ();
1319
+ } catch (IOException e ) {
1320
+ }
1321
+ }
1322
+ }
1323
+ ;
1324
+ pdfDocOutput .addEventHandler (PdfDocumentEvent .END_PAGE , new WatermarkEventHandler ());
1325
+
1326
+ pdfDocInput .copyPagesTo (1 , pdfDocInput .getNumberOfPages (), pdfDocOutput );
1327
+
1328
+ pdfDocInput .close ();
1329
+ pdfDocOutput .close ();
1330
+
1331
+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + "stampingStreamNoEndingWhitespace01.pdf" , sourceFolder + "cmp_stampingStreamNoEndingWhitespace01.pdf" , destinationFolder , "diff_" ));
1332
+ }
1287
1333
}
0 commit comments