Ejemplo n.º 1
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            // Add button
            PushButton button = new PushButton(20, 20, 150, 25, "button1");

            button.Caption = "BYTESCOUT.COM";
            // Add URI action
            URIAction action = new URIAction(new Uri("http://bytescout.com/"));

            button.OnActivated = action;
            page.Annotations.Add(button);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer app
            Process.Start("result.pdf");
        }
Ejemplo n.º 2
0
        internal override Action Clone(IDocumentEssential owner)
        {
            PDFDictionary dict = new PDFDictionary();

            dict.AddItem("Type", new PDFName("Action"));
            dict.AddItem("S", new PDFName("URI"));

            string[] keys = { "URI", "IsMap" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = _dictionary[keys[i]];
                if (obj != null)
                {
                    dict.AddItem(keys[i], obj.Clone());
                }
            }

            URIAction action = new URIAction(dict, owner);

            IPDFObject next = _dictionary["Next"];

            if (next != null)
            {
                for (int i = 0; i < Next.Count; ++i)
                {
                    action.Next.Add(Next[i]);
                }
            }

            return(action);
        }
Ejemplo n.º 3
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            // Add button
            PushButton button = new PushButton(20, 20, 150, 25, "button1");

            button.Caption = "BYTESCOUT.COM";
            // Add URI action
            URIAction action = new URIAction(new Uri("http://bytescout.com/"));

            button.OnActivated = action;
            page.Annotations.Add(button);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
Ejemplo n.º 4
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            // Set Url action
            URIAction action = new URIAction(new Uri("https://bytescout.com"));

            // Add link annotation
            LinkAnnotation linkAnnotation = new LinkAnnotation(action, 20, 20, 150, 25);

            // Set highlight mode
            linkAnnotation.HighlightingMode = LinkAnnotationHighlightingMode.Outline;

            // Set color
            linkAnnotation.Color = new ColorRGB(0, 0, 255);

            // Add Link
            page.Annotations.Add(linkAnnotation);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
Ejemplo n.º 5
0
        public void TestAddURLAction()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));

            URIAction urlAction = new URIAction(new Uri(@"http://bytescout.com"));

            PushButton button = new PushButton(20, 40, 120, 25, "btn1");

            button.Caption     = "Bytescout.com";
            button.OnActivated = urlAction;
            button.Font.Size   = 8;
            document.Pages[0].Annotations.Add(button);
            document.Save(OutputFolder + @"\AddURLAction.pdf");
            document.Dispose();

            //Process.Start("AddURLAction.pdf");
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("PDFObject Sample:");

            // ReSharper disable once UnusedVariable
            using (Library lib = new Library())
            {
                String sInput  = Library.ResourceDirectory + "Sample_Input/sample_links.pdf";
                String sOutput = "PDFObject-out.pdf";

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

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

                Console.WriteLine("Input file: " + sInput + ". Writing to output " + sOutput);

                Document doc  = new Document(sInput);
                Page     page = doc.GetPage(0);

                LinkAnnotation annot = (LinkAnnotation)page.GetAnnotation(1);
                URIAction      uri   = (URIAction)annot.Action;

                // Print some info about the URI action, before we modify it
                Console.WriteLine("Initial URL: " + uri.URI);
                Console.WriteLine("Is Map property: " + uri.IsMap);

                // Modify the URIAction
                //
                // A URI action is a dictionary containing:
                //    Key: S     Contents: a name object with the value "URI" (required)
                //    Key: URI   Contents: a string object for the uniform resource locator (required)
                //    Key: IsMap Contents: a boolean for whether the link is part of a map (optional)
                //    (see section 8.5.3, "Action Types", of the PDF Reference)
                //
                // We will change the URI entry and delete the IsMap entry for this dictionary

                PDFDict uri_dict = uri.PDFDict; // Extract the dictionary

                // Create a new string object
                PDFString uri_string = new PDFString("http://www.google.com", doc, false, false);

                uri_dict.Put("URI", uri_string); // Change the URI (replaces the old one)
                uri_dict.Remove("IsMap");        // Remove the IsMap entry

                // Check that we deleted the IsMap entry
                Console.WriteLine("Does this dictionary have an IsMap entry? " + uri_dict.Contains("IsMap"));

                doc.Save(SaveFlags.Full, sOutput);
                doc.Close();

                // Check the modified contents of the link
                doc   = new Document(sOutput);
                page  = doc.GetPage(0);
                annot = (LinkAnnotation)page.GetAnnotation(1);
                uri   = (URIAction)annot.Action;

                Console.WriteLine("Modified URL: " + uri.URI);
                Console.WriteLine("Is Map property (if not present, defaults to false): " + uri.IsMap);
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Actions Sample:");

            using (Library lib = new Library())
            {
                String sOutput = "../Actions-out.pdf";

                Console.WriteLine("Initialized the library.");

                Document doc = new Document();

                using (Path newpath = new Path())
                {
                    // Create a PDF page which is the same size of the image.
                    Rect pageRect = new Rect(0, 0, 100, 100);
                    Page docpage  = doc.CreatePage(Document.BeforeFirstPage,
                                                   pageRect);
                    Console.WriteLine("Created page.");

                    // Create our first link with a URI action
                    LinkAnnotation newLink = (LinkAnnotation)docpage.CreateAnnotation("Link", new Rect(1.0, 2.0, 3.0, 4.0));
                    Console.WriteLine(newLink.ToString());

                    doc.BaseURI = "http://www.datalogics.com";
                    URIAction uri = new URIAction("/products/pdfl/pdflibrary.asp", false);
                    Console.WriteLine("Action data: " + uri.ToString());

                    newLink.Action = uri;
                    docpage.AddAnnotation(-2, newLink);

                    // Create a second link with a GoTo action
                    LinkAnnotation secondLink = (LinkAnnotation)docpage.CreateAnnotation("Link", new Rect(5.0, 6.0, 7.0, 8.0));

                    Rect       r   = new Rect(5, 5, 100, 100);
                    GoToAction gta = new GoToAction(new ViewDestination(doc, 0, "FitR", r, 1.0));
                    Console.WriteLine("Action data: " + gta.ToString());

                    secondLink.Action = gta;
                    docpage.AddAnnotation(-2, secondLink);

                    // Read some URI properties
                    Console.WriteLine("Extracted URI: " + uri.URI);

                    if (uri.IsMap)
                    {
                        Console.WriteLine("Send mouse coordinates");
                    }
                    else
                    {
                        Console.WriteLine("Don't send mouse coordinates");
                    }

                    // Change the URI properties
                    doc.BaseURI = "http://www.datalogics.com";
                    uri.URI     = "/products/pdfl/pdflibrary.asp";

                    uri.IsMap = true;

                    Console.WriteLine("Complete changed URI:" + doc.BaseURI + uri.URI);

                    if (uri.IsMap)
                    {
                        Console.WriteLine("Send mouse coordinates");
                    }
                    else
                    {
                        Console.WriteLine("Don't send mouse coordinates");
                    }

                    // Testing gta
                    Console.WriteLine("Fit type of destination: " + gta.Destination.FitType.ToString());
                    Console.WriteLine("Rectangle of destination: " + gta.Destination.DestRect.ToString());
                    Console.WriteLine("Zoom of destination: " + gta.Destination.Zoom.ToString());
                    Console.WriteLine("Page number of destination: " + gta.Destination.PageNumber.ToString());

                    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);
                            }
                        }
                    }
                }
            }
        }