@@ -47,6 +47,7 @@ This file is part of the iText (R) project.
47
47
import com .itextpdf .io .image .ImageData ;
48
48
import com .itextpdf .io .image .ImageDataFactory ;
49
49
import com .itextpdf .io .source .ByteArrayOutputStream ;
50
+ import com .itextpdf .io .util .MessageFormatUtil ;
50
51
import com .itextpdf .io .util .StreamUtil ;
51
52
import com .itextpdf .io .util .UrlUtil ;
52
53
import com .itextpdf .kernel .PdfException ;
@@ -67,23 +68,24 @@ This file is part of the iText (R) project.
67
68
import com .itextpdf .kernel .pdf .colorspace .PdfDeviceCs ;
68
69
import com .itextpdf .kernel .pdf .colorspace .PdfSpecialCs ;
69
70
import com .itextpdf .kernel .pdf .extgstate .PdfExtGState ;
71
+ import com .itextpdf .kernel .pdf .xobject .PdfImageXObject ;
70
72
import com .itextpdf .kernel .utils .CompareTool ;
71
73
import com .itextpdf .test .ExtendedITextTest ;
72
74
import com .itextpdf .test .annotations .LogMessage ;
73
75
import com .itextpdf .test .annotations .LogMessages ;
74
76
import com .itextpdf .test .annotations .type .IntegrationTest ;
75
77
import org .junit .Assert ;
76
78
import org .junit .BeforeClass ;
79
+ import org .junit .Ignore ;
77
80
import org .junit .Test ;
78
81
import org .junit .experimental .categories .Category ;
79
82
80
- import java .awt .* ;
83
+ import java .awt .Toolkit ;
81
84
import java .io .ByteArrayInputStream ;
82
85
import java .io .FileInputStream ;
83
86
import java .io .IOException ;
84
87
import java .io .InputStream ;
85
88
import java .nio .charset .StandardCharsets ;
86
- import com .itextpdf .io .util .MessageFormatUtil ;
87
89
import java .util .ArrayList ;
88
90
import java .util .HashMap ;
89
91
import java .util .List ;
@@ -603,6 +605,56 @@ public void create1000PagesDocumentWithFullCompression() throws IOException {
603
605
canvas .rectangle (100 , 500 , 100 , 100 ).fill ();
604
606
canvas .release ();
605
607
page .flush ();
608
+
609
+ }
610
+ pdfDoc .close ();
611
+
612
+ PdfReader reader = new PdfReader (filename );
613
+ PdfDocument pdfDocument = new PdfDocument (reader );
614
+ Assert .assertEquals ("Rebuilt" , false , reader .hasRebuiltXref ());
615
+ PdfDictionary info = pdfDocument .getDocumentInfo ().getPdfObject ();
616
+ Assert .assertEquals ("Author" , author , info .get (PdfName .Author ).toString ());
617
+ Assert .assertEquals ("Creator" , creator , info .get (PdfName .Creator ).toString ());
618
+ Assert .assertEquals ("Title" , title , info .get (PdfName .Title ).toString ());
619
+ Assert .assertEquals ("Page count" , pageCount , pdfDocument .getNumberOfPages ());
620
+ for (int i = 1 ; i <= pageCount ; i ++) {
621
+ PdfDictionary page = pdfDocument .getPage (i ).getPdfObject ();
622
+ Assert .assertEquals (PdfName .Page , page .get (PdfName .Type ));
623
+ }
624
+ pdfDocument .close ();
625
+ }
626
+
627
+ @ Test (timeout = 0 )
628
+ @ Ignore ("Too big result file. This test is for manual testing. -Xmx6g shall be set." )
629
+ public void hugeDocumentWithFullCompression () throws IOException {
630
+ int pageCount = 800 ;
631
+ String filename = destinationFolder + "hugeDocumentWithFullCompression.pdf" ;
632
+
633
+ final String author = "Alexander Chingarev" ;
634
+ final String creator = "iText 6" ;
635
+ final String title = "Empty iText 6 Document" ;
636
+
637
+ PdfWriter writer = new PdfWriter (filename , new WriterProperties ().setFullCompressionMode (true ));
638
+ PdfDocument pdfDoc = new PdfDocument (writer );
639
+ pdfDoc .getDocumentInfo ().setAuthor (author ).
640
+ setCreator (creator ).
641
+ setTitle (title );
642
+ for (int i = 0 ; i < pageCount ; i ++) {
643
+ PdfPage page = pdfDoc .addNewPage ();
644
+ PdfCanvas canvas = new PdfCanvas (page );
645
+ canvas
646
+ .saveState ()
647
+ .beginText ()
648
+ .moveText (36 , 700 )
649
+ .setFontAndSize (PdfFontFactory .createFont (StandardFonts .HELVETICA ), 72 )
650
+ .showText (Integer .toString (i + 1 ))
651
+ .endText ()
652
+ .restoreState ();
653
+ PdfImageXObject xObject = new PdfImageXObject (ImageDataFactory .create (sourceFolder + "Willaerts_Adam_The_Embarkation_of_the_Elector_Palantine_Oil_Canvas-huge.jpg" ));
654
+ canvas .addXObject (xObject , 100 , 500 , 400 );
655
+ canvas .release ();
656
+ page .flush ();
657
+
606
658
}
607
659
pdfDoc .close ();
608
660
@@ -621,6 +673,49 @@ public void create1000PagesDocumentWithFullCompression() throws IOException {
621
673
pdfDocument .close ();
622
674
}
623
675
676
+ @ Test
677
+ public void smallDocumentWithFullCompression () throws IOException {
678
+ String filename = destinationFolder + "smallDocumentWithFullCompression.pdf" ;
679
+
680
+ final String author = "Alexander Chingarev" ;
681
+ final String creator = "iText 6" ;
682
+ final String title = "Empty iText 6 Document" ;
683
+
684
+ PdfWriter writer = new PdfWriter (filename , new WriterProperties ().setFullCompressionMode (true ));
685
+ PdfDocument pdfDoc = new PdfDocument (writer );
686
+ pdfDoc .getDocumentInfo ().setAuthor (author ).
687
+ setCreator (creator ).
688
+ setTitle (title );
689
+
690
+ PdfPage page = pdfDoc .addNewPage ();
691
+ PdfCanvas canvas = new PdfCanvas (page );
692
+ canvas
693
+ .saveState ()
694
+ .beginText ()
695
+ .moveText (36 , 700 )
696
+ .setFontAndSize (PdfFontFactory .createFont (StandardFonts .HELVETICA ), 72 )
697
+ .showText ("Hi!" )
698
+ .endText ()
699
+ .restoreState ();
700
+ page .flush ();
701
+
702
+ pdfDoc .close ();
703
+
704
+ PdfReader reader = new PdfReader (filename );
705
+ PdfDocument pdfDocument = new PdfDocument (reader );
706
+ Assert .assertEquals ("Rebuilt" , false , reader .hasRebuiltXref ());
707
+ PdfDictionary info = pdfDocument .getDocumentInfo ().getPdfObject ();
708
+ Assert .assertEquals ("Author" , author , info .get (PdfName .Author ).toString ());
709
+ Assert .assertEquals ("Creator" , creator , info .get (PdfName .Creator ).toString ());
710
+ Assert .assertEquals ("Title" , title , info .get (PdfName .Title ).toString ());
711
+ Assert .assertEquals ("Page count" , 1 , pdfDocument .getNumberOfPages ());
712
+
713
+ page = pdfDocument .getPage (1 );
714
+ Assert .assertEquals (PdfName .Page , page .getPdfObject ().get (PdfName .Type ));
715
+
716
+ pdfDocument .close ();
717
+ }
718
+
624
719
@ Test
625
720
public void create100PagesDocumentWithFullCompression () throws IOException {
626
721
int pageCount = 100 ;
@@ -760,7 +855,7 @@ public void create10PagesDocumentWithFullCompression() throws IOException {
760
855
}
761
856
762
857
@ Test
763
- public void copyPagesTest1 () throws IOException , InterruptedException {
858
+ public void copyPagesTest1 () throws IOException , InterruptedException {
764
859
String file1 = destinationFolder + "copyPages1_1.pdf" ;
765
860
String file2 = destinationFolder + "copyPages1_2.pdf" ;
766
861
@@ -807,7 +902,7 @@ public void copyPagesTest1() throws IOException, InterruptedException {
807
902
}
808
903
809
904
@ Test
810
- public void copyPagesTest2 () throws IOException , InterruptedException {
905
+ public void copyPagesTest2 () throws IOException {
811
906
String file1 = destinationFolder + "copyPages2_1.pdf" ;
812
907
String file2 = destinationFolder + "copyPages2_2.pdf" ;
813
908
@@ -861,7 +956,7 @@ public void copyPagesTest2() throws IOException, InterruptedException {
861
956
}
862
957
863
958
@ Test
864
- public void copyPagesTest3 () throws IOException , InterruptedException {
959
+ public void copyPagesTest3 () throws IOException {
865
960
String file1 = destinationFolder + "copyPages3_1.pdf" ;
866
961
String file2 = destinationFolder + "copyPages3_2.pdf" ;
867
962
@@ -913,7 +1008,7 @@ public void copyPagesTest3() throws IOException, InterruptedException {
913
1008
}
914
1009
915
1010
@ Test
916
- public void copyPagesTest4 () throws IOException , InterruptedException {
1011
+ public void copyPagesTest4 () throws IOException {
917
1012
String file1 = destinationFolder + "copyPages4_1.pdf" ;
918
1013
PdfDocument pdfDoc1 = new PdfDocument (new PdfWriter (file1 ));
919
1014
@@ -961,7 +1056,7 @@ public void copyPagesTest4() throws IOException, InterruptedException {
961
1056
962
1057
963
1058
@ Test
964
- public void copyPagesTest5 () throws IOException , InterruptedException {
1059
+ public void copyPagesTest5 () throws IOException {
965
1060
966
1061
int documentCount = 3 ;
967
1062
@@ -1013,7 +1108,7 @@ public void copyPagesTest5() throws IOException, InterruptedException {
1013
1108
}
1014
1109
1015
1110
@ Test
1016
- public void copyPagesTest6 () throws IOException , InterruptedException {
1111
+ public void copyPagesTest6 () throws IOException {
1017
1112
String file1 = destinationFolder + "copyPages6_1.pdf" ;
1018
1113
String file2 = destinationFolder + "copyPages6_2.pdf" ;
1019
1114
String file3 = destinationFolder + "copyPages6_3.pdf" ;
@@ -1083,7 +1178,7 @@ public void copyPagesTest6() throws IOException, InterruptedException {
1083
1178
}
1084
1179
1085
1180
@ Test
1086
- public void markedContentTest1 () throws Exception {
1181
+ public void markedContentTest1 () {
1087
1182
String message = "" ;
1088
1183
PdfDocument document = new PdfDocument (new PdfWriter (new ByteArrayOutputStream ()));
1089
1184
PdfPage page = document .addNewPage ();
@@ -1124,7 +1219,7 @@ public void markedContentTest2() throws Exception {
1124
1219
}
1125
1220
1126
1221
@ Test
1127
- public void graphicsStateTest1 () throws Exception {
1222
+ public void graphicsStateTest1 () {
1128
1223
PdfDocument document = new PdfDocument (new PdfWriter (new ByteArrayOutputStream ()));
1129
1224
PdfPage page = document .addNewPage ();
1130
1225
PdfCanvas canvas = new PdfCanvas (page );
@@ -1475,7 +1570,7 @@ public void gifImageTest03() throws IOException, InterruptedException {
1475
1570
}
1476
1571
1477
1572
@ Test
1478
- public void gifImageTest04 () throws IOException , InterruptedException {
1573
+ public void gifImageTest04 () throws IOException {
1479
1574
PdfDocument document = new PdfDocument (new PdfWriter (destinationFolder + "gifImageTest04.pdf" ));
1480
1575
PdfPage page = document .addNewPage ();
1481
1576
0 commit comments