@@ -44,11 +44,14 @@ This file is part of the iText (R) project.
44
44
45
45
import com .itextpdf .forms .PdfAcroForm ;
46
46
import com .itextpdf .io .image .ImageDataFactory ;
47
+ import com .itextpdf .io .util .MessageFormatUtil ;
48
+ import com .itextpdf .kernel .colors .ColorConstants ;
47
49
import com .itextpdf .kernel .geom .Rectangle ;
48
50
import com .itextpdf .kernel .pdf .PdfDocument ;
49
51
import com .itextpdf .kernel .pdf .PdfName ;
50
52
import com .itextpdf .kernel .pdf .PdfReader ;
51
53
import com .itextpdf .kernel .pdf .PdfStream ;
54
+ import com .itextpdf .kernel .utils .CompareTool ;
52
55
import com .itextpdf .signatures .BouncyCastleDigest ;
53
56
import com .itextpdf .signatures .DigestAlgorithms ;
54
57
import com .itextpdf .signatures .IExternalSignature ;
@@ -75,7 +78,6 @@ This file is part of the iText (R) project.
75
78
import java .security .UnrecoverableKeyException ;
76
79
import java .security .cert .Certificate ;
77
80
import java .security .cert .CertificateException ;
78
- import com .itextpdf .io .util .MessageFormatUtil ;
79
81
80
82
@ Category (IntegrationTest .class )
81
83
public class PdfSignatureAppearanceTest extends ExtendedITextTest {
@@ -203,5 +205,28 @@ private static void assertAppearanceFontSize(String filename, float expectedFont
203
205
Assert .assertTrue (MessageFormatUtil .format ("Font size: exptected {0}, found {1}" , expectedFontSize , fontSize ), Math .abs (foundFontSize - expectedFontSize ) < 0.1 * expectedFontSize );
204
206
}
205
207
208
+ @ Test
209
+ public void fontColorTest01 () throws GeneralSecurityException , IOException , InterruptedException {
210
+ String fileName = "fontColorTest01.pdf" ;
211
+ String dest = destinationFolder + fileName ;
212
+
213
+ Rectangle rect = new Rectangle (36 , 648 , 100 , 50 );
214
+ String src = sourceFolder + "simpleDocument.pdf" ;
215
+
216
+ PdfSigner signer = new PdfSigner (new PdfReader (src ), new FileOutputStream (dest ), false );
217
+ // Creating the appearance
218
+ signer .getSignatureAppearance ()
219
+ .setLayer2FontColor (ColorConstants .RED )
220
+ .setLayer2Text ("Verified and signed by me." )
221
+ .setPageRect (rect );
222
+
223
+ signer .setFieldName ("Signature1" );
224
+ // Creating the signature
225
+ IExternalSignature pks = new PrivateKeySignature (pk , DigestAlgorithms .SHA256 , BouncyCastleProvider .PROVIDER_NAME );
226
+ signer .signDetached (new BouncyCastleDigest (), pks , chain , null , null , null , 0 , PdfSigner .CryptoStandard .CADES );
227
+
228
+ Assert .assertNull (new CompareTool ().compareVisually (dest , sourceFolder + "cmp_" + fileName , destinationFolder ,
229
+ "diff_" ));
230
+ }
206
231
207
232
}
0 commit comments