@@ -41,11 +41,13 @@ source product.
41
41
42
42
*/
43
43
using System ;
44
+ using System . IO ;
44
45
using iText . Forms . Fields ;
45
46
using iText . Kernel . Colors ;
46
47
using iText . Kernel . Pdf ;
47
48
using iText . Kernel . Utils ;
48
49
using iText . Test ;
50
+ using iText . Test . Attributes ;
49
51
50
52
namespace iText . Forms {
51
53
public class FormFieldFlatteningTest : ExtendedITextTest {
@@ -209,5 +211,30 @@ private static void FillTextFieldsThenFlattenThenCompare(String testName) {
209
211
doc . Close ( ) ;
210
212
NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( dest , cmp , destinationFolder , "diff_" ) ) ;
211
213
}
214
+
215
+ /// <exception cref="System.IO.IOException"/>
216
+ [ NUnit . Framework . Test ]
217
+ [ LogMessage ( iText . IO . LogMessageConstant . DOCUMENT_ALREADY_HAS_FIELD , Count = 3 ) ]
218
+ public virtual void FlattenReadOnly ( ) {
219
+ //Logging is expected since there are duplicate field names
220
+ //isReadOnly should be true after DEVSIX-2156
221
+ PdfWriter writer = new PdfWriter ( new MemoryStream ( ) ) ;
222
+ PdfDocument pdfDoc = new PdfDocument ( writer ) ;
223
+ PdfReader reader = new PdfReader ( sourceFolder + "readOnlyForm.pdf" ) ;
224
+ PdfDocument pdfInnerDoc = new PdfDocument ( reader ) ;
225
+ pdfInnerDoc . CopyPagesTo ( 1 , pdfInnerDoc . GetNumberOfPages ( ) , pdfDoc , new PdfPageFormCopier ( ) ) ;
226
+ pdfInnerDoc . Close ( ) ;
227
+ reader = new PdfReader ( sourceFolder + "readOnlyForm.pdf" ) ;
228
+ pdfInnerDoc = new PdfDocument ( reader ) ;
229
+ pdfInnerDoc . CopyPagesTo ( 1 , pdfInnerDoc . GetNumberOfPages ( ) , pdfDoc , new PdfPageFormCopier ( ) ) ;
230
+ pdfInnerDoc . Close ( ) ;
231
+ PdfAcroForm form = PdfAcroForm . GetAcroForm ( pdfDoc , false ) ;
232
+ bool isReadOnly = true ;
233
+ foreach ( PdfFormField field in form . GetFormFields ( ) . Values ) {
234
+ isReadOnly = ( isReadOnly && field . IsReadOnly ( ) ) ;
235
+ }
236
+ pdfDoc . Close ( ) ;
237
+ NUnit . Framework . Assert . IsFalse ( isReadOnly ) ;
238
+ }
212
239
}
213
240
}
0 commit comments