Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sFileSpec = "../../Resources/Sample_Input/ducky.pdf";
                String sOutput   = "../RemoteGoToActions-out.pdf";

                if (args.Length > 0)
                {
                    sFileSpec = args[0];
                }

                if (args.Length > 1)
                {
                    sOutput = args[1];
                }

                Console.WriteLine("Writing to output " + sOutput + ". Using " + sFileSpec + " as file specification");

                Document doc = new Document();

                // Standard letter size page (8.5" x 11")
                Rect pageRect = new Rect(0, 0, 612, 792);
                Page docpage  = doc.CreatePage(Document.BeforeFirstPage, pageRect);
                Console.WriteLine("Created page.");

                LinkAnnotation newLink = new LinkAnnotation(docpage, new Rect(153, 198, 306, 396));
                Console.WriteLine("Created new Link Annotation");

                // RemoteGoToActions need a FileSpecification and a RemoteDestination.
                //
                // The FileSpecification specifies which file should be opened when the LinkAnnotation is "clicked"
                //
                // The RemoteDestination specifies a particular view (page number, Fit type, rectangle, and zoom level)
                // to display when the file in the FileSpecification is opened. Remember page numbers start at 0.
                //
                // FileSpecification objects, RemoteDestination objects, and RemoteGoToActions
                // must be associated with a Document. The association happens at object creation time and cannot be changed.
                //
                // FileSpecifications and RemoteDestinations are associated with the Document that is passed in the constructor.
                // RemoteGoToActions are associated with the same Document as the RemoteDestination used to create it.
                //
                // When creating a RemoteGoToAction, make sure that the FileSpecification and RemoteDestination are both
                // associated with the same Document, or an exception will be thrown.

                // FileSpecifications can take either a relative or an absolute path. It is best to specify
                // a relative path if the document is intended to work across multiple platforms (Windows, Linux, Mac)
                FileSpecification fileSpec = new FileSpecification(doc, sFileSpec);
                Console.WriteLine("Path to remote document : " + fileSpec.Path);

                RemoteDestination remoteDest = new RemoteDestination(doc, 0, "XYZ", new Rect(0, 0, 4 * 72, 4 * 72), 1.5);
                Console.WriteLine("When the Link is clicked the remote document will open to : ");
                Console.WriteLine("Page Number : " + remoteDest.PageNumber);
                Console.WriteLine("zoom level : " + remoteDest.Zoom);
                Console.WriteLine("fit type : " + remoteDest.FitType);
                Console.WriteLine("rectangle : " + remoteDest.DestRect.ToString());

                // Now create the RemoteGoToAction from the fileSpec and the RemoteDestination
                RemoteGoToAction remoteAction = new RemoteGoToAction(fileSpec, remoteDest);

                // assign the RemoteGoToAction to the LinkAnnotation
                newLink.Action = remoteAction;

                doc.Save(SaveFlags.Full, sOutput);
            }
        }
        /**
         * Mouse up handler.
         * All annotation transformation is performed in mouse move handler.
         * This handler is for context menu calls, and for finishing annotation tracking.
         */
        public override void MouseUp(MouseEventArgs e, System.Drawing.Point location)
        {
            captured = false;
            if (!docView.EditPermission)
            {
                return;
            }

            if (e.Button == MouseButtons.Right)
            {
                if (docView.ActiveAnnotation != null)
                {
                    ContextMenu currentContextMenu = null;

                    switch (docView.ActiveAnnotation.Properties.Subtype)
                    {
                    case "FreeText":
                        currentContextMenu = textAnnotationContextMenu;
                        break;

                    case "Link":
                        currentContextMenu = linkAnnotationContextMenu;
                        break;

                    default:
                        currentContextMenu = shapeAnnotationContextMenu;
                        break;
                    }
                    if (currentContextMenu != null)
                    {
                        UpdateMenuItems(currentContextMenu);
                        currentContextMenu.Show(docView.Parent, e.Location);
                    }
                }
            }
            else
            {
                docView.EditCheckPoint();
                if (e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Control && (docView.ActiveAnnotation != null || cachedIndex != -1))
                {
                    BaseAnnotationEditor editor = docView.EditAnnotations[cachedIndex];
                    if (editor is LinkAnnotationEditor)
                    {
                        LinkAnnotation annot = editor.Annotation as LinkAnnotation;
                        if (annot.Action is URIAction)
                        {
                            URIAction act = annot.Action as URIAction;
                            System.Diagnostics.Process.Start(act.URI);
                        }
                        else if (annot.Action is RemoteGoToAction)
                        {
                            RemoteGoToAction  action = annot.Action as RemoteGoToAction;
                            FileSpecification spec   = action.FileSpecification;

                            string fullPath = System.IO.Path.GetFullPath(spec.Path);
                            if (System.IO.File.Exists(fullPath))
                            {
                                System.Diagnostics.Process.Start(fullPath);
                            }
                        }
                        else if (annot.Action is GoToAction || annot.Destination != null)
                        {
                            GoToAction      action = (annot.Action as GoToAction);
                            ViewDestination dest   = action == null ? annot.Destination : action.Destination;

                            if (dest != null)
                            {
                                docView.GoToDestionation(dest);
                            }
                        }
                    }
                }
            }
        }