forked from pipeline-foundation/itext7-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVSIX-8396 Autoported commit. Original commit hash: [1ee19dc92]
- Loading branch information
Showing
14 changed files
with
212 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} | ||
} |
Binary file added
BIN
+4.42 KB
...nel.tests/resources/itext/kernel/pdf/PdfDocumentTest/cmp_removedDuplicateInOrderArray.pdf
Binary file not shown.
Binary file added
BIN
+4.34 KB
...ts/resources/itext/kernel/pdf/PdfDocumentTest/cmp_removedNestedDuplicatesInOrderArray.pdf
Binary file not shown.
Binary file added
BIN
+4.21 KB
...tests/resources/itext/kernel/pdf/PdfDocumentTest/removeDuplicatesHasChildInOrderArray.pdf
Binary file not shown.
Binary file added
BIN
+4.31 KB
....kernel.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeDuplicatesInOrderArray.pdf
Binary file not shown.
Binary file added
BIN
+4.09 KB
...resources/itext/kernel/pdf/PdfDocumentTest/removeNestedDuplicatesHasChildInOrderArray.pdf
Binary file not shown.
Binary file added
BIN
+4.2 KB
...l.tests/resources/itext/kernel/pdf/PdfDocumentTest/removeNestedDuplicatesInOrderArray.pdf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
cd91477a6b5dcb768f827dfa4d1083fecb2c8f52 | ||
1ee19dc92c5f07f9f932d3ffdf0748616ea1b8c3 |