From de6e4ed408b17403bd1d791edc932fddca6e9772 Mon Sep 17 00:00:00 2001 From: Alexander Pliushchou Date: Sun, 28 Jul 2024 14:07:35 +0000 Subject: [PATCH 1/2] Remove Duplicate OCProperties DEVSIX-8396 Autoported commit. Original commit hash: [1ee19dc92] --- .../itext/kernel/pdf/PdfDocumentTest.cs | 56 +++++++++++ .../itext/kernel/pdf/layer/PdfLayerTest.cs | 19 ++++ .../pdf/layer/PdfOCPropertiesUnitTest.cs | 88 ++++++++++++++++++ .../cmp_removedDuplicateInOrderArray.pdf | Bin 0 -> 4528 bytes ...mp_removedNestedDuplicatesInOrderArray.pdf | Bin 0 -> 4448 bytes .../removeDuplicatesHasChildInOrderArray.pdf | Bin 0 -> 4308 bytes .../removeDuplicatesInOrderArray.pdf | Bin 0 -> 4410 bytes ...veNestedDuplicatesHasChildInOrderArray.pdf | Bin 0 -> 4188 bytes .../removeNestedDuplicatesInOrderArray.pdf | Bin 0 -> 4297 bytes .../KernelExceptionMessageConstant.cs | 6 ++ .../kernel/logs/KernelLogMessageConstant.cs | 4 + .../itext/kernel/pdf/layer/PdfLayer.cs | 6 +- .../itext/kernel/pdf/layer/PdfOCProperties.cs | 34 ++++++- port-hash | 2 +- 14 files changed, 212 insertions(+), 3 deletions(-) create mode 100644 itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs create mode 100644 itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/cmp_removedDuplicateInOrderArray.pdf create mode 100644 itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/cmp_removedNestedDuplicatesInOrderArray.pdf create mode 100644 itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeDuplicatesHasChildInOrderArray.pdf create mode 100644 itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeDuplicatesInOrderArray.pdf create mode 100644 itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeNestedDuplicatesHasChildInOrderArray.pdf create mode 100644 itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeNestedDuplicatesInOrderArray.pdf diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfDocumentTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfDocumentTest.cs index 272f412bc7..32c9b14ac2 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfDocumentTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfDocumentTest.cs @@ -529,6 +529,62 @@ public virtual void GetDefaultConformanceLevelTest() { NUnit.Framework.Assert.IsNull(document.GetConformanceLevel()); } + //TODO DEVSIX-8490 remove this test when implemented + [NUnit.Framework.Test] + [LogMessage(KernelLogMessageConstant.DUPLICATE_ENTRIES_IN_ORDER_ARRAY_REMOVED)] + public virtual void RemoveDuplicatesInOrderArrayTest() { + String inputPdf = "removeDuplicatesInOrderArray.pdf"; + String outputPdf = "removedDuplicateInOrderArray.pdf"; + PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + inputPdf), CompareTool.CreateTestPdfWriter + (DESTINATION_FOLDER + outputPdf)); + //Need to update OCProperties + doc.GetCatalog().GetOCProperties(false); + doc.Close(); + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(DESTINATION_FOLDER + outputPdf, SOURCE_FOLDER + + "cmp_" + outputPdf, DESTINATION_FOLDER)); + } + + //TODO DEVSIX-8490 remove this test when implemented + [NUnit.Framework.Test] + [LogMessage(KernelLogMessageConstant.DUPLICATE_ENTRIES_IN_ORDER_ARRAY_REMOVED)] + public virtual void RemoveNestedDuplicatesInOrderArrayTest() { + String inputPdf = "removeNestedDuplicatesInOrderArray.pdf"; + String outputPdf = "removedNestedDuplicatesInOrderArray.pdf"; + PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + inputPdf), new PdfWriter(DESTINATION_FOLDER + + outputPdf)); + //Need to update OCProperties + doc.GetCatalog().GetOCProperties(false); + doc.Close(); + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(DESTINATION_FOLDER + outputPdf, SOURCE_FOLDER + + "cmp_" + outputPdf, DESTINATION_FOLDER)); + } + + //TODO DEVSIX-8490 remove this test when implemented + [NUnit.Framework.Test] + public virtual void RemoveDuplicatesHasChildInOrderArrayTest() { + String inputPdf = "removeDuplicatesHasChildInOrderArray.pdf"; + String outputPdf = "removedDuplicatesHasChildInOrderArray.pdf"; + PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + inputPdf), CompareTool.CreateTestPdfWriter + (DESTINATION_FOLDER + outputPdf)); + PdfCatalog catalog = doc.GetCatalog(); + Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => catalog.GetOCProperties(false)); + NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNABLE_TO_REMOVE_DUPLICATE_LAYER + , "4 0 R"), e.Message); + } + + //TODO DEVSIX-8490 remove this test when implemented + [NUnit.Framework.Test] + public virtual void RemoveNestedDuplicatesHasChildInOrderArrayTest() { + String inputPdf = "removeNestedDuplicatesHasChildInOrderArray.pdf"; + String outputPdf = "removedNestedDuplicatesHasChildInOrderArray.pdf"; + PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + inputPdf), CompareTool.CreateTestPdfWriter + (DESTINATION_FOLDER + outputPdf)); + PdfCatalog catalog = doc.GetCatalog(); + Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => catalog.GetOCProperties(false)); + NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNABLE_TO_REMOVE_DUPLICATE_LAYER + , "27 0 R"), e.Message); + } + private class IgnoreTagStructurePdfDocument : PdfDocument { //\cond DO_NOT_DOCUMENT internal IgnoreTagStructurePdfDocument(PdfReader reader) 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 b529d1b5dd..5a1073eb2d 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 @@ -24,6 +24,8 @@ You should have received a copy of the GNU Affero General Public License using System.Collections.Generic; using iText.Commons.Utils; using iText.IO.Font.Constants; +using iText.IO.Source; +using iText.Kernel.Exceptions; using iText.Kernel.Font; using iText.Kernel.Pdf; using iText.Kernel.Pdf.Canvas; @@ -354,5 +356,22 @@ public virtual void TestInStamperMode2() { NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "output_layered.pdf", sourceFolder + "cmp_output_layered.pdf", destinationFolder, "diff")); } + + //TODO DEVSIX-8490 remove this test when implemented + [NUnit.Framework.Test] + public virtual void AddSecondParentlayerTest() { + using (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + using (PdfDocument doc = new PdfDocument(new PdfWriter(outputStream))) { + PdfLayer childLayer = new PdfLayer("childLayer", doc); + PdfLayer parentLayer1 = new PdfLayer("firstParentLayer", doc); + PdfLayer parentLayer2 = new PdfLayer("secondParentLayer", doc); + parentLayer1.AddChild(childLayer); + PdfIndirectReference @ref = childLayer.GetIndirectReference(); + Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => parentLayer2.AddChild(childLayer)); + NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNABLE_TO_ADD_SECOND_PARENT_LAYER + , @ref.ToString()), e.Message); + } + } + } } } diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs new file mode 100644 index 0000000000..388a954aa1 --- /dev/null +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs @@ -0,0 +1,88 @@ +using System; +using System.IO; +using iText.Commons.Utils; +using iText.IO.Source; +using iText.Kernel.Exceptions; +using iText.Kernel.Pdf; + +namespace iText.Kernel.Pdf.Layer { + [NUnit.Framework.Category("UnitTest")] + public class PdfOCPropertiesUnitTest { + //TODO DEVSIX-8490 remove this test when implemented + [NUnit.Framework.Test] + public virtual void RemoveOrderDuplicatesTest() { + byte[] docBytes; + using (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + using (PdfDocument document = new PdfDocument(new PdfWriter(outputStream))) { + PdfDictionary ocgDic = new PdfDictionary(); + ocgDic.MakeIndirect(document); + PdfArray orderArray = new PdfArray(); + for (int i = 0; i < 3; i++) { + orderArray.Add(ocgDic); + } + PdfDictionary ocgDic2 = new PdfDictionary(); + ocgDic.MakeIndirect(document); + for (int i = 0; i < 3; i++) { + PdfArray layerArray = new PdfArray(); + layerArray.Add(new PdfString("layerName" + i)); + layerArray.Add(ocgDic2); + orderArray.Add(layerArray); + } + PdfDictionary DDictionary = new PdfDictionary(); + DDictionary.Put(PdfName.Order, orderArray); + PdfArray OCGsArray = new PdfArray(); + OCGsArray.Add(ocgDic); + OCGsArray.Add(ocgDic2); + PdfDictionary OCPropertiesDic = new PdfDictionary(); + OCPropertiesDic.Put(PdfName.D, DDictionary); + OCPropertiesDic.Put(PdfName.OCGs, OCGsArray); + document.GetCatalog().GetPdfObject().Put(PdfName.OCProperties, OCPropertiesDic); + document.GetCatalog().GetOCProperties(false); + } + docBytes = outputStream.ToArray(); + } + using (PdfDocument docReopen = new PdfDocument(new PdfReader(new MemoryStream(docBytes)))) { + PdfArray resultArray = docReopen.GetCatalog().GetPdfObject().GetAsDictionary(PdfName.OCProperties).GetAsDictionary + (PdfName.D).GetAsArray(PdfName.Order); + NUnit.Framework.Assert.AreEqual(2, resultArray.Size()); + } + } + + //TODO DEVSIX-8490 remove this test when implemented + [NUnit.Framework.Test] + public virtual void RemoveOrderDuplicateHasChildTest() { + using (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + using (PdfDocument document = new PdfDocument(new PdfWriter(outputStream))) { + PdfDictionary ocgDic = new PdfDictionary(); + PdfDictionary ocgDicChild1 = new PdfDictionary(); + PdfDictionary ocgDicChild2 = new PdfDictionary(); + ocgDic.MakeIndirect(document); + PdfArray orderArray = new PdfArray(); + PdfArray childArray1 = new PdfArray(); + childArray1.Add(ocgDicChild1); + PdfArray childArray2 = new PdfArray(); + childArray2.Add(ocgDicChild2); + orderArray.Add(ocgDic); + orderArray.Add(childArray1); + orderArray.Add(ocgDic); + orderArray.Add(childArray2); + PdfDictionary DDictionary = new PdfDictionary(); + DDictionary.Put(PdfName.Order, orderArray); + PdfArray OCGsArray = new PdfArray(); + OCGsArray.Add(ocgDic); + OCGsArray.Add(ocgDicChild1); + OCGsArray.Add(ocgDicChild2); + PdfDictionary OCPropertiesDic = new PdfDictionary(); + OCPropertiesDic.Put(PdfName.D, DDictionary); + OCPropertiesDic.Put(PdfName.OCGs, OCGsArray); + document.GetCatalog().GetPdfObject().Put(PdfName.OCProperties, OCPropertiesDic); + PdfIndirectReference @ref = ocgDic.GetIndirectReference(); + PdfCatalog catalog = document.GetCatalog(); + Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => catalog.GetOCProperties(false)); + NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNABLE_TO_REMOVE_DUPLICATE_LAYER + , @ref.ToString()), e.Message); + } + } + } + } +} diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/cmp_removedDuplicateInOrderArray.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/cmp_removedDuplicateInOrderArray.pdf new file mode 100644 index 0000000000000000000000000000000000000000..602e3a4c817cdf7cf59de275c0a63188b4a69e00 GIT binary patch literal 4528 zcmds5%WmT~6m8L+zk-`!Vibw^5Fcs-1F7AlgU-Z;6LjP8LJ}#Dio`M`rO5PK`UBnc zSGwpQv_DdkQew(f26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bQK1S@ zGNCF>IE|$cJmnb?hBe9pbH;SWq{-VP%Tgec$Aa+OoQefcXihiW~h6mHR-Pr*$v35rDgkwmHu45W6G4muMXPSB0V3reIsDiX_(Qi*Rf#P4 z%zLj@Ccn!c=GZ(2QGkR`7v5ABMg~z3ndvg$6p1d8falvHyLWcnep+j@ZK;PtOK(XD zG2*YHKC#L*NL&2@{y+mrZPBwW2wL8k1%UW1Qfq;QKhy#n%9;0E3uwo4FSH=)u>jx? zw1C>QIKYBeivjJ60sRj#pohhPy;>cxPBgb!1n>vOfE`u`tP}f}Wf8M2WWSOD{y+x$=RQ6~hG(X`0dx~MYK(dy{izEw8e4jS1=R`M=iw!MsX)Hc1g%JS9NbmHUjHxyGJ zbILHr+-F~7_6FlOC*J#9?FxjL5I^v@0!9h7Npx|X-Rg(x4>ZaPjl>x~3r}yZFQzv? zOm5MKW?C7fk5l zf}b5=+6!!*`xI~;uN`FTH3ymXB6nN?)~(^t)T;%|yeGAQH0f#qk#w~1`?P>)JEB3a z=;vHfXU&ch`>v?%>-7a>nWIJ6rv;3jr(98IYgY?MTnCx=B6o@w0zfrH0zH#e$6W_P-2UG=-WSCKbBbA6aG_h4_z*F-UM*&ZimNdmGB!Wvnio;ka$`hW%G}e*O zBGFuPpQlNxq)u=W8aS>s)j>e8Oe0Q3oSIKUbt07tLlVZ656=@GNJ153Qi>>&L@P|B zN)2LYJ~$dKytk_~M3ot M2S-QWPc8@l0_PQe8UO$Q literal 0 HcmV?d00001 diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeDuplicatesInOrderArray.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeDuplicatesInOrderArray.pdf new file mode 100644 index 0000000000000000000000000000000000000000..5afded545db526f8765dc843b82a5a394a801a72 GIT binary patch literal 4410 zcmd5=O>W~h6mHR-Pr*$vF^WXwqa;#oU?8<8>7X;Q;RM}yywDHjQIS}Nq_mlyr5EU? zSLvcR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30I_XnuIE*v9IBTQlLDK z(J&1J$SBo6F{n6965nTj1Y&UJ#{rWNDCT)eYOZPQds2a3Numg-KbSl3mT6A#8stp# tydqkUzSm!8zbZX0^wE8U7ugeYJwCyEY_F`sqQZ%y14GMDWR(?|kQfIGCJY9J3QSIQaXYKmQs?LP?SQJUBh|F7n&j zl-|W{T$^)~7TS34%yLnGBx*RU>e9q_gNNU~`U0LW2WF|)BKXS!gj=9dv8>Iqu80Mn zdhdErEzEFe&0C|4 zf%>b^XO`R=X~Q4k_jG_Y9zENGU~Bhf31I#fY3qT7-`4}1%BlBU4|pqbFZ3Yl@c`lX z^nly4*u#TY%K`7p0sjv<;QQr3yjmZKRyH?Pgz$UjKKCr`IM$<9Ns5+8$}lKSDPL zfWzZ*ZS~Q%oWbo$$q3pQ!t!-XM z39Mt)#{t*FQ{FZG*7gpYt<3_Fqh93J5NnlNZzNh5j+Sa~93D!O4Jh%&046*>T#+yc zpz$-ZmN5}R3)+V)H!>NxGGD-4>gow-^3miQfh7K1RMDAH1GO>&2 z`_5VJyRo7wg#FUxLZx!g25v5Spd7oDuJzcqUU+D?XV(U!ffIWgDTfP$&*6ed_E+16 zwEG&r+0-PLfpeBC>eL!nz7u-}!P>=ROgfyoQjQ*v>@?Zo61D5EF5~>xl=dI$x94Pb zDw8DDG)V%kgD4hM0L@6JDhWA=vOs3=EsX-1Y7_H}>X0cJ`%w}mN^_aYG~tPflu@aX zM*1>KGaZ|hrXj#dW4H+dM&m4!TqPO&q}-&j)?vuPgv;Tn3V8}WmqI;I6Y4~2;fqwo zCXPap>TEdo-Y&C(K=HwKcUlxR!F!2!o&RcJT)^r+z^mS|y+9u0O>a=uaarR;5m3v6 LgM;tK7lVHRM`c|Z literal 0 HcmV?d00001 diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeNestedDuplicatesInOrderArray.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeNestedDuplicatesInOrder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 z;fgd#Wuy|C_!>?q1Adds a child layer. Nested layers can only have one parent. /// the child layer public virtual void AddChild(iText.Kernel.Pdf.Layer.PdfLayer childLayer) { + //TODO DEVSIX-8490 implement multiple parent support if (childLayer.parent != null) { - throw new ArgumentException("Illegal argument: childLayer"); + PdfIndirectReference @ref = childLayer.GetIndirectReference(); + throw new PdfException(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNABLE_TO_ADD_SECOND_PARENT_LAYER + , @ref.ToString())); } childLayer.parent = this; if (children == null) { diff --git a/itext/itext.kernel/itext/kernel/pdf/layer/PdfOCProperties.cs b/itext/itext.kernel/itext/kernel/pdf/layer/PdfOCProperties.cs index 3bfbb72e00..f61c976b11 100644 --- a/itext/itext.kernel/itext/kernel/pdf/layer/PdfOCProperties.cs +++ b/itext/itext.kernel/itext/kernel/pdf/layer/PdfOCProperties.cs @@ -26,6 +26,7 @@ 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.Exceptions; using iText.Kernel.Logs; using iText.Kernel.Pdf; @@ -51,6 +52,12 @@ public class PdfOCProperties : PdfObjectWrapper { private IList layers = new List(); + //TODO DEVSIX-8490 remove this field when implemented + private ICollection references; + + //TODO DEVSIX-8490 remove this field when implemented + private bool isDuplicateRemoved; + /// Creates a new PdfOCProperties instance. /// the document the optional content belongs to public PdfOCProperties(PdfDocument document) @@ -406,7 +413,14 @@ private void ReadLayersFromDictionary() { } PdfArray orderArray = d.GetAsArray(PdfName.Order); if (orderArray != null && !orderArray.IsEmpty()) { + references = new HashSet(); + isDuplicateRemoved = false; ReadOrderFromDictionary(null, orderArray, layerMap); + //TODO DEVSIX-8490 remove this check when implemented + if (isDuplicateRemoved) { + ILogger logger = ITextLogManager.GetLogger(typeof(iText.Kernel.Pdf.Layer.PdfOCProperties)); + logger.LogWarning(KernelLogMessageConstant.DUPLICATE_ENTRIES_IN_ORDER_ARRAY_REMOVED); + } } } // Add the layers which should not be displayed on the panel to the order list @@ -424,7 +438,25 @@ private void ReadOrderFromDictionary(PdfLayer parent, PdfArray orderArray, IDict PdfObject item = orderArray.Get(i); if (item.GetObjectType() == PdfObject.DICTIONARY) { PdfLayer layer = layerMap.Get(item.GetIndirectReference()); - if (layer != null) { + if (layer == null) { + continue; + } + //TODO DEVSIX-8490 remove this check and it statement when implemented + if (references.Contains(layer.GetIndirectReference())) { + //We want to check if this duplicate layer has childLayers, if it has - throw an exception, + // else just don't add this layer. + if (i + 1 < orderArray.Size() && orderArray.Get(i + 1).GetObjectType() == PdfObject.ARRAY) { + PdfArray nextArray = orderArray.GetAsArray(i + 1); + if (nextArray.Size() > 0 && nextArray.Get(0).GetObjectType() != PdfObject.STRING) { + PdfIndirectReference @ref = layer.GetIndirectReference(); + throw new PdfException(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNABLE_TO_REMOVE_DUPLICATE_LAYER + , @ref.ToString())); + } + } + isDuplicateRemoved = true; + } + else { + references.Add(layer.GetIndirectReference()); layers.Add(layer); layer.onPanel = true; if (parent != null) { diff --git a/port-hash b/port-hash index 6174884e88..b79cbe289c 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -cd91477a6b5dcb768f827dfa4d1083fecb2c8f52 +1ee19dc92c5f07f9f932d3ffdf0748616ea1b8c3 From 5aef3d6821ccc98c3107c743f83518a084161b70 Mon Sep 17 00:00:00 2001 From: iText Software Date: Sun, 28 Jul 2024 14:09:21 +0000 Subject: [PATCH 2/2] Add missing copyright headers Autoported commit. Original commit hash: [c8f9dfd8a] --- .../pdf/layer/PdfOCPropertiesUnitTest.cs | 22 +++++++++++++++++++ port-hash | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs index 388a954aa1..f2a257799f 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs @@ -1,3 +1,25 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ using System; using System.IO; using iText.Commons.Utils; diff --git a/port-hash b/port-hash index b79cbe289c..2f5e19c137 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -1ee19dc92c5f07f9f932d3ffdf0748616ea1b8c3 +c8f9dfd8aab3ecfc3815c096cd36fa8109b9b0ab