/// <summary>
        /// Convert a standard page size to its dimensions.
        /// </summary>
        /// <param name="pageSize">The physical page size to convert.</param>
        /// <param name="orientation">The orientation of the page.  "Arbitrary" orientation returns the same dimensions as portrait orientation.</param>
        /// <returns>A <see cref="UniSize" /> instance representing the physical dimensions of the paper size, in points.</returns>
        public static UniSize ToUniSize(this PhysicalPageSize pageSize, PageOrientation orientation)
        {
            if (orientation != PageOrientation.Landscape)
            {
                return(pageSize.ToUniSize());
            }
            switch (pageSize)
            {
            case PhysicalPageSize.A1:
                return(_a1Landscape.Value);

            case PhysicalPageSize.A2:
                return(_a2Landscape.Value);

            case PhysicalPageSize.A3:
                return(_a3Landscape.Value);

            case PhysicalPageSize.A4:
                return(_a4Landscape.Value);

            case PhysicalPageSize.A5:
                return(_a5Landscape.Value);

            case PhysicalPageSize.A6:
                return(_a6Landscape.Value);

            default:
                throw new ArgumentOutOfRangeException(nameof(pageSize));
            }
        }
        /// <summary>
        /// Value-setting constructor.
        /// </summary>
        /// <param name="parent">The parent node of this page in the document page tree.</param>
        /// <param name="objectId">The indirect object ID of this page.</param>
        /// <param name="size">The paper size of this page.</param>
        /// <param name="orientation">The orientation of this page.</param>
        /// <param name="horizontalMarginProportion">The proportion of the page taken up by each of the left and right margins.</param>
        /// <param name="verticalMarginProportion">The proportion of the page taken up by each of the top and bottom margins.</param>
        /// <param name="generation">The object generation number.  Defaults to zero.  As we do not currently support rewriting existing documents, this should not be set.</param>
        public PdfPage(
            PdfPageTreeNode parent,
            int objectId,
            PhysicalPageSize size,
            PageOrientation orientation,
            double horizontalMarginProportion,
            double verticalMarginProportion,
            int generation = 0)
            : base(parent, objectId, generation)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            PageSize        = size;
            PageOrientation = orientation;

            UniSize pagePtSize = size.ToUniSize(orientation);

            TopMarginPosition     = pagePtSize.Height * verticalMarginProportion;
            BottomMarginPosition  = pagePtSize.Height - TopMarginPosition;
            LeftMarginPosition    = pagePtSize.Width * horizontalMarginProportion;
            RightMarginPosition   = pagePtSize.Width - LeftMarginPosition;
            PageAvailableWidth    = RightMarginPosition - LeftMarginPosition;
            CurrentVerticalCursor = TopMarginPosition;
            MediaBox = size.ToPdfRectangle(orientation);
        }
        public void PhysicalPageSizeExtensionsClass_ToUniSizeMethodWithOneParameter_ThrowsArgumentOutOfRangeExceptionWhenParameterIsLessThanZero()
        {
            PhysicalPageSize testParam0 = (PhysicalPageSize)(_rnd.Next(2048) * -1 - 1);

            testParam0.ToUniSize();

            Assert.Fail();
        }
        public void PhysicalPageSizeExtensionsClass_ToUniSizeMethodWithOneParameter_ThrowsArgumentOutOfRangeExceptionWhenParameterIsEqualToSix()
        {
            PhysicalPageSize testParam0 = (PhysicalPageSize)6;

            testParam0.ToUniSize();

            Assert.Fail();
        }
        public void PhysicalPageSizeExtensionsClass_ToUniSizeMethodWithTwoParameters_ThrowsArgumentOutOfRangeExceptionWhenFirstParameterIsGreaterThanSixAndSecondParameterEqualsArbitrary()
        {
            PhysicalPageSize testParam0 = (PhysicalPageSize)(6 + _rnd.Next(2048));
            PageOrientation  testParam1 = PageOrientation.Arbitrary;

            testParam0.ToUniSize(testParam1);

            Assert.Fail();
        }
        public void PhysicalPageSizeExtensionsClass_ToUniSizeMethodWithOneParameter_ReturnsCorrectValueWhenParameterEqualsA6()
        {
            PhysicalPageSize testParam0 = PhysicalPageSize.A6;

            UniSize testOutput = testParam0.ToUniSize();

            Assert.AreEqual(297, testOutput.Width);
            Assert.AreEqual(419, testOutput.Height);
        }
        public void PhysicalPageSizeExtensionsClass_ToUniSizeMethodWithTwoParameters_ThrowsArgumentOutOfRangeExceptionWhenFirstParameterIsEqualToSixAndSecondParameterEqualsLandscape()
        {
            PhysicalPageSize testParam0 = (PhysicalPageSize)6;
            PageOrientation  testParam1 = PageOrientation.Landscape;

            testParam0.ToUniSize(testParam1);

            Assert.Fail();
        }
        public void PhysicalPageSizeExtensionsClass_ToUniSizeMethodWithTwoParameters_ThrowsArgumentOutOfRangeExceptionWhenFirstParameterIsLessThanZeroAndSecondParameterEqualsPortrait()
        {
            PhysicalPageSize testParam0 = (PhysicalPageSize)(_rnd.Next(2048) * -1 - 1);
            PageOrientation  testParam1 = PageOrientation.Portrait;

            testParam0.ToUniSize(testParam1);

            Assert.Fail();
        }
        public void PhysicalPageSizeExtensionsClass_ToUniSizeMethodWithTwoParameters_ReturnsCorrectValueWhenFirstParameterEqualsA6AndSecondParameterEqualsArbitrary()
        {
            PhysicalPageSize testParam0 = PhysicalPageSize.A6;
            PageOrientation  testParam1 = PageOrientation.Arbitrary;

            UniSize testOutput = testParam0.ToUniSize(testParam1);

            Assert.AreEqual(297, testOutput.Width);
            Assert.AreEqual(419, testOutput.Height);
        }
        public void PhysicalPageSizeExtensionsClass_ToUniSizeMethodWithTwoParameters_ReturnsCorrectValueWhenFirstParameterEqualsA4AndSecondParameterEqualsLandscape()
        {
            PhysicalPageSize testParam0 = PhysicalPageSize.A4;
            PageOrientation  testParam1 = PageOrientation.Landscape;

            UniSize testOutput = testParam0.ToUniSize(testParam1);

            Assert.AreEqual(595, testOutput.Height);
            Assert.AreEqual(841, testOutput.Width);
        }
        public void PhysicalPageSizeExtensionsClass_ToUniSizeMethodWithTwoParameters_ReturnsCorrectValueWhenFirstParameterEqualsA3AndSecondParameterEqualsPortrait()
        {
            PhysicalPageSize testParam0 = PhysicalPageSize.A3;
            PageOrientation  testParam1 = PageOrientation.Portrait;

            UniSize testOutput = testParam0.ToUniSize(testParam1);

            Assert.AreEqual(841, testOutput.Width);
            Assert.AreEqual(1190, testOutput.Height);
        }
 /// <summary>
 /// Convert a <see cref="PhysicalPageSize" /> value to a <see cref="PdfRectangle" /> representing the size of the page.
 /// </summary>
 /// <param name="pageSize">The page size to be converted.</param>
 /// <param name="orientation">The orientation of the page.</param>
 /// <returns>A <see cref="PdfRectangle" /> instance containing the dimensions of the page (in portrait orientation).
 /// The first coordinate pair is (0,0); the second is (width, height).</returns>
 public static PdfRectangle ToPdfRectangle(this PhysicalPageSize pageSize, PageOrientation orientation)
 {
     return(pageSize.ToUniSize(orientation).ToPdfRectangle());
 }
 /// <summary>
 /// Convert a <see cref="PhysicalPageSize" /> value to a <see cref="PdfRectangle" /> representing the size of the page.
 /// </summary>
 /// <param name="pageSize">The page size to be converted.</param>
 /// <returns>A <see cref="PdfRectangle" /> instance containing the dimensions of the page (in portrait orientation).
 /// The first coordinate pair is (0,0); the second is (width, height).</returns>
 public static PdfRectangle ToPdfRectangle(this PhysicalPageSize pageSize)
 {
     return(pageSize.ToUniSize().ToPdfRectangle());
 }