@@ -41,6 +41,7 @@ source product.
41
41
42
42
*/
43
43
using System ;
44
+ using System . Collections . Generic ;
44
45
using System . IO ;
45
46
using Org . BouncyCastle . Crypto ;
46
47
using Org . BouncyCastle . X509 ;
@@ -160,6 +161,52 @@ public virtual void TextAutoscaleTest06() {
160
161
AssertAppearanceFontSize ( dest , 6.26f ) ;
161
162
}
162
163
164
+ /// <exception cref="System.IO.IOException"/>
165
+ /// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/>
166
+ /// <exception cref="System.Exception"/>
167
+ [ NUnit . Framework . Test ]
168
+ public virtual void TestSigningInAppendModeWithHybridDocument ( ) {
169
+ String src = sourceFolder + "hybrid.pdf" ;
170
+ String dest = destinationFolder + "signed_hybrid.pdf" ;
171
+ String cmp = sourceFolder + "cmp_signed_hybrid.pdf" ;
172
+ PdfSigner signer = new PdfSigner ( new PdfReader ( src ) , new FileStream ( dest , FileMode . Create ) , new StampingProperties
173
+ ( ) . UseAppendMode ( ) ) ;
174
+ PdfSignatureAppearance appearance = signer . GetSignatureAppearance ( ) ;
175
+ appearance . SetLayer2FontSize ( 13.8f ) . SetPageRect ( new Rectangle ( 36 , 748 , 200 , 100 ) ) . SetPageNumber ( 1 ) . SetReason
176
+ ( "Test" ) . SetLocation ( "Nagpur" ) ;
177
+ signer . SetFieldName ( "Sign1" ) ;
178
+ signer . SetCertificationLevel ( PdfSigner . NOT_CERTIFIED ) ;
179
+ IExternalSignature pks = new PrivateKeySignature ( pk , DigestAlgorithms . SHA256 ) ;
180
+ signer . SignDetached ( pks , chain , null , null , null , 0 , PdfSigner . CryptoStandard . CADES ) ;
181
+ // Make sure iText can open the document
182
+ new PdfDocument ( new PdfReader ( dest ) ) . Close ( ) ;
183
+ // Assert that the document can be rendered correctly
184
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareVisually ( dest , cmp , destinationFolder , "diff_" , GetIgnoredAreaTestMap
185
+ ( new Rectangle ( 36 , 748 , 200 , 100 ) ) ) ) ;
186
+ }
187
+
188
+ /// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/>
189
+ /// <exception cref="System.IO.IOException"/>
190
+ /// <exception cref="System.Exception"/>
191
+ [ NUnit . Framework . Test ]
192
+ public virtual void FontColorTest01 ( ) {
193
+ String fileName = "fontColorTest01.pdf" ;
194
+ String dest = destinationFolder + fileName ;
195
+ Rectangle rect = new Rectangle ( 36 , 648 , 100 , 50 ) ;
196
+ String src = sourceFolder + "simpleDocument.pdf" ;
197
+ PdfSigner signer = new PdfSigner ( new PdfReader ( src ) , new FileStream ( dest , FileMode . Create ) , new StampingProperties
198
+ ( ) ) ;
199
+ // Creating the appearance
200
+ signer . GetSignatureAppearance ( ) . SetLayer2FontColor ( ColorConstants . RED ) . SetLayer2Text ( "Verified and signed by me."
201
+ ) . SetPageRect ( rect ) ;
202
+ signer . SetFieldName ( "Signature1" ) ;
203
+ // Creating the signature
204
+ IExternalSignature pks = new PrivateKeySignature ( pk , DigestAlgorithms . SHA256 ) ;
205
+ signer . SignDetached ( pks , chain , null , null , null , 0 , PdfSigner . CryptoStandard . CADES ) ;
206
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareVisually ( dest , sourceFolder + "cmp_" + fileName , destinationFolder
207
+ , "diff_" ) ) ;
208
+ }
209
+
163
210
/// <exception cref="System.IO.IOException"/>
164
211
/// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/>
165
212
private void TestSignatureAppearanceAutoscale ( String dest , Rectangle rect , PdfSignatureAppearance . RenderingMode
@@ -198,26 +245,10 @@ private static void AssertAppearanceFontSize(String filename, float expectedFont
198
245
. Format ( "Font size: exptected {0}, found {1}" , expectedFontSize , fontSize ) ) ;
199
246
}
200
247
201
- /// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/>
202
- /// <exception cref="System.IO.IOException"/>
203
- /// <exception cref="System.Exception"/>
204
- [ NUnit . Framework . Test ]
205
- public virtual void FontColorTest01 ( ) {
206
- String fileName = "fontColorTest01.pdf" ;
207
- String dest = destinationFolder + fileName ;
208
- Rectangle rect = new Rectangle ( 36 , 648 , 100 , 50 ) ;
209
- String src = sourceFolder + "simpleDocument.pdf" ;
210
- PdfSigner signer = new PdfSigner ( new PdfReader ( src ) , new FileStream ( dest , FileMode . Create ) , new StampingProperties
211
- ( ) ) ;
212
- // Creating the appearance
213
- signer . GetSignatureAppearance ( ) . SetLayer2FontColor ( ColorConstants . RED ) . SetLayer2Text ( "Verified and signed by me."
214
- ) . SetPageRect ( rect ) ;
215
- signer . SetFieldName ( "Signature1" ) ;
216
- // Creating the signature
217
- IExternalSignature pks = new PrivateKeySignature ( pk , DigestAlgorithms . SHA256 ) ;
218
- signer . SignDetached ( pks , chain , null , null , null , 0 , PdfSigner . CryptoStandard . CADES ) ;
219
- NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareVisually ( dest , sourceFolder + "cmp_" + fileName , destinationFolder
220
- , "diff_" ) ) ;
248
+ private static IDictionary < int , IList < Rectangle > > GetIgnoredAreaTestMap ( Rectangle ignoredArea ) {
249
+ IDictionary < int , IList < Rectangle > > result = new Dictionary < int , IList < Rectangle > > ( ) ;
250
+ result . Put ( 1 , JavaUtil . ArraysAsList ( ignoredArea ) ) ;
251
+ return result ;
221
252
}
222
253
}
223
254
}
0 commit comments