@@ -41,11 +41,13 @@ source product.
41414242*/
4343using System ;
44+ using System . IO ;
4445using iText . Forms . Fields ;
4546using iText . Kernel . Colors ;
4647using iText . Kernel . Pdf ;
4748using iText . Kernel . Utils ;
4849using iText . Test ;
50+ using iText . Test . Attributes ;
4951
5052namespace iText . Forms {
5153 public class FormFieldFlatteningTest : ExtendedITextTest {
@@ -209,5 +211,30 @@ private static void FillTextFieldsThenFlattenThenCompare(String testName) {
209211 doc . Close ( ) ;
210212 NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( dest , cmp , destinationFolder , "diff_" ) ) ;
211213 }
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+ }
212239 }
213240}
0 commit comments