diff --git a/itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs index 0fda61cb08..5f0a494db0 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs @@ -783,6 +783,26 @@ public virtual void CopyOnlyEmptyOcPropertiesTest() { , destinationFolder, "diff_")); } + [LogMessage(iText.IO.Logs.IoLogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)] + [NUnit.Framework.Test] + public virtual void CombineTagRootKidsTest() { + String filename1 = sourceFolder + "tagRootKidsDoc1.pdf"; + String filename2 = sourceFolder + "tagRootKidsDoc2.pdf"; + String resultFile = destinationFolder + "mergedTags.pdf"; + PdfDocument result = new PdfDocument(CompareTool.CreateTestPdfWriter(resultFile)); + PdfMerger merger = new PdfMerger(result, new PdfMergerProperties().SetMergeTags(true).SetMergeOutlines(true + )).SetCloseSourceDocuments(true); + PdfDocument input1 = new PdfDocument(new PdfReader(filename1)); + merger.Merge(input1, 1, 1); + input1.Close(); + PdfDocument input2 = new PdfDocument(new PdfReader(filename2)); + merger.Merge(input2, 1, 1); + input2.Close(); + merger.Close(); + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(resultFile, sourceFolder + "cmp_mergedTags.pdf" + , destinationFolder, "diff_")); + } + private PdfDictionary MergeSinglePdfAndGetResultingStructTreeRoot(String pathToMerge) { IList sources = new List(); sources.Add(new FileInfo(sourceFolder + pathToMerge)); diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergedResult04.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergedResult04.pdf index f362958bff..6bbe3fdc55 100644 Binary files a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergedResult04.pdf and b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergedResult04.pdf differ diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergedTags.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergedTags.pdf new file mode 100644 index 0000000000..e0c63b3f78 Binary files /dev/null and b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergedTags.pdf differ diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/tagRootKidsDoc1.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/tagRootKidsDoc1.pdf new file mode 100644 index 0000000000..102a320161 Binary files /dev/null and b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/tagRootKidsDoc1.pdf differ diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/tagRootKidsDoc2.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/tagRootKidsDoc2.pdf new file mode 100644 index 0000000000..a07b23bd54 Binary files /dev/null and b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/tagRootKidsDoc2.pdf differ diff --git a/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs b/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs index 1f8966cf77..fa8bc0f29d 100644 --- a/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs +++ b/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs @@ -67,10 +67,29 @@ public virtual void BasicThreeColumnsTest() { )); } + [NUnit.Framework.Test] + public virtual void BorderBoxWithNoBordersTest() { + String filename = DESTINATION_FOLDER + "borderBoxWithNoBordersTest.pdf"; + String cmpName = SOURCE_FOLDER + "cmp_borderBoxWithNoBordersTest.pdf"; + IList templateColumns = new List(); + templateColumns.Add(new PointValue(150.0f)); + templateColumns.Add(new PointValue(150.0f)); + using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { + GridContainer grid = new GridContainer(); + grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, templateColumns); + Paragraph child = new Paragraph("First"); + child.SetProperty(Property.BOX_SIZING, BoxSizingPropertyValue.BORDER_BOX); + grid.Add(child); + document.Add(grid); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_" + )); + } + [NUnit.Framework.Test] public virtual void BasicTwoColumnsTest() { - String filename = DESTINATION_FOLDER + "basicTwoColumnsTest.pdf"; - String cmpName = SOURCE_FOLDER + "cmp_basicTwoColumnsTest.pdf"; + String filename = DESTINATION_FOLDER + "borderBoxChild.pdf"; + String cmpName = SOURCE_FOLDER + "cmp_borderBoxChild.pdf"; IList templateColumns = new List(); templateColumns.Add(new PointValue(150.0f)); templateColumns.Add(new PointValue(150.0f)); diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_basicThreeColumnsTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_basicThreeColumnsTest.pdf index 89371e7953..0aa4e37347 100644 Binary files a/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_basicThreeColumnsTest.pdf and b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_basicThreeColumnsTest.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_borderBoxChild.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_borderBoxChild.pdf new file mode 100644 index 0000000000..b8387843b9 Binary files /dev/null and b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_borderBoxChild.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_borderBoxWithNoBordersTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_borderBoxWithNoBordersTest.pdf new file mode 100644 index 0000000000..db964dcf55 Binary files /dev/null and b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_borderBoxWithNoBordersTest.pdf differ diff --git a/itext/itext.kernel/itext/kernel/pdf/tagging/PdfStructTreeRoot.cs b/itext/itext.kernel/itext/kernel/pdf/tagging/PdfStructTreeRoot.cs index 7a6d371016..7e95ffa915 100644 --- a/itext/itext.kernel/itext/kernel/pdf/tagging/PdfStructTreeRoot.cs +++ b/itext/itext.kernel/itext/kernel/pdf/tagging/PdfStructTreeRoot.cs @@ -369,18 +369,6 @@ public virtual PdfMcr FindMcrByMcid(PdfDictionary pageDict, int mcid) { return GetParentTreeHandler().FindMcrByMcid(pageDict, mcid); } - public virtual PdfMcr FindMcrByMcid(PdfDocument document, int mcid) { - int amountOfPages = document.GetNumberOfPages(); - for (int i = 1; i <= amountOfPages; ++i) { - PdfPage page = document.GetPage(i); - PdfMcr mcr = FindMcrByMcid(page.GetPdfObject(), mcid); - if (mcr != null) { - return mcr; - } - } - return null; - } - public virtual PdfObjRef FindObjRefByStructParentIndex(PdfDictionary pageDict, int structParentIndex) { return GetParentTreeHandler().FindObjRefByStructParentIndex(pageDict, structParentIndex); } diff --git a/itext/itext.kernel/itext/kernel/pdf/tagutils/RootTagNormalizer.cs b/itext/itext.kernel/itext/kernel/pdf/tagutils/RootTagNormalizer.cs index b3deb89bd6..ec08ccc492 100644 --- a/itext/itext.kernel/itext/kernel/pdf/tagutils/RootTagNormalizer.cs +++ b/itext/itext.kernel/itext/kernel/pdf/tagutils/RootTagNormalizer.cs @@ -113,8 +113,10 @@ private void AddStructTreeRootKidsToTheRootTag(IList rootKids) { } // This boolean is used to "flatten" possible deep "stacking" of the tag structure in case of the multiple pages copying operations. // This could happen due to the wrapping of all the kids in the createNewRootTag or ensureExistingRootTagIsDocument methods. - // And therefore, we don't need here to resolve mappings, because we exactly know which role we set. - bool kidIsDocument = PdfName.Document.Equals(kid.GetRole()); + IRoleMappingResolver mapping = kid.GetRole() == null ? null : context.ResolveMappingToStandardOrDomainSpecificRole + (kid.GetRole().GetValue(), rootTagElement.GetNamespace()); + bool kidIsDocument = mapping != null && mapping.CurrentRoleIsStandard() && StandardRoles.DOCUMENT.Equals(mapping + .GetRole()); if (kidIsDocument && kid.GetNamespace() != null && context.TargetTagStructureVersionIs2()) { // we flatten only tags of document role in standard structure namespace String kidNamespaceName = kid.GetNamespace().GetNamespaceName(); diff --git a/itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs b/itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs index a85d8aec8c..15ec494643 100644 --- a/itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs +++ b/itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs @@ -160,7 +160,9 @@ internal virtual float CalculateHeight(float initialHeight) { rectangle.DecreaseHeight(paddingBottom.GetValue()); } Border borderBottom = renderer.GetBorders()[AbstractRenderer.BOTTOM_SIDE]; - rectangle.DecreaseHeight(borderBottom.GetWidth()); + if (borderBottom != null) { + rectangle.DecreaseHeight(borderBottom.GetWidth()); + } } else { renderer.ApplyMarginsBordersPaddings(rectangle, false); diff --git a/itext/itext.pdfua/itext/pdfua/checkers/PdfUA1Checker.cs b/itext/itext.pdfua/itext/pdfua/checkers/PdfUA1Checker.cs index f4973b2596..0b9aeec0df 100644 --- a/itext/itext.pdfua/itext/pdfua/checkers/PdfUA1Checker.cs +++ b/itext/itext.pdfua/itext/pdfua/checkers/PdfUA1Checker.cs @@ -255,8 +255,7 @@ private bool IsRealContent(Tuple2 tag) { if (properties == null || !properties.ContainsKey(PdfName.MCID)) { return false; } - PdfMcr mcr = this.pdfDocument.GetStructTreeRoot().FindMcrByMcid(pdfDocument, (int)properties.GetAsInt(PdfName - .MCID)); + PdfMcr mcr = McrExists(pdfDocument, (int)properties.GetAsInt(PdfName.MCID)); if (mcr == null) { throw new PdfUAConformanceException(PdfUAExceptionMessageConstants.CONTENT_WITH_MCID_BUT_MCID_NOT_FOUND_IN_STRUCT_TREE_ROOT ); @@ -264,6 +263,18 @@ private bool IsRealContent(Tuple2 tag) { return true; } + private PdfMcr McrExists(PdfDocument document, int mcid) { + int amountOfPages = document.GetNumberOfPages(); + for (int i = 1; i <= amountOfPages; ++i) { + PdfPage page = document.GetPage(i); + PdfMcr mcr = document.GetStructTreeRoot().FindMcrByMcid(page.GetPdfObject(), mcid); + if (mcr != null) { + return mcr; + } + } + return null; + } + private void CheckCatalog(PdfCatalog catalog) { PdfDictionary catalogDict = catalog.GetPdfObject(); if (!catalogDict.ContainsKey(PdfName.Metadata)) { diff --git a/port-hash b/port-hash index fb6a48d90b..0e7b1735f1 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -280e61ecff65c45495a10a43f25b8c66bd34149e +b8f684a0dd103255900f1cf090e811e8c2444b11