Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
 private static void ValidateRemoteDestination(PdfDestination destination)
 {
     // No page object can be specified for a destination associated with a remote go-to action because the
     // destination page is in a different PDF document. In this case, the page parameter specifies an integer
     // page number within the remote document instead of a page object in the current document.
     // See section 12.3.2.2 of ISO 32000-1.
     if (destination is PdfExplicitDestination)
     {
         PdfObject firstObj = ((PdfArray)destination.GetPdfObject()).Get(0);
         if (firstObj.IsDictionary())
         {
             throw new ArgumentException("Explicit destinations shall specify page number in remote go-to actions instead of page dictionary"
                                         );
         }
     }
     else
     {
         if (destination is PdfStructureDestination)
         {
             // No structure element dictionary can be specified for a structure destination associated with a remote
             // go-to action because the destination structure element is in a
             // different PDF document. In this case, the indirect reference to the structure element dictionary shall be
             // replaced by a byte string representing a structure element ID
             PdfObject firstObj = ((PdfArray)destination.GetPdfObject()).Get(0);
             if (firstObj.IsDictionary())
             {
                 PdfDictionary structElemObj = (PdfDictionary)firstObj;
                 PdfString     id            = structElemObj.GetAsString(PdfName.ID);
                 if (id == null)
                 {
                     throw new ArgumentException("Structure destinations shall specify structure element ID in remote go-to actions. Structure element that has no ID is specified instead"
                                                 );
                 }
                 else
                 {
                     LogManager.GetLogger(typeof(iText.Kernel.Pdf.Action.PdfAction)).Warn(iText.IO.LogMessageConstant.STRUCTURE_ELEMENT_REPLACED_BY_ITS_ID_IN_STRUCTURE_DESTINATION
                                                                                          );
                     ((PdfArray)destination.GetPdfObject()).Set(0, id);
                     destination.GetPdfObject().SetModified();
                 }
             }
         }
     }
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 public static void ValidateNotRemoteDestination(PdfDestination destination)
 {
     if (destination is PdfExplicitRemoteGoToDestination)
     {
         LogManager.GetLogger(typeof(iText.Kernel.Pdf.Action.PdfAction)).Warn(iText.IO.LogMessageConstant.INVALID_DESTINATION_TYPE
                                                                              );
     }
     else
     {
         if (destination is PdfExplicitDestination)
         {
             // No page number can be specified for a destination associated with a not remote go-to action because the
             // destination page is in a current PDF document. See section 12.3.2.2 of ISO 32000-1.
             PdfObject firstObj = ((PdfArray)destination.GetPdfObject()).Get(0);
             if (firstObj.IsNumber())
             {
                 LogManager.GetLogger(typeof(iText.Kernel.Pdf.Action.PdfAction)).Warn(iText.IO.LogMessageConstant.INVALID_DESTINATION_TYPE
                                                                                      );
             }
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>Creates a GoToR action, or remote action (section 12.6.4.3 of ISO 32000-1).</summary>
 /// <param name="fileSpec">the file in which the destination shall be located</param>
 /// <param name="destination">the destination in the remote document to jump to</param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoToR(PdfFileSpec fileSpec, PdfDestination destination
                                                             )
 {
     ValidateRemoteDestination(destination);
     return(new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.GoToR).Put(PdfName.F, fileSpec.GetPdfObject
                                                                                          ()).Put(PdfName.D, destination.GetPdfObject()));
 }
Ejemplo n.º 6
0
 /// <summary>Creates a GoTo action (section 12.6.4.2 of ISO 32000-1) via a given destination.</summary>
 /// <param name="destination">the desired destination of the action</param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoTo(PdfDestination destination)
 {
     ValidateNotRemoteDestination(destination);
     return(new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.GoTo).Put(PdfName.D, destination.GetPdfObject
                                                                                         ()));
 }
Ejemplo n.º 7
0
 public virtual iText.Kernel.Pdf.Annot.PdfLinkAnnotation SetDestination(PdfDestination destination)
 {
     return(SetDestination(destination.GetPdfObject()));
 }
Ejemplo n.º 8
0
 public virtual iText.Kernel.Pdf.PdfCatalog SetOpenAction(PdfDestination destination)
 {
     return(Put(PdfName.OpenAction, destination.GetPdfObject()));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Adds
 /// <see cref="iText.Kernel.Pdf.Navigation.PdfDestination"/>
 /// for the outline,
 /// <c>Dest</c>
 /// key.
 /// </summary>
 /// <param name="destination">
 /// instance of
 /// <see cref="iText.Kernel.Pdf.Navigation.PdfDestination"/>.
 /// </param>
 public virtual void AddDestination(PdfDestination destination)
 {
     SetDestination(destination);
     content.Put(PdfName.Dest, destination.GetPdfObject());
 }
Ejemplo n.º 10
0
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoToR(PdfFileSpec fileSpec, PdfDestination destination
                                                             , bool newWindow)
 {
     return(new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.GoToR).Put(PdfName.F, fileSpec.GetPdfObject
                                                                                          ()).Put(PdfName.D, destination.GetPdfObject()).Put(PdfName.NewWindow, new PdfBoolean(newWindow)));
 }