From 6657f16b688673c7557f3a87ee80d4def2bf7ae1 Mon Sep 17 00:00:00 2001 From: Alexander Pliushchou Date: Wed, 31 Jan 2024 23:16:54 +0000 Subject: [PATCH 1/2] Fix D dictionary copying DEVSIX-6332 Autoported commit. Original commit hash: [abe3f098b] --- .../kernel/pdf/OcgPropertiesCopierTest.cs | 29 +++--- .../itext/kernel/pdf/PdfCopyTest.cs | 13 +++ .../itext/kernel/pdf/layer/PdfLayerTest.cs | 2 +- .../pdf/PdfCopyTest/DocWithDDictionary.pdf | Bin 0 -> 3307 bytes .../cmp_copyDocWithDDictionary.pdf | Bin 0 -> 3171 bytes .../PdfOutlineTest/cmp_outlineTypeNull.pdf | Bin 74200 -> 74322 bytes .../PdfLayerTest/cmp_output_copy_layered.pdf | Bin 0 -> 2566 bytes .../pdf/layer/PdfLayerTest/ocpConfigs.pdf | Bin 1864 -> 2052 bytes .../cmp_MergeWithSameNamedOCG.pdf | Bin 2354 -> 2567 bytes .../cmp_mergePdfWithComplexOCGTest.pdf | Bin 3544 -> 3861 bytes .../cmp_mergePdfWithComplexOCGTwiceTest.pdf | Bin 3128 -> 3485 bytes .../PdfMergerTest/cmp_mergePdfWithOCGTest.pdf | Bin 2985 -> 3206 bytes .../cmp_mergeTwoPagePdfWithComplexOCGTest.pdf | Bin 2041 -> 2262 bytes .../cmp_mergeWithSameNamedOCMD.pdf | Bin 2074355 -> 2074522 bytes .../kernel/logs/KernelLogMessageConstant.cs | 2 + .../itext/kernel/pdf/OcgPropertiesCopier.cs | 43 ++++++++- .../itext/kernel/pdf/PdfCatalog.cs | 8 +- .../itext/kernel/pdf/PdfDocument.cs | 1 + .../itext/kernel/pdf/layer/PdfOCProperties.cs | 84 +++++++++++++----- port-hash | 2 +- 20 files changed, 141 insertions(+), 43 deletions(-) create mode 100644 itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfCopyTest/DocWithDDictionary.pdf create mode 100644 itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfCopyTest/cmp_copyDocWithDDictionary.pdf create mode 100644 itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/layer/PdfLayerTest/cmp_output_copy_layered.pdf diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/OcgPropertiesCopierTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/OcgPropertiesCopierTest.cs index 470c389341..ee54bb00ba 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/OcgPropertiesCopierTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/OcgPropertiesCopierTest.cs @@ -544,8 +544,8 @@ public virtual void CopyDFieldsToEmptyDocumentTest() { NUnit.Framework.Assert.AreEqual("Off1", off.GetAsDictionary(0).GetAsString(PdfName.Name).ToUnicodeString() ); NUnit.Framework.Assert.IsNull(dDict.GetAsArray(PdfName.Creator)); - NUnit.Framework.Assert.AreEqual("OCConfigName0", dDict.GetAsString(PdfName.Name).ToUnicodeString()); - NUnit.Framework.Assert.IsNull(dDict.GetAsName(PdfName.BaseState)); + NUnit.Framework.Assert.AreEqual("Name", dDict.GetAsString(PdfName.Name).ToUnicodeString()); + NUnit.Framework.Assert.AreEqual(PdfName.ON, dDict.GetAsName(PdfName.BaseState)); PdfArray asArray = dDict.GetAsArray(PdfName.AS); NUnit.Framework.Assert.AreEqual(1, asArray.Size()); NUnit.Framework.Assert.AreEqual(1, asArray.GetAsDictionary(0).GetAsArray(PdfName.Category).Size()); @@ -553,8 +553,8 @@ public virtual void CopyDFieldsToEmptyDocumentTest() { (0)); NUnit.Framework.Assert.AreEqual("noPrint1", asArray.GetAsDictionary(0).GetAsArray(PdfName.OCGs).GetAsDictionary (0).GetAsString(PdfName.Name).ToUnicodeString()); - NUnit.Framework.Assert.IsNull(dDict.GetAsName(PdfName.Intent)); - NUnit.Framework.Assert.IsNull(dDict.GetAsName(PdfName.ListMode)); + NUnit.Framework.Assert.AreEqual(PdfName.View, dDict.GetAsName(PdfName.Intent)); + NUnit.Framework.Assert.AreEqual(PdfName.VisiblePages, dDict.GetAsName(PdfName.ListMode)); } [NUnit.Framework.Test] @@ -665,8 +665,8 @@ public virtual void CopyDFieldsToDocumentWithDDictTest() { NUnit.Framework.Assert.AreEqual("from_Off1", off.GetAsDictionary(2).GetAsString(PdfName.Name).ToUnicodeString ()); NUnit.Framework.Assert.IsNull(dDict.GetAsArray(PdfName.Creator)); - NUnit.Framework.Assert.AreEqual("OCConfigName0", dDict.GetAsString(PdfName.Name).ToUnicodeString()); - NUnit.Framework.Assert.IsNull(dDict.GetAsName(PdfName.BaseState)); + NUnit.Framework.Assert.AreEqual("Name", dDict.GetAsString(PdfName.Name).ToUnicodeString()); + NUnit.Framework.Assert.AreEqual(PdfName.ON, dDict.GetAsName(PdfName.BaseState)); PdfArray asArray = dDict.GetAsArray(PdfName.AS); NUnit.Framework.Assert.AreEqual(1, asArray.Size()); NUnit.Framework.Assert.AreEqual(1, asArray.GetAsDictionary(0).GetAsArray(PdfName.Category).Size()); @@ -677,8 +677,8 @@ public virtual void CopyDFieldsToDocumentWithDDictTest() { (0).GetAsString(PdfName.Name).ToUnicodeString()); NUnit.Framework.Assert.AreEqual("from_noPrint1", asArray.GetAsDictionary(0).GetAsArray(PdfName.OCGs).GetAsDictionary (1).GetAsString(PdfName.Name).ToUnicodeString()); - NUnit.Framework.Assert.IsNull(dDict.GetAsName(PdfName.Intent)); - NUnit.Framework.Assert.IsNull(dDict.GetAsName(PdfName.ListMode)); + NUnit.Framework.Assert.AreEqual(PdfName.View, dDict.GetAsName(PdfName.Intent)); + NUnit.Framework.Assert.AreEqual(PdfName.VisiblePages, dDict.GetAsName(PdfName.ListMode)); } // Copy OCGs from different locations (OCMDs, annotations, content streams, xObjects) test block @@ -976,12 +976,13 @@ private static byte[] GetDocumentWithAllDFields() { off2.SetOn(false); pdfResource.MakeIndirect(fromDocument); PdfOCProperties ocProperties = fromDocument.GetCatalog().GetOCProperties(true); + PdfDictionary dDictionary = ocProperties.GetPdfObject().GetAsDictionary(PdfName.D); // Creator (will be not copied) - ocProperties.GetPdfObject().Put(PdfName.Creator, new PdfString("CreatorName", PdfEncodings.UNICODE_BIG)); + dDictionary.Put(PdfName.Creator, new PdfString("CreatorName", PdfEncodings.UNICODE_BIG)); // Name (will be automatically changed) - ocProperties.GetPdfObject().Put(PdfName.Name, new PdfString("Name", PdfEncodings.UNICODE_BIG)); + dDictionary.Put(PdfName.Name, new PdfString("Name", PdfEncodings.UNICODE_BIG)); // BaseState (will be not copied) - ocProperties.GetPdfObject().Put(PdfName.BaseState, PdfName.OFF); + dDictionary.Put(PdfName.BaseState, PdfName.ON); // AS (will be automatically changed) PdfArray asArray = new PdfArray(); PdfDictionary dict = new PdfDictionary(); @@ -993,14 +994,14 @@ private static byte[] GetDocumentWithAllDFields() { ocgs.Add(locked1.GetPdfObject()); dict.Put(PdfName.OCGs, ocgs); asArray.Add(dict); - ocProperties.GetPdfObject().Put(PdfName.AS, asArray); + dDictionary.Put(PdfName.AS, asArray); PdfLayer noPrint1 = new PdfLayer("noPrint1", fromDocument); pdfResource.AddProperties(noPrint1.GetPdfObject()); noPrint1.SetPrint("Print", false); // Intent (will be not copied) - ocProperties.GetPdfObject().Put(PdfName.Intent, PdfName.Design); + dDictionary.Put(PdfName.Intent, PdfName.View); // ListMode (will be not copied) - ocProperties.GetPdfObject().Put(PdfName.ListMode, PdfName.VisiblePages); + dDictionary.Put(PdfName.ListMode, PdfName.VisiblePages); } fromDocBytes = outputStream.ToArray(); } diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfCopyTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfCopyTest.cs index d3d01e9543..68d6d8b201 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfCopyTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfCopyTest.cs @@ -323,6 +323,19 @@ public virtual void CopyPagesLinkAnnotationTest() { )); } + [NUnit.Framework.Test] + public virtual void CopyDocWithFullDDictionary() { + String outFileName = destinationFolder + "copyDocWithDDictionary.pdf"; + String cmpFileName = sourceFolder + "cmp_copyDocWithDDictionary.pdf"; + PdfDocument inPdf = new PdfDocument(new PdfReader(sourceFolder + "DocWithDDictionary.pdf")); + PdfDocument outPdf = new PdfDocument(new PdfWriter(outFileName)); + inPdf.CopyPagesTo(1, 1, outPdf); + inPdf.Close(); + outPdf.Close(); + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder + )); + } + private IList GetPdfAnnotations(PdfDocument pdfDoc) { int number = pdfDoc.GetNumberOfPages(); List annotations = new List(); diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfLayerTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfLayerTest.cs index cb32c8f062..b529d1b5dd 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfLayerTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfLayerTest.cs @@ -330,7 +330,7 @@ public virtual void TestInStamperMode1() { (destinationFolder + "output_copy_layered.pdf")); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "output_copy_layered.pdf" - , sourceFolder + "input_layered.pdf", destinationFolder, "diff")); + , sourceFolder + "cmp_output_copy_layered.pdf", destinationFolder, "diff")); } [NUnit.Framework.Test] diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfCopyTest/DocWithDDictionary.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfCopyTest/DocWithDDictionary.pdf new file mode 100644 index 0000000000000000000000000000000000000000..fca8cebb4ad82c8732948881f48124ccc1efb447 GIT binary patch literal 3307 zcmb_eeQX@X6?dah!l_XxB}D?MOe(qf0`|_#eh2H2WBU?=V_kQoqoA-Nfy0b&+Uec#0x=){3d^bTb!pJM`O!W6lL+}~M7vOu)3R&6n z=L*uK=T)bq;a#j2N)s--QOXQ%3JR2hRcrp9+Tu^FPGa>bX`>aedDUc`zY0RoJ zfxs6@DU(hYh$;Mmivs2Q%S}lc-(h}1$WeiacuAZ)Tb~sAA1AKS&~?aw|kM zVGIg6%W*wa=4$ZPh~7qMv4<%sw^6_Zg+gbAR4U3wWY!WxtHX{C5RHPar#``I4nH^^ zOniW8w*ono(iO<>5VLvaMp>;K?mz^mQb7pmt|n#=UjE^VuC70K?dAxvFvjBB{*PFu z-h$;PP93{Z9>+><)yNsDi9{Iz$JI=d!@9l|)^Dmy<{Pd~| zW)5t5|LADEix7E9Mb>4Nw30N~`Ou!w*ePJU6;7^Veq{ zd+W6??OQoH|MBa)kFWpqC;!-a!S~m_6kd4FvGR*2PF_`g>k93;6Zx}$I<&BV#mc*H z|NGZp8Qk`ZKc@G-RJnI??$V!r+djPZ?EPyGO|HGkIP~QYw3}zDlQ-Y7V$a&^U;X^a zp7X!;x!;U>8@qn=o%{AK%x}|9%=gdV{lz!d98G@3Klk0Qtvg)!UE=)X-}}aQ7oS|P zvsdl=;L>eJ|5@4afU^39-+p?>@#{X>z2?bBb7!~T^2_@lnv?cbe^B{kVdd7BC*SvS zJO6TEU?G3zsRPzMYo0G1+0>q7rIF-8PY^OFL`5GFgC7ErY728*Yoj+?;3QK`6&VVh zlCqW$3`T;UQjP`QjBm358bunQ_zyvXS5lfHB6B2QM%MSHnIF1BG3yf~SOQ{bP*KUl z8uSGTU@6D!g{2a+2bO9~Sy*Z@i(sjvs3E}8KoMPGX~v97!6S|PZnbSA<8#vtc2j1l z)DqcvxG_OQ^K!k~5Rk2BXamK>AQbCFRt>E7V)-(RFH1_$zUm58!GxNi0IHWSDZs{^ z8Jqb%?l_wbpFnya=~H|2V*}az=FB*Hgkp?)IXDsuNc0#qHi5SH3~b7d_U?j)1yO8I zUWuxn5wUD@XbfAd%YC6l^N&wmwFAI_TATA_v7%-QtidSv`@FH6}4{rvlj!4(IPEg(&Npfm{EdpDBjC9ylb4fVpV{mlte|D@M{7 zA87TF5?R3TY#4}I{wxbblATPN_S@zJ(T*lfCHsHfub7d|;fu=L5Y5of2)`-!BK#JU z&fzzWH(??sahVU|fA4DfakSfY^e5Uw^RC+MRS&C5n~dltRO&K4 z9Rrb<$rKG{P^*j>MjIZ+yg--fnKCq%<+65LisiPw0bY~?(#Q)X{McLZDA7CELgu(y zvn_?rxZIZNP`3POTE?2=N_i>!z(qLp+DPQU_q*(zxzP0^X*P*AWK zO-;eozvLm_u5wb&1Ny)oVVQStVo;vIgl;jfdinV2Z5=;}Ahi5YlrmLyEz#XQoJlAC E1%OQCFaQ7m literal 0 HcmV?d00001 diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfCopyTest/cmp_copyDocWithDDictionary.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfCopyTest/cmp_copyDocWithDDictionary.pdf new file mode 100644 index 0000000000000000000000000000000000000000..87f72256369d416949a11fc2060b39375d5aee1b GIT binary patch literal 3171 zcmc&$du$X%7_SWoTqGcZB$&uxQf+`FACi+8up?iN}^ zJJ^<1!#t53WAdK*l~ooN}E zSaHl)5{L9Q>~IZM{Ap}Nd4Vb58ub(|k60;84;5T65Qy?h=2Or%upQ-TIAIXw5qo=b zAX;8$TOIA#07<GI*UL2E;u^lB6^lPl7wzE}e3vIKpE%UMf{qEwtn!st<=r{(QBx8=!-* z{hdejk_T!xwKVT&m=OG9`_`ie?^!jdrTgkvi_T2E@$TRAM!h^?pF4W+iMG9G&rM4m zeOTUcHgf&f-94*I2d!K2*W(AOXMgcaVCBB#o4sA*-+Mm3XUz5WV|KTUS*Y&5_q@Eg zBh|8aP3e*`Pknjkx$=?E-SK^cHNE8R7v5Ug(>+^0+dZ{=-Q8c0I8t%HJ>=wr6ZS-Z z^o>08(lamiZtIDMrmZ?Ze)f@nl2bN{!*~5~W6hZ-uPqv}?St_3IZMA;zp0B`m3lpS zt!L1z{Vk`h@VwvGR`ok!LE#|?AFAL8 zYTcTFL~eA%v0ZL9;ZFA>P;J>5sFUGjp)%4~6^hIVHi0?iRdt~TFrR=EF*v6JY(Wsh zN@7v~Rqb|{g8{=H(AZp&^_9Y~=WDP!n_$3Dourmxs8=NxDZzC;X|-h)&79Uba49p*_-W(i=*`J?ktcx9>dg_!>BeFaG@wY%WHS-gH&Zg3?J}>uW%CDlZBejH85tc$`oS z18S-kmkcF_^@Jt}k_JVImlKA;$0P*xn3m8KUDe}?Ac`uFWQo^AC>aS|m65EAN=%Jm zq$o%ev@|d@w9qy%o_v(Y*4{b4C{@8i&p^*uH`vcH zAlSn{L?K4Q(LKONp)9qiI5R&lMpI#>k%57Mu91O}v4UekQDt$ef_qVZX@P=Y*ko(o z$D2=a1u;&R;}c^v+ic4BmQlpWMAyJj*T^!&(9+7l&zH#aa(H88eFO-{71OfxnxF-o*ZHA_kb(#FP# z$!3P;7UqU#Cdmet7DTCg!Q;W)>Ev$)={pNd}flX~u?$rYR|j zsYb?zDHf@g=7uI|MoDR=mc}M#ra*0}rfKHMspbZ1sdlmYo_Q&$710I?7Dga;TE2pb zse*w*kiJi9UV2G}f{~%o^!W;mCiSOz4;k4N1bLpP>OSflOra3NUIxDrNE}1+hc&Co#QvJv)HCmw?`gn7aT6B9h_HveO z=(c_Hn8CfM&CEjE znS~gW`CKiMEfN!x&6ATYla106Q&J7g4H8pREDVy;Op*=KOwH|L^*!@aQY)ej6f6uu z?6iCZ6H^5Pg&=*O)V%bP3$*aDmk~ zfLVw)fKxPpacY6uKT&zRNIxa(X;-FXU2;9QGH&{uOWSp#?50ZHIL23Icu4NpjpHor z7Doj83Y&~At@vu~mTx+sy3T;N{Ey426;C1(Iz{seA>b!{A+UW*B2B(Pym#V6(zZ(|- DFAcMB diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/layer/PdfLayerTest/cmp_output_copy_layered.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/layer/PdfLayerTest/cmp_output_copy_layered.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d957af711a2029ddfa648409fbcfb4be2a46a041 GIT binary patch literal 2566 zcmaJ@Z)hAv6jv(JUZMD>twJpf#h3(1c4l^G|HSk(x#ZF|X>#86pWU9gw>x{?HrWlk zdugs#K~O}of_`X4TMPAzRS^+IsI*i`#iCefs%TNsD%4W(LxonfSZDV3a+kZS`{8c) z?fcDp@ArOhX4^6Y=`Pf*B-+mZa(XtQ0SLUpjzn*-kaosH>I>;{Bcub=^eifjP`4Ov z2UygS$sqKpF_D-)@XX7fjLv|igID*Q{Na_~-g<~`-T&2=((<0Ymlv!YUY0Y?9Ja6R zUNO8Bzqxqo!h!u)`=?HwSoish)@#e&-~HH@N8efa$huV>&tE*X@17N;=j+4Xl^u7F z{VE>0_lSGnm&1GZExF@`(Y=@7yLox~)9k;SpKD)t?V~f!2MZ5wd~oHt6RSIWms~0B z|90rvzQguQ_C^>y=fh?N1_p+N;ofM z44?S`9Jyp^;FWxn2Apq(=6?tv4#*~xLdN$dsUJGg`;3o(6rtE11gH`u<6|JlRuL%i zodi%NK*lEkiLq4%h{U%FKvk3qP!*;D#LHo!S?~?zNy@S<(qxiX&1>Zg#p+10?uU-& z4ls3e4D?`#2*i*eBq;>l55;x}+dGBzo;BxyC5W(wG^imw=fEnoN+$I?oDFn3d>5oV zp8~ZTc8guP(Y{P>&DaL8t)p)!GXkclAFzPiI>8YPA?(5si=c1PF9#G1`Ce%fjBe_z z<%(*#j-_fuf|vnTR}eQLDl}z;#<*9k;W>ZRTD=nM7!rmZE6^i?@-=pX8iaQzhKw2$ zv}2S8A+^A`QD&)kRv=@kp&Eea5(5TU>-%y#`(>HXqUV=&VXNm&9%A=O!pUS_81c-V)Y7AF=Y_F!TCa#8763E(7WMT=WI&Jf zQBhPL=p7NowQ6F4#p2=)S;KNXP~@HHjD;49th#<)$o5Ce1iD^PVxt3-T~uQwg}Myp zhikcftlfAp7(Z3j@?~z+7Jypyg)?+R1a5_hMmC1@8v*6REUcm9Q#5o;Ll|_~{^__y zVYB1*xq&nHoGTSVK4)BmsG<-KttB7LaeXckfjt#bwaz}8_Zvc5r(dVUNV-uoqh9`h zs77v^ajoMuGTe+4Thd&&+eUf1UI-?+@~Ktx7d8fLyxDX_V^ICig>106>V+!l(QCff z)zMvd07e1$3%3CE56=dU~MQ#%0xh6%QHMHfOqCPXB_ z234DaS#*8@w`SAWrrTg6gwfYvQzbStjkabi!h~&%^Zk$rn`}_T%{I2jH)EUEgAi47 znX3&+5VRV3SET?i_ze;gi|mr@}h^Lf>%4sn5T7 z)(!x@*DgQ{**3(gNQrDJhDs5^M8t||OR@x$y|!&r%Th!Isv1EmEkM(dsEy@? zwrI-|)@)lgOw-f~3M7(b6H}EX17idw6Kh1Y5mihB$)aURnkp(36-Jc2g!XrslTjIPK!6Y1jPI VG!cY`A4YOSEd4}V+u&F_@gF7Z?UVoj literal 0 HcmV?d00001 diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/layer/PdfLayerTest/ocpConfigs.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/layer/PdfLayerTest/ocpConfigs.pdf index 5d68f5028cd9b15ca59c63d1c35e72d7e17db7f8..0f217c612e90d681a473bae19bd77ce55da534de 100644 GIT binary patch delta 424 zcmZ8dJxc>Y6eQ84I8@X|5yWi*iITAI?e6U^C>Vl9L@t4dRhqloJxO5_E>X0y5i1d4 zdmAfD5&wgw;J>l*6e5`J&0{{8d0)6$e5lX28jV3e>754QnZ=jjF6Y+rJ9Ee>AP3I5 zU@p!-xwri4Zex&IqH46ps-2+T?i{p^Nw-{YwvWh#O-H>!zgr>CNGYu%MMmnw^lD^D zGaZ}{NpMneAGyQVrJ39OhN6mOG)hUIc)tgwO5)__?hEVgvrt~qnaea!OXik~Y8J8x z7Zgid0Dr=X86XqWLSRC<$Kv)iqBh1#o3-;XVuBkmCe#^{C_~F3j7)4bSkO#>4-hGi z95qT2`%F_EsaQ%(V$@bLj!d&ihr$>Lwcvh2BNReJ+E)gIG#E-0j0vAci3Lh?+IIKel;kvBL$H`TecsK_rdH#KB(0jt)=iX_I#8q5xpZ!y~P7+M;b8<`rK8=9CH zOjc%E%&56Jj(GypWHB}oadQh(1p^RJ$W!0~GYkw&jV&fivRR5-7@J|pSy-4&&SbM- zF|af?o4k}wRolP_!vI4=6AN^WhDPRwlfSarC;(kyXlRs_Vr&F-mZ5>6aaxLrnPHk) zk_AwgfkEozjqF+~=6Z&D7P`THjsd|Q{vlk&C5c5P6-B9OT!zM$CS0njuKsRZ00f~u AT>t<8 diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_MergeWithSameNamedOCG.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_MergeWithSameNamedOCG.pdf index 652264cdc95ed1b8e5287c0c4ed1c0d92ef34274..db714d7a226ce0e0a9b983edab7e9ae02646c6c4 100644 GIT binary patch delta 780 zcmcIiJ!=#}7)EkN*+vp4$a;B&O4uS2q9~th@E1f&{6(C9^GE(0IS_4??51-AZX_)hR z`apubLMUH#?p}8T7*P4C(_JO8d0c!vVX;%p-XDwci+*{!^z_^J&d#;+aQR|^(xQNR zh$E3)ZlHE*Vc>le0|ME?kX#c(RjD^Ul&g8+Z(~iZFknbGFN3meL2Xr&hX!4_xY1pJ zH*FCI?Uu&08lhEJn$L@H@Rp1E<({PC^$2aoPMIu_^?`$;=mJGa3}}OuhDe#PfZUOu zS^%4Qw)s?pNAFl^jFAJ&OvPwD=AgBLO3xb3ks@a~2S+ZTvuvl8mi7=raIspAVa<^q v{zHT}Rfhi4vYq?^;FrG% delta 565 zcmZn{*(AiL8sOrlYp7?=rTXac`O6zS4>3>v&f+-Pn?=^&$k4#R#L&#Z)X-epz*ybD zKwVScH$TNCu_RT)#mdOQ2%Ca{qWqN7hHz{0Ft4Ega7~l diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergePdfWithComplexOCGTest.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergePdfWithComplexOCGTest.pdf index fc847304724c032968927ce57353dfdf52e8ee30..3ee417dfb2760df2887bc2bb129bc93a91ba99ac 100644 GIT binary patch delta 1080 zcmc(dv2W8r6vhW=ii`>)5{T*;q9&l!@1E~`cU2WBO4=e+lBlgZkY=!b=Mt*Mm6Mis z%FJx>N3bAOAa(|31{P-cE7-U+fN;!?C0lo&e(&D*`Q6uhua_s~ZfmnfSA|pl_Wko0 zM-U)M_`+FVcU$&t?Dp)p8H~+gl3w)OXGwD0cQ?+=aP006%uBb^+#2;Lw^cj+dY$Cp zZaNr_f74f+8IImByzg#5NTMU7dvw}&r|-6dV^irgo5?U998Nb-&FYKqvmc9aXV!)M zsdmgzTdSA1J}zXpOZO)XC`Iadz6X!MTLD<9x=$0`vgRwTH3a+@&`lG48kw{**fZzj zx1^b*hR9V|^=iBAMtApdXOA3I8e83Ma%R%eAQ>K1$r}WKnmy4Yjg$0ZWXM*Ulul1b zd%v1}T6mIuC>_09yCJSUN8moOFaQ}6=V}2+5#}{2C7ahka#he6#d!^>5ZUF;@`S4b zPXXvWPeItfo%ckM6*xpJaOlxu9tL*)0Fzuu#;?Sj#+jXbzAHg>X55Q8!j=nhfPd< o{eN1xZatXn)zZW2^y=60SKk?pgLHhJn%MDxGN)YL=xjPa0aI-bQ2+n{ delta 768 zcmZva!AiqG5QZrt4MF+>qU?37))o z_2NZeKwrRv7ti`4Zt6kJb|4VG{b&D~Ke=7~ST1O7cSomXu4b2ED; z!jPHRC94Aqn9OXDn9U>|Qm|5;i2rwZq>f~aXv@upAv1>3fXKMWE3H2sCjRXe{-V(2 zQj%z)lq6bnhT%-w7`Zds?#DQe2E&UWO26%%OO7h0@B`bV9-K1E^8$*tgUC)$0EhY< itN$eP6v=C0UCaD*>Np-m@iYofRdJ!AYT9;dNBssx39o|y diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergePdfWithComplexOCGTwiceTest.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergePdfWithComplexOCGTwiceTest.pdf index 949e9be430e997dfbf17480f159d2e4e66293ab3..54713f1af3fbdac814f2905d6b33add259fbdbd0 100644 GIT binary patch delta 1080 zcmc&zO>0v@6s05q`?3&Rl&X{tLa-5%H#2wMd_V|>w2fd%f-PN`cJV%DN|ff6mss0P z^9OYG-0E7F;>Mjn!G#O=iVJ^*PD0w6ydU7e4BRv4+;iv7%;(j&cgLmf=5~ctg;V7WF0&jSw`G{cAhil%#LaE&RE!8~r;JsH{wFuM%P=G6^wfnS?}o z-l7Rn%=UZUm}0mzx$>Y`E?{GfDdG117Q}S&a27GKAhuedna)rU* delta 742 zcmaiyzfRmh5XNO8jAZ_l=mG+^v6L%(nVI$Odd2C)5dsJyH~~rn6gKurfOJO3f#~iP zK&~n1NE;d+AUy?dkW_hwH24e(hK-bwwwT|3JKv0UuBY!S6K-p1*~6N0+@HT59`7!# zbjZT*!xbz0VK=jiJu?cRfnz`lf^5N_e3OUvhj~@Q8gg%YquJVC-P~c{2mm|+0(Q8Q zT=dvVH$6LH8(-Pp$L30F-8)aZr-x~0uUgIi*i{Sf+>z?gY%T|uMn_J){%I*c>*>L9 z67M3<@z(y;&8>ymXG`^UkvAGn(uoK1i*C|(fDt*l?MpBz1Q)E$UKpbCS#ifYf0+-` zV8rwCgLu_}L@crF_vmzAmr0=q68~_JCKG~6)rz+${e1R8yt<;)CQ~XXbp5h0Afsgr z0`sxvM$@PRqZtDJY*O+d(8eG@C=3%KU%j6M0!>+MY-*8f5yix#@F0n0l=!iVxF2eg q2%(H*yHWq2B3m1u1IoYNEf&jrw|UNKFYNY;eISAPM!R1&mz^i6(y1~4 diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergePdfWithOCGTest.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergePdfWithOCGTest.pdf index 4820634f857bf31bbae25949412d1abf3d7261cb..1d2e7eff6f9064f0ed05ec6c78d6969e0bba9588 100644 GIT binary patch delta 799 zcmc&yJ#Q015N!|+8wpAT64Dl&;se>4ncchFMOKjIBS8pkONl5@n!WuXM#2}JohYf? zQPSM6NP|RA#}A<3AHe@Woau5-PqCxjH*a>{Jk8bpPY*Df=KDSDXDs^l`^Qg~ao}a~ zfei+`d2`0*qwh{eqjDZ*@7E8A>u+0=ulJsJ>d&1=D+!2%LZkwpg4hAriFe+r ziIJ(WL73o0;juO$0me-RV#U#Zgbr!Z)gwv5Z{pcA9qg%<9oa zTm|Z?n64SL9r)7++PS9vVzX^usE;z3jQnxGv{i~;vrjpV0`&*C#4swRVZ5Lf<+nc? zsB1uDB>+06WE}uQz$AusE|M6C8jCEFzhbDdWRk^}#6Z_m!cc>hFyqmZ?9Mr)6cE@3 zc1=%qiU+EuFd^a_Bvuvd&qQJ1jP7NyI?=gF%^L$nRfwwVg7kzKqL2e21`hMQ*z3B> ePyS^@eCJR}{EkdQCkSVO^avB0Ac}Howa70dnv5C% diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergeTwoPagePdfWithComplexOCGTest.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergeTwoPagePdfWithComplexOCGTest.pdf index be203568cfae547dcec5d45828f34205eabd3101..b5371972c0cfe97ada1ff25059ef71653d8660d1 100644 GIT binary patch delta 700 zcmc(dJ!@Mr6owbq0YM2}0|hN6z74jIzNO+6j9sUc);2g~2wrq0-QtA$hHIxdlYc|F zW0$VY5Xdj-Q0Nb6w+`LARqkfHdk2B^=soZG;QZeI_Jq_%y?%o<6{>yz@#QO07;v6m zpmw{}i)Ucphx)MF&1c#4-TDDZiK^^j|6`^6S$VqRKnNv_Nyd+W9ReICt+%=F*+r=L zo>QRz5{!!6U%OD$r>9}LxX0bR2v|3v$r|H9XEc5_JjIiG=VbH-e+b2Vn$IQ){!9U& z5gi%sTopI-fKQ6NdVPflXG!^~^18fzbXgu(&sSU!9HjtwhSA>(5JAKaqsnYE5Ipw3 z84DyjZ80Jg-DVK8tXcW1`uK=2x$`gePCg7L=#d#QwRqL1*5@F-oB| xv%ztvwP#xEm3z_tpCwdc4X(V~dzP$Mp|QCNXuhz;Vp)U?5vc^K)m{$!=no7yv{V29 delta 473 zcmca6_>-ScHNeG9*HF)#OZCy?^OrX!&taLon$=lx}98tVr8IR*rK_=hO0 z1nM%-1!-0Qt59$+$}cTY@C#Fj(QtGR@X;+xEh^5;&x_Gy)SUc~wUp0X!9XEDDT~X- zM&HH8W}>0-Z^cC~sF3nO$X zLsMf+F#}UWbae)12AI~HS^}L4b5coBVrEWi5y;h^E(*~$<|(PENd{>qMk(f&My7^l zhUNx|$z}#gCTXe0Mu|o##&%egpsJYM%%P=<7MxtgC5c5P6-B9OT!v<*23)GDuKsRZ E06LC$)Bpeg diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergeWithSameNamedOCMD.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergeWithSameNamedOCMD.pdf index 2fee600a7c7b6b13a40861220fbd1c7307539d49..d20100d15ddd1682a3b2f41a5e356c9490f34941 100644 GIT binary patch delta 1986 zcmc&#%}!H66b=eiswe`YsL&c|fG99?=ARG~17g$&UAb^~Z#&nh5eVwSg*3(mYtzLw zCM2k_TcaDE!G$4)og1P)f-m5iQh}NK08aCz_kR7(@64J0`L_CYYgL!ZvvcEgLgh=p zes68(1uv4~Qv5JKJv}*#n2#RY(S@0rrN!jIefL7fCKpz!b|qae_m8J<%KcMqvi^Fw z^jUoBsPo+56;3GNhY6xD6E;G~$k^narRr?-)Q-+h0f7U8`itC9hn^r4tiF*O?qS7i z%PY^H*y4?qrDw~<`MYEFA078z?c~;Wa&3r1h{K3>LILRS>`5trkd*^=A;OErjM3@sH*wCOJLZr;tDgeKA=ua`(@>ko>U9skl zw;GRM6g29z7sPQ|hYmF}%1;n=lDpY2pc9N~Udxc-%s6ANf{Kxo!7*_<85Y8Y(IO~>OG5WXp=)=jDUv`<`gNml z@e#fN7r}u;PH_Jmxh=xG&8xt1H0ZJOC&Rr!P8pWAeJl*ujAFq~afOb;43IM!4yVx1 zfO5s~^6;{1a^Yk+U31hA+%Z5D4M*K^hWiO32YAA~AdW+iSuU7yrxWymzw}b0(3jqB z6uN5+o1&tmVzjccjueFoCkd^{3Il4ninx|ZVt5=!GO1_+wyFsial)&zQc*Idk<>{7 zqDpv`$3$vlg|?9eE2Y&W7E~&$BWt5525v>nwbdx97{ja8n!GywKT~MO9AvuQC`|7D TNv7W$g@H~6`BLfn!d(6@KXb^g delta 1858 zcmah~Jx^0%6pkOXS{20){DfW;2qHq??+-#uOe)$z+63Za917ef5Cf#vgo!&iFp~}> z4o)P_PK3dqU>HoCjs65z2cP!})qCzB$rGBV=bZPv&w0+sxXnMxI?&+V*E6e{)ha@^ioo!p71w+|YF zz;)mTa1*!%+y?FdL%{I(LsG^URqXC$&#?n8=NT0n)2-GSoYv7E_HW)a|XoCz> z%K3t6k*jB!HBp#<&r~RA1xX(cJ*Y1+8p_*HkwP&FLB7U{RKe)YHg9^z3BuE^(a({LCTS(44lGJgw06b+c2a+YT}BNGye>y({8T3ireAEuT`TLGb(mQh()bi(lZ;| zB@Me7{1bjzu%+h1|3|#6)Yf)uAIkT~(%-Sk`MF1p`KR@T((6vM-Pvr%tx{;iX#7@= JKCaJ}egjzdjpqOW diff --git a/itext/itext.kernel/itext/kernel/logs/KernelLogMessageConstant.cs b/itext/itext.kernel/itext/kernel/logs/KernelLogMessageConstant.cs index 8d6a15adf2..6e47fa1586 100644 --- a/itext/itext.kernel/itext/kernel/logs/KernelLogMessageConstant.cs +++ b/itext/itext.kernel/itext/kernel/logs/KernelLogMessageConstant.cs @@ -84,6 +84,8 @@ public sealed class KernelLogMessageConstant { public const String FORMFIELD_ANNOTATION_WILL_NOT_BE_FLATTENED = "Form field annotation flattening is not " + "supported. Use the PdfAcroForm#flattenFields() method instead."; + public const String INVALID_DDICTIONARY_FIELD_VALUE = "The default configuration dictionary field {0}" + " has a value of {1}, which is not the required value for this field. The field will not be processed."; + private KernelLogMessageConstant() { } //Private constructor will prevent the instantiation of this class directly diff --git a/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs b/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs index 2d88e53a97..03f284e0fd 100644 --- a/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs +++ b/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs @@ -26,7 +26,9 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons; using iText.Commons.Utils; using iText.IO.Font; +using iText.Kernel.Logs; using iText.Kernel.Pdf.Annot; +using iText.Kernel.Pdf.Layer; namespace iText.Kernel.Pdf { internal sealed class OcgPropertiesCopier { @@ -251,19 +253,20 @@ private static void CopyDDictionary(ICollection fromOcgsTo toOcProperties.Put(PdfName.D, new PdfDictionary()); } PdfDictionary toDDict = toOcProperties.GetAsDictionary(PdfName.D); - // The Name field is not copied because it will be given when flushing the PdfOCProperties + iText.Kernel.Pdf.OcgPropertiesCopier.CopyDStringField(PdfName.Name, fromDDict, toDDict); // Delete the Creator field because the D dictionary are changing toDDict.Remove(PdfName.Creator); - // The BaseState field is not copied because for dictionary D BaseState should have the value ON, which is the default + iText.Kernel.Pdf.OcgPropertiesCopier.CopyDNameField(PdfName.BaseState, fromDDict, toDDict); iText.Kernel.Pdf.OcgPropertiesCopier.CopyDArrayField(PdfName.ON, fromOcgsToCopy, fromDDict, toDDict, toDocument ); iText.Kernel.Pdf.OcgPropertiesCopier.CopyDArrayField(PdfName.OFF, fromOcgsToCopy, fromDDict, toDDict, toDocument ); - // The Intent field is not copied because for dictionary D Intent should have the value View, which is the default + iText.Kernel.Pdf.OcgPropertiesCopier.CopyDNameField(PdfName.Intent, fromDDict, toDDict); // The AS field is not copied because it will be given when flushing the PdfOCProperties iText.Kernel.Pdf.OcgPropertiesCopier.CopyDArrayField(PdfName.Order, fromOcgsToCopy, fromDDict, toDDict, toDocument ); - // The ListModel field is not copied because it only affects the visual presentation of the layers + // The ListMode field is copied, but it only affects the visual presentation of the layers + iText.Kernel.Pdf.OcgPropertiesCopier.CopyDNameField(PdfName.ListMode, fromDDict, toDDict); iText.Kernel.Pdf.OcgPropertiesCopier.CopyDArrayField(PdfName.RBGroups, fromOcgsToCopy, fromDDict, toDDict, toDocument); iText.Kernel.Pdf.OcgPropertiesCopier.CopyDArrayField(PdfName.Locked, fromOcgsToCopy, fromDDict, toDDict, toDocument @@ -278,6 +281,38 @@ private static void AttemptToAddObjectToArray(ICollection } } + private static void CopyDNameField(PdfName fieldToCopy, PdfDictionary fromDict, PdfDictionary toDict) { + PdfName fromName = fromDict.GetAsName(fieldToCopy); + if (fromName == null || toDict.GetAsName(fieldToCopy) != null) { + return; + } + if (PdfOCProperties.CheckDDictonaryFieldValue(fieldToCopy, fromName)) { + toDict.Put(fieldToCopy, fromName); + } + else { + ILogger logger = ITextLogManager.GetLogger(typeof(iText.Kernel.Pdf.OcgPropertiesCopier)); + String warnText = MessageFormatUtil.Format(KernelLogMessageConstant.INVALID_DDICTIONARY_FIELD_VALUE, fieldToCopy + , fromName); + logger.LogWarning(warnText); + } + } + + private static void CopyDStringField(PdfName fieldToCopy, PdfDictionary fromDict, PdfDictionary toDict) { + PdfString fromString = fromDict.GetAsString(fieldToCopy); + if (fromString == null || toDict.GetAsString(fieldToCopy) != null) { + return; + } + if (PdfOCProperties.CheckDDictonaryFieldValue(fieldToCopy, fromString)) { + toDict.Put(fieldToCopy, fromString); + } + else { + ILogger logger = ITextLogManager.GetLogger(typeof(iText.Kernel.Pdf.OcgPropertiesCopier)); + String warnText = MessageFormatUtil.Format(KernelLogMessageConstant.INVALID_DDICTIONARY_FIELD_VALUE, fieldToCopy + , fromString); + logger.LogWarning(warnText); + } + } + private static void CopyDArrayField(PdfName fieldToCopy, ICollection fromOcgsToCopy, PdfDictionary fromDict, PdfDictionary toDict, PdfDocument toDocument) { if (fromDict.GetAsArray(fieldToCopy) == null) { diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs b/itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs index 48fdd6c46c..bc49dc8312 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs @@ -80,6 +80,8 @@ public class PdfCatalog : PdfObjectWrapper { // If this flag is false all outline operations will be ignored private bool outlineMode; + private bool ocgCopied = false; + /// /// Create /// @@ -494,7 +496,11 @@ public virtual iText.Kernel.Pdf.PdfCatalog Remove(PdfName key) { /// /// boolean indicating if the dictionary needs to be reconstructed protected internal virtual bool IsOCPropertiesMayHaveChanged() { - return ocProperties != null; + return ocProperties != null || ocgCopied; + } + + internal virtual void SetOcgCopied(bool ocgCopied) { + this.ocgCopied = ocgCopied; } internal virtual PdfPagesTree GetPageTree() { diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs b/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs index 432f9d9658..4482f2e945 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs @@ -1243,6 +1243,7 @@ public virtual IList CopyPagesTo(IList pagesToCopy, iText.Kernel.P // Copying OCGs should go after copying LinkAnnotations if (GetCatalog() != null && GetCatalog().GetPdfObject().GetAsDictionary(PdfName.OCProperties) != null) { OcgPropertiesCopier.CopyOCGProperties(this, toDocument, page2page); + toDocument.GetCatalog().SetOcgCopied(true); } // It's important to copy tag structure after link annotations were copied, because object content items in tag // structure are not copied in case if their's OBJ key is annotation and doesn't contain /P entry. diff --git a/itext/itext.kernel/itext/kernel/pdf/layer/PdfOCProperties.cs b/itext/itext.kernel/itext/kernel/pdf/layer/PdfOCProperties.cs index 09d61c92ba..4ffb5743b5 100644 --- a/itext/itext.kernel/itext/kernel/pdf/layer/PdfOCProperties.cs +++ b/itext/itext.kernel/itext/kernel/pdf/layer/PdfOCProperties.cs @@ -22,7 +22,11 @@ You should have received a copy of the GNU Affero General Public License */ using System; using System.Collections.Generic; +using Microsoft.Extensions.Logging; +using iText.Commons; +using iText.Commons.Utils; using iText.IO.Font; +using iText.Kernel.Logs; using iText.Kernel.Pdf; namespace iText.Kernel.Pdf.Layer { @@ -131,18 +135,24 @@ public virtual PdfObject FillDictionary(bool removeNonDocumentOcgs) { } } GetPdfObject().Put(PdfName.OCGs, gr); - // Save radio groups. - PdfArray rbGroups = null; - PdfDictionary d = GetPdfObject().GetAsDictionary(PdfName.D); - if (d != null) { - rbGroups = d.GetAsArray(PdfName.RBGroups); - } - d = new PdfDictionary(); - if (rbGroups != null) { - d.Put(PdfName.RBGroups, rbGroups); - } - d.Put(PdfName.Name, new PdfString(CreateUniqueName(), PdfEncodings.UNICODE_BIG)); - GetPdfObject().Put(PdfName.D, d); + PdfDictionary filledDDictionary = new PdfDictionary(); + // Save radio groups,Name,BaseState,Intent,ListMode + PdfDictionary dDictionary = GetPdfObject().GetAsDictionary(PdfName.D); + if (dDictionary != null) { + iText.Kernel.Pdf.Layer.PdfOCProperties.CopyDDictionaryField(PdfName.RBGroups, dDictionary, filledDDictionary + ); + iText.Kernel.Pdf.Layer.PdfOCProperties.CopyDDictionaryField(PdfName.Name, dDictionary, filledDDictionary); + iText.Kernel.Pdf.Layer.PdfOCProperties.CopyDDictionaryField(PdfName.BaseState, dDictionary, filledDDictionary + ); + iText.Kernel.Pdf.Layer.PdfOCProperties.CopyDDictionaryField(PdfName.Intent, dDictionary, filledDDictionary + ); + iText.Kernel.Pdf.Layer.PdfOCProperties.CopyDDictionaryField(PdfName.ListMode, dDictionary, filledDDictionary + ); + } + if (filledDDictionary.Get(PdfName.Name) == null) { + filledDDictionary.Put(PdfName.Name, new PdfString(CreateUniqueName(), PdfEncodings.UNICODE_BIG)); + } + GetPdfObject().Put(PdfName.D, filledDDictionary); IList docOrder = new List(layers); for (int i = 0; i < docOrder.Count; i++) { PdfLayer layer = docOrder[i]; @@ -156,7 +166,7 @@ public virtual PdfObject FillDictionary(bool removeNonDocumentOcgs) { PdfLayer layer = (PdfLayer)element; GetOCGOrder(order, layer); } - d.Put(PdfName.Order, order); + filledDDictionary.Put(PdfName.Order, order); PdfArray off = new PdfArray(); foreach (Object element in layers) { PdfLayer layer = (PdfLayer)element; @@ -165,10 +175,7 @@ public virtual PdfObject FillDictionary(bool removeNonDocumentOcgs) { } } if (off.Size() > 0) { - d.Put(PdfName.OFF, off); - } - else { - d.Remove(PdfName.OFF); + filledDDictionary.Put(PdfName.OFF, off); } PdfArray locked = new PdfArray(); foreach (PdfLayer layer in layers) { @@ -177,12 +184,8 @@ public virtual PdfObject FillDictionary(bool removeNonDocumentOcgs) { } } if (locked.Size() > 0) { - d.Put(PdfName.Locked, locked); + filledDDictionary.Put(PdfName.Locked, locked); } - else { - d.Remove(PdfName.Locked); - } - d.Remove(PdfName.AS); AddASEvent(PdfName.View, PdfName.Zoom); AddASEvent(PdfName.View, PdfName.View); AddASEvent(PdfName.Print, PdfName.Print); @@ -193,6 +196,27 @@ public virtual PdfObject FillDictionary(bool removeNonDocumentOcgs) { return GetPdfObject(); } + /// + /// Checks if optional content group default configuration dictionary field value matches + /// the required value for this field, if one exists. + /// + /// default configuration dictionary field. + /// value of that field. + /// boolean indicating if field meets requirement. + public static bool CheckDDictonaryFieldValue(PdfName field, PdfObject value) { + // dictionary D BaseState should have the value ON + if (PdfName.BaseState.Equals(field) && !PdfName.ON.Equals(value)) { + return false; + } + else { + //for dictionary D Intent should have the value View + if (PdfName.Intent.Equals(field) && !PdfName.View.Equals(value)) { + return false; + } + } + return true; + } + public override void Flush() { FillDictionary(); base.Flush(); @@ -266,6 +290,22 @@ private static void GetOCGOrder(PdfArray order, PdfLayer layer) { } } + private static void CopyDDictionaryField(PdfName fieldToAdd, PdfDictionary fromDictionary, PdfDictionary toDictionary + ) { + PdfObject value = fromDictionary.Get(fieldToAdd); + if (value != null) { + if (iText.Kernel.Pdf.Layer.PdfOCProperties.CheckDDictonaryFieldValue(fieldToAdd, value)) { + toDictionary.Put(fieldToAdd, value); + } + else { + ILogger logger = ITextLogManager.GetLogger(typeof(iText.Kernel.Pdf.Layer.PdfOCProperties)); + String warnText = MessageFormatUtil.Format(KernelLogMessageConstant.INVALID_DDICTIONARY_FIELD_VALUE, fieldToAdd + , value); + logger.LogWarning(warnText); + } + } + } + private void RemoveNotRegisteredOcgs() { PdfDictionary dDict = GetPdfObject().GetAsDictionary(PdfName.D); PdfDictionary ocProperties = this.GetDocument().GetCatalog().GetPdfObject().GetAsDictionary(PdfName.OCProperties diff --git a/port-hash b/port-hash index 6fc845e2ee..1a36faf6e3 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -0ecc4cd397ba4046902f2a0685b2aa35e1c16d89 +abe3f098b9d6dedcab048715f32f1de25b60e65c From 14aba17b5c357f06714afc50d5536a6380b07e5b Mon Sep 17 00:00:00 2001 From: Dmitry Chubrick Date: Thu, 1 Feb 2024 16:03:52 +0300 Subject: [PATCH 2/2] Get rid of TeamCity.VSTest.TestAdapter * New version of TeamCity isn't compatible with the old TeamCity.VSTest.TestAdapter, so deiced to remove it, because new .NET runners are used which override reason of using TeamCity.VSTest.TestAdapter --- itext.tests/itext.barcodes.tests/itext.barcodes.tests.csproj | 1 - itext.tests/itext.commons.tests/itext.commons.tests.csproj | 1 - itext.tests/itext.forms.tests/itext.forms.tests.csproj | 1 - itext.tests/itext.io.tests/itext.io.tests.csproj | 1 - itext.tests/itext.kernel.tests/itext.kernel.tests.csproj | 1 - itext.tests/itext.layout.tests/itext.layout.tests.csproj | 1 - itext.tests/itext.pdfa.tests/itext.pdfa.tests.csproj | 1 - itext.tests/itext.pdftest.tests/itext.pdftest.tests.csproj | 1 - itext.tests/itext.pdfua.tests/itext.pdfua.tests.csproj | 1 - itext.tests/itext.sign.tests/itext.sign.tests.csproj | 1 - .../itext.styledxmlparser.tests.csproj | 1 - itext.tests/itext.svg.tests/itext.svg.tests.csproj | 1 - 12 files changed, 12 deletions(-) diff --git a/itext.tests/itext.barcodes.tests/itext.barcodes.tests.csproj b/itext.tests/itext.barcodes.tests/itext.barcodes.tests.csproj index 1e6cfa2a6e..01ceb83efb 100644 --- a/itext.tests/itext.barcodes.tests/itext.barcodes.tests.csproj +++ b/itext.tests/itext.barcodes.tests/itext.barcodes.tests.csproj @@ -33,7 +33,6 @@ - diff --git a/itext.tests/itext.commons.tests/itext.commons.tests.csproj b/itext.tests/itext.commons.tests/itext.commons.tests.csproj index 26bc070a71..50ac589f5b 100644 --- a/itext.tests/itext.commons.tests/itext.commons.tests.csproj +++ b/itext.tests/itext.commons.tests/itext.commons.tests.csproj @@ -33,7 +33,6 @@ - diff --git a/itext.tests/itext.forms.tests/itext.forms.tests.csproj b/itext.tests/itext.forms.tests/itext.forms.tests.csproj index 6fa93ea76d..051da61660 100644 --- a/itext.tests/itext.forms.tests/itext.forms.tests.csproj +++ b/itext.tests/itext.forms.tests/itext.forms.tests.csproj @@ -35,7 +35,6 @@ - diff --git a/itext.tests/itext.io.tests/itext.io.tests.csproj b/itext.tests/itext.io.tests/itext.io.tests.csproj index bb3b65616b..3b4d7ddfb8 100644 --- a/itext.tests/itext.io.tests/itext.io.tests.csproj +++ b/itext.tests/itext.io.tests/itext.io.tests.csproj @@ -28,7 +28,6 @@ - 1701;1702;1591;1570;1572;1573;1574;1580;1584;1658 diff --git a/itext.tests/itext.kernel.tests/itext.kernel.tests.csproj b/itext.tests/itext.kernel.tests/itext.kernel.tests.csproj index 9c3449b77b..a3b02580a8 100644 --- a/itext.tests/itext.kernel.tests/itext.kernel.tests.csproj +++ b/itext.tests/itext.kernel.tests/itext.kernel.tests.csproj @@ -33,7 +33,6 @@ - diff --git a/itext.tests/itext.layout.tests/itext.layout.tests.csproj b/itext.tests/itext.layout.tests/itext.layout.tests.csproj index 9f68a42563..6f794def70 100644 --- a/itext.tests/itext.layout.tests/itext.layout.tests.csproj +++ b/itext.tests/itext.layout.tests/itext.layout.tests.csproj @@ -33,7 +33,6 @@ - diff --git a/itext.tests/itext.pdfa.tests/itext.pdfa.tests.csproj b/itext.tests/itext.pdfa.tests/itext.pdfa.tests.csproj index 0cbeaf9d26..1f2b3356cf 100644 --- a/itext.tests/itext.pdfa.tests/itext.pdfa.tests.csproj +++ b/itext.tests/itext.pdfa.tests/itext.pdfa.tests.csproj @@ -33,7 +33,6 @@ - diff --git a/itext.tests/itext.pdftest.tests/itext.pdftest.tests.csproj b/itext.tests/itext.pdftest.tests/itext.pdftest.tests.csproj index 7161149c66..7f4bb7afa5 100644 --- a/itext.tests/itext.pdftest.tests/itext.pdftest.tests.csproj +++ b/itext.tests/itext.pdftest.tests/itext.pdftest.tests.csproj @@ -33,7 +33,6 @@ - diff --git a/itext.tests/itext.pdfua.tests/itext.pdfua.tests.csproj b/itext.tests/itext.pdfua.tests/itext.pdfua.tests.csproj index a623a27ccc..28456d3fda 100644 --- a/itext.tests/itext.pdfua.tests/itext.pdfua.tests.csproj +++ b/itext.tests/itext.pdfua.tests/itext.pdfua.tests.csproj @@ -33,7 +33,6 @@ - diff --git a/itext.tests/itext.sign.tests/itext.sign.tests.csproj b/itext.tests/itext.sign.tests/itext.sign.tests.csproj index 8f90f83b4f..fb883e150c 100644 --- a/itext.tests/itext.sign.tests/itext.sign.tests.csproj +++ b/itext.tests/itext.sign.tests/itext.sign.tests.csproj @@ -33,7 +33,6 @@ - diff --git a/itext.tests/itext.styledxmlparser.tests/itext.styledxmlparser.tests.csproj b/itext.tests/itext.styledxmlparser.tests/itext.styledxmlparser.tests.csproj index 04730baae5..f9ee967600 100644 --- a/itext.tests/itext.styledxmlparser.tests/itext.styledxmlparser.tests.csproj +++ b/itext.tests/itext.styledxmlparser.tests/itext.styledxmlparser.tests.csproj @@ -27,7 +27,6 @@ - diff --git a/itext.tests/itext.svg.tests/itext.svg.tests.csproj b/itext.tests/itext.svg.tests/itext.svg.tests.csproj index bebcf16385..5c83e67eba 100644 --- a/itext.tests/itext.svg.tests/itext.svg.tests.csproj +++ b/itext.tests/itext.svg.tests/itext.svg.tests.csproj @@ -27,7 +27,6 @@ -