Esempio n. 1
0
        public virtual Rectangle GetMediaBox()
        {
            InitParentPages();
            PdfArray mediaBox = GetPdfObject().GetAsArray(PdfName.MediaBox);

            if (mediaBox == null)
            {
                mediaBox = (PdfArray)GetParentValue(parentPages, PdfName.MediaBox);
            }
            return(mediaBox.ToRectangle());
        }
        public virtual void MediaBoxInheritance()
        {
            String      inputFileName = sourceFolder + "mediaBoxInheritanceTestSource.pdf";
            PdfDocument outFile       = new PdfDocument(new PdfReader(inputFileName));
            PdfObject   mediaBox      = outFile.GetPage(1).GetPdfObject().Get(PdfName.MediaBox);

            //Check if MediaBox in Page is absent
            NUnit.Framework.Assert.IsNull(mediaBox);
            PdfArray array = outFile.GetCatalog().GetPdfObject().GetAsDictionary(PdfName.Pages).GetAsArray(PdfName.MediaBox
                                                                                                           );
            Rectangle rectangle = array.ToRectangle();
            Rectangle pageRect  = outFile.GetPage(1).GetMediaBox();

            outFile.Close();
            NUnit.Framework.Assert.IsTrue(rectangle.EqualsWithEpsilon(pageRect));
        }
Esempio n. 3
0
 private void CopyInheritedProperties(iText.Kernel.Pdf.PdfPage copyPdfPage, PdfDocument pdfDocument)
 {
     if (copyPdfPage.GetPdfObject().Get(PdfName.Resources) == null)
     {
         PdfObject copyResource = pdfDocument.GetWriter().CopyObject(GetResources().GetPdfObject(), pdfDocument, false
                                                                     );
         copyPdfPage.GetPdfObject().Put(PdfName.Resources, copyResource);
     }
     if (copyPdfPage.GetPdfObject().Get(PdfName.MediaBox) == null)
     {
         copyPdfPage.SetMediaBox(GetMediaBox());
     }
     if (copyPdfPage.GetPdfObject().Get(PdfName.CropBox) == null)
     {
         InitParentPages();
         PdfArray cropBox = (PdfArray)GetParentValue(parentPages, PdfName.CropBox);
         if (cropBox != null)
         {
             copyPdfPage.SetCropBox(cropBox.ToRectangle());
         }
     }
 }
Esempio n. 4
0
        /// <summary>Returns the value associated to this key as a Rectangle.</summary>
        /// <remarks>
        /// Returns the value associated to this key as a Rectangle. If the value isn't a PdfArray of which the
        /// firt four elements are PdfNumbers, null is returned.
        /// </remarks>
        /// <param name="key">the key of which the associated value needs to be returned</param>
        /// <returns>PdfArray associated with this key</returns>
        /// <seealso cref="PdfArray.ToRectangle()"/>
        public virtual Rectangle GetAsRectangle(PdfName key)
        {
            PdfArray a = GetAsArray(key);

            return(a == null ? null : a.ToRectangle());
        }