public virtual void IsWrappedObjectMustBeIndirectTest()
        {
            PdfDictionary pdfObject = new PdfDictionary();
            PdfTarget     target    = PdfTarget.Create(pdfObject);

            NUnit.Framework.Assert.IsFalse(target.IsWrappedObjectMustBeIndirect());
        }
        public virtual void CreateChildInstanceTest()
        {
            PdfTarget     target     = PdfTarget.CreateChildTarget();
            PdfDictionary dictionary = target.GetPdfObject();

            NUnit.Framework.Assert.AreEqual(PdfName.C, dictionary.Get(PdfName.R));
        }
        public virtual void CreateInstanceTest()
        {
            PdfDictionary dictionary = new PdfDictionary();
            PdfTarget     target     = PdfTarget.Create(dictionary);

            NUnit.Framework.Assert.AreEqual(dictionary, target.GetPdfObject());
        }
        public virtual void NamePropertyTest()
        {
            String    name   = "Name";
            PdfTarget target = PdfTarget.Create(new PdfDictionary());

            target.SetName(name);
            NUnit.Framework.Assert.AreEqual(name, target.GetName());
            NUnit.Framework.Assert.AreEqual(new PdfString(name), target.GetPdfObject().Get(PdfName.N));
        }
        public virtual void CreateChildInstanceWithEmbeddedFileTest()
        {
            String        embeddedFileName = "EmbeddedFileName.file";
            PdfTarget     target           = PdfTarget.CreateChildTarget(embeddedFileName);
            PdfDictionary dictionary       = target.GetPdfObject();

            NUnit.Framework.Assert.AreEqual(PdfName.C, dictionary.Get(PdfName.R));
            NUnit.Framework.Assert.AreEqual(new PdfString(embeddedFileName), dictionary.Get(PdfName.N));
        }
        public virtual void CreateChildInstanceWithPageNumberTest()
        {
            int           pageNumber      = 23;
            int           annotationIndex = 7;
            PdfTarget     target          = PdfTarget.CreateChildTarget(pageNumber, annotationIndex);
            PdfDictionary dictionary      = target.GetPdfObject();

            NUnit.Framework.Assert.AreEqual(PdfName.C, dictionary.Get(PdfName.R));
            NUnit.Framework.Assert.AreEqual(new PdfNumber(pageNumber - 1), dictionary.Get(PdfName.P));
            NUnit.Framework.Assert.AreEqual(new PdfNumber(annotationIndex), dictionary.Get(PdfName.A));
        }
        public virtual void PutTest()
        {
            PdfName       key1       = new PdfName("Key1");
            PdfName       key2       = new PdfName("Key2");
            PdfDictionary dictionary = new PdfDictionary();
            PdfTarget     target     = PdfTarget.Create(dictionary);

            target.Put(key1, new PdfNumber(23)).Put(key2, new PdfString("Hello, world!"));
            NUnit.Framework.Assert.AreEqual(23, dictionary.GetAsNumber(key1).IntValue());
            NUnit.Framework.Assert.AreEqual("Hello, world!", dictionary.GetAsString(key2).GetValue());
        }
        public virtual void CreateChildInstanceWithNamedDestinationTest()
        {
            String        namedDestination     = "namedDestination";
            String        annotationIdentifier = "annotationIdentifier";
            PdfTarget     target     = PdfTarget.CreateChildTarget(namedDestination, annotationIdentifier);
            PdfDictionary dictionary = target.GetPdfObject();

            NUnit.Framework.Assert.AreEqual(PdfName.C, dictionary.Get(PdfName.R));
            NUnit.Framework.Assert.AreEqual(new PdfString(namedDestination), dictionary.Get(PdfName.P));
            NUnit.Framework.Assert.AreEqual(new PdfString(annotationIdentifier), dictionary.Get(PdfName.A));
        }
 public virtual void GetAnnotationSetAsIntsTest()
 {
     using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
         int       pageNumber      = 1;
         int       annotationIndex = 0;
         PdfTarget target          = PdfTarget.CreateChildTarget(pageNumber, annotationIndex);
         PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20));
         document.AddNewPage();
         document.GetPage(1).AddAnnotation(annotation);
         NUnit.Framework.Assert.AreEqual(annotation.GetPdfObject(), target.GetAnnotation(document).GetPdfObject());
     }
 }
 public virtual void SetAnnotationWithoutPageTest()
 {
     NUnit.Framework.Assert.That(() => {
         using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
             document.AddNewPage();
             PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20));
             PdfTarget target = PdfTarget.Create(new PdfDictionary());
             target.SetAnnotation(annotation, document);
         }
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfException>().With.Message.EqualTo(PdfException.AnnotationShallHaveReferenceToPage))
     ;
 }
 public virtual void GetAnnotationSetAsAnnotationTest()
 {
     using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
         PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20));
         document.AddNewPage();
         document.GetPage(1).AddAnnotation(annotation);
         PdfDictionary content = new PdfDictionary();
         content.Put(new PdfName("Key"), new PdfString("Value"));
         PdfTarget target = PdfTarget.Create(new PdfDictionary());
         target.SetAnnotation(annotation, document);
         NUnit.Framework.Assert.AreEqual(annotation.GetPdfObject(), target.GetAnnotation(document).GetPdfObject());
     }
 }
 public virtual void GetAnnotationSetAsStringNotAvailableTest()
 {
     using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
         String    namedDestination     = "namedDestination";
         String    annotationIdentifier = "annotationIdentifier";
         PdfTarget target = PdfTarget.CreateChildTarget(namedDestination, annotationIdentifier);
         document.AddNewPage();
         document.GetCatalog().GetNameTree(PdfName.Dests).AddEntry(namedDestination, new PdfArray(new PdfNumber(1))
                                                                   );
         PdfAnnotation annotation = target.GetAnnotation(document);
         NUnit.Framework.Assert.IsNull(annotation);
     }
 }
        public virtual void TargetPropertyTest()
        {
            PdfDictionary oldDictionary = new PdfDictionary();

            oldDictionary.Put(new PdfName("Id"), new PdfString("Old"));
            PdfDictionary newDictionary = new PdfDictionary();

            newDictionary.Put(new PdfName("Id"), new PdfString("New"));
            PdfTarget target = PdfTarget.Create(oldDictionary);

            target.SetTarget(PdfTarget.Create(newDictionary));
            NUnit.Framework.Assert.AreEqual(newDictionary, target.GetTarget().GetPdfObject());
            NUnit.Framework.Assert.AreEqual(newDictionary, target.GetPdfObject().Get(PdfName.T));
        }
 public virtual void GetAnnotationSetAsStringTest()
 {
     using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
         String    namedDestination     = "namedDestination";
         String    annotationIdentifier = "annotationIdentifier";
         PdfTarget target = PdfTarget.CreateChildTarget(namedDestination, annotationIdentifier);
         PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20));
         annotation.SetName(new PdfString(annotationIdentifier));
         document.AddNewPage();
         document.GetPage(1).AddAnnotation(annotation);
         document.GetCatalog().GetNameTree(PdfName.Dests).AddEntry(namedDestination, new PdfArray(new PdfNumber(1))
                                                                   );
         PdfAnnotation retrievedAnnotation = target.GetAnnotation(document);
         NUnit.Framework.Assert.AreEqual(annotation.GetPdfObject(), retrievedAnnotation.GetPdfObject());
     }
 }
 public virtual void SetAnnotationTest()
 {
     using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
         PdfFileAttachmentAnnotation annotation0 = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20));
         PdfFileAttachmentAnnotation annotation1 = new PdfFileAttachmentAnnotation(new Rectangle(1, 1, 21, 21));
         PdfFileAttachmentAnnotation annotation2 = new PdfFileAttachmentAnnotation(new Rectangle(2, 2, 22, 22));
         document.AddNewPage();
         document.GetPage(1).AddAnnotation(annotation0);
         document.GetPage(1).AddAnnotation(annotation1);
         document.GetPage(1).AddAnnotation(annotation2);
         PdfTarget target = PdfTarget.Create(new PdfDictionary());
         target.SetAnnotation(annotation2, document);
         PdfDictionary dictionary = target.GetPdfObject();
         NUnit.Framework.Assert.AreEqual(0, dictionary.GetAsNumber(PdfName.P).IntValue());
         NUnit.Framework.Assert.AreEqual(2, dictionary.GetAsNumber(PdfName.A).IntValue());
     }
 }
Example #16
0
 /// <summary>Creates a GoToE action, or embedded file action (section 12.6.4.4 of ISO 32000-1).</summary>
 /// <param name="fileSpec">The root document of the target relative to the root document of the source</param>
 /// <param name="destination">the destination in the target to jump to</param>
 /// <param name="newWindow">
 /// if true, the destination document should be opened in a new window;
 /// if false, the destination document should replace the current document in the same window
 /// </param>
 /// <param name="targetDictionary">
 /// A target dictionary specifying path information to the target document.
 /// Each target dictionary specifies one element in the full path to the target and
 /// may have nested target dictionaries specifying additional elements
 /// </param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoToE(PdfFileSpec fileSpec, PdfDestination destination
                                                             , bool newWindow, PdfTarget targetDictionary)
 {
     iText.Kernel.Pdf.Action.PdfAction action = new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.
                                                                                            GoToE).Put(PdfName.NewWindow, PdfBoolean.ValueOf(newWindow));
     if (fileSpec != null)
     {
         action.Put(PdfName.F, fileSpec.GetPdfObject());
     }
     if (destination != null)
     {
         action.Put(PdfName.D, destination.GetPdfObject());
     }
     if (targetDictionary != null)
     {
         action.Put(PdfName.T, targetDictionary.GetPdfObject());
     }
     return(action);
 }
Example #17
0
 /// <summary>Creates a GoToE action, or embedded file action (section 12.6.4.4 of ISO 32000-1).</summary>
 /// <param name="fileSpec">The root document of the target relative to the root document of the source</param>
 /// <param name="destination">the destination in the target to jump to</param>
 /// <param name="newWindow">
 /// if true, the destination document should be opened in a new window;
 /// if false, the destination document should replace the current document in the same window
 /// </param>
 /// <param name="targetDictionary">
 /// A target dictionary specifying path information to the target document.
 /// Each target dictionary specifies one element in the full path to the target and
 /// may have nested target dictionaries specifying additional elements
 /// </param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoToE(PdfFileSpec fileSpec, PdfDestination destination
                                                             , bool newWindow, PdfTarget targetDictionary)
 {
     iText.Kernel.Pdf.Action.PdfAction action = new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.
                                                                                            GoToE).Put(PdfName.NewWindow, PdfBoolean.ValueOf(newWindow));
     if (fileSpec != null)
     {
         action.Put(PdfName.F, fileSpec.GetPdfObject());
     }
     if (destination != null)
     {
         ValidateRemoteDestination(destination);
         action.Put(PdfName.D, destination.GetPdfObject());
     }
     else
     {
         LogManager.GetLogger(typeof(iText.Kernel.Pdf.Action.PdfAction)).Warn(iText.IO.LogMessageConstant.EMBEDDED_GO_TO_DESTINATION_NOT_SPECIFIED
                                                                              );
     }
     if (targetDictionary != null)
     {
         action.Put(PdfName.T, targetDictionary.GetPdfObject());
     }
     return(action);
 }
Example #18
0
 /// <summary>Creates a GoToE action, or embedded file action (section 12.6.4.4 of ISO 32000-1).</summary>
 /// <param name="destination">the destination in the target to jump to</param>
 /// <param name="newWindow">
 /// if true, the destination document should be opened in a new window;
 /// if false, the destination document should replace the current document in the same window
 /// </param>
 /// <param name="targetDictionary">
 /// A target dictionary specifying path information to the target document.
 /// Each target dictionary specifies one element in the full path to the target and
 /// may have nested target dictionaries specifying additional elements
 /// </param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoToE(PdfDestination destination, bool newWindow, PdfTarget
                                                             targetDictionary)
 {
     return(CreateGoToE(null, destination, newWindow, targetDictionary));
 }