@@ -65,6 +65,7 @@ This file is part of the iText (R) project.
65
65
import com .itextpdf .kernel .pdf .ReaderProperties ;
66
66
import com .itextpdf .kernel .pdf .annot .PdfAnnotation ;
67
67
import com .itextpdf .kernel .pdf .annot .PdfLinkAnnotation ;
68
+ import com .itextpdf .kernel .pdf .canvas .PdfCanvas ;
68
69
import com .itextpdf .kernel .xmp .PdfConst ;
69
70
import com .itextpdf .kernel .xmp .XMPConst ;
70
71
import com .itextpdf .kernel .xmp .XMPException ;
@@ -852,7 +853,7 @@ private String listDiffPagesAsString(List<Integer> diffPages) {
852
853
}
853
854
}
854
855
sb .append ("]" );
855
- return diffPages .toString ();
856
+ return sb .toString ();
856
857
}
857
858
858
859
private void createIgnoredAreasPdfs (String outPath , Map <Integer , List <Rectangle >> ignoredAreas ) throws IOException {
@@ -867,28 +868,17 @@ private void createIgnoredAreasPdfs(String outPath, Map<Integer, List<Rectangle>
867
868
List <Rectangle > rectangles = entry .getValue ();
868
869
869
870
if (rectangles != null && !rectangles .isEmpty ()) {
870
- //drawing rectangles manually, because we don't want to create dependency on itextpdf.canvas module for itextpdf.kernel
871
- PdfStream outStream = getPageContentStream (pdfOutDoc .getPage (pageNumber ));
872
- PdfStream cmpStream = getPageContentStream (pdfCmpDoc .getPage (pageNumber ));
873
-
874
- outStream .getOutputStream ().writeBytes (ByteUtils .getIsoBytes ("q\n " ));
875
- outStream .getOutputStream ().writeFloats (new float []{0.0f , 0.0f , 0.0f }).writeSpace ().writeBytes (ByteUtils .getIsoBytes ("rg\n " ));
876
- cmpStream .getOutputStream ().writeBytes (ByteUtils .getIsoBytes ("q\n " ));
877
- cmpStream .getOutputStream ().writeFloats (new float []{0.0f , 0.0f , 0.0f }).writeSpace ().writeBytes (ByteUtils .getIsoBytes ("rg\n " ));
871
+ PdfCanvas outCanvas = new PdfCanvas (pdfOutDoc .getPage (pageNumber ));
872
+ PdfCanvas cmpCanvas = new PdfCanvas (pdfCmpDoc .getPage (pageNumber ));
878
873
874
+ outCanvas .saveState ();
875
+ cmpCanvas .saveState ();
879
876
for (Rectangle rect : rectangles ) {
880
- outStream .getOutputStream ().writeFloats (new float []{rect .getX (), rect .getY (), rect .getWidth (), rect .getHeight ()}).
881
- writeSpace ().
882
- writeBytes (ByteUtils .getIsoBytes ("re\n " )).
883
- writeBytes (ByteUtils .getIsoBytes ("f\n " ));
884
-
885
- cmpStream .getOutputStream ().writeFloats (new float []{rect .getX (), rect .getY (), rect .getWidth (), rect .getHeight ()}).
886
- writeSpace ().
887
- writeBytes (ByteUtils .getIsoBytes ("re\n " )).
888
- writeBytes (ByteUtils .getIsoBytes ("f\n " ));
877
+ outCanvas .rectangle (rect ).fill ();
878
+ cmpCanvas .rectangle (rect ).fill ();
889
879
}
890
- outStream . getOutputStream (). writeBytes ( ByteUtils . getIsoBytes ( "Q \n " ) );
891
- cmpStream . getOutputStream (). writeBytes ( ByteUtils . getIsoBytes ( "Q \n " ) );
880
+ outCanvas . restoreState ( );
881
+ cmpCanvas . restoreState ( );
892
882
}
893
883
}
894
884
@@ -898,11 +888,6 @@ private void createIgnoredAreasPdfs(String outPath, Map<Integer, List<Rectangle>
898
888
init (outPath + ignoredAreasPrefix + outPdfName , outPath + ignoredAreasPrefix + cmpPdfName );
899
889
}
900
890
901
- private PdfStream getPageContentStream (PdfPage page ) {
902
- PdfStream stream = page .getContentStream (page .getContentStreamCount () - 1 );
903
- return stream .getOutputStream () == null ? page .newContentStreamAfter () : stream ;
904
- }
905
-
906
891
private void prepareOutputDirs (String outPath , String differenceImagePrefix ) {
907
892
File [] imageFiles ;
908
893
File [] cmpImageFiles ;
0 commit comments