예제 #1
0
        private static void CreateUriActions(PDFFixedDocument document, PDFFont font)
        {
            PDFPen   blackPen   = new PDFPen(new PDFRgbColor(0, 0, 0), 1);
            PDFBrush blackBrush = new PDFBrush();

            font.Size = 12;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Canvas.DrawString("Uri actions:", font, blackBrush, 400, 420);

                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 440, 200, 20);
                slo.X = 500;
                slo.Y = 450;
                document.Pages[i].Canvas.DrawString("Go to o2sol.com", sao, slo);

                // Create a link annotation on top of the widget.
                PDFLinkAnnotation link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 440, 200, 20);

                // Create an uri action and attach it to the link.
                PDFUriAction uriAction = new PDFUriAction();
                uriAction.URI = "http://www.o2sol.com";
                link.Action   = uriAction;
            }
        }
예제 #2
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PDFFixedDocument document = new PDFFixedDocument();

            document.DisplayMode = PDFDisplayMode.UseOutlines;

            PDFStandardFont helvetica  = new PDFStandardFont(PDFStandardFontFace.Helvetica, 216);
            PDFBrush        blackBrush = new PDFBrush();

            for (int i = 0; i < 10; i++)
            {
                PDFPage page = document.Pages.Add();
                page.Canvas.DrawString((i + 1).ToString(), helvetica, blackBrush, 50, 50);
            }

            PDFOutlineItem root = new PDFOutlineItem();

            root.Title       = "Contents";
            root.VisualStyle = PDFOutlineItemVisualStyle.Bold;
            root.Color       = new PDFRgbColor(255, 0, 0);
            document.Outline.Add(root);

            for (int i = 0; i < document.Pages.Count; i++)
            {
                // Create a destination to target page.
                PDFPageDirectDestination pageDestination = new PDFPageDirectDestination();
                pageDestination.Page = document.Pages[i];
                pageDestination.Top  = 0;
                pageDestination.Left = 0;
                // Inherit current zoom
                pageDestination.Zoom = 0;

                // Create a go to action to be executed when the outline is clicked,
                // the go to action goes to specified destination.
                PDFGoToAction gotoPage = new PDFGoToAction();
                gotoPage.Destination = pageDestination;

                // Create the outline in the table of contents
                PDFOutlineItem outline = new PDFOutlineItem();
                outline.Title       = string.Format("Go to page {0}", i + 1);
                outline.VisualStyle = PDFOutlineItemVisualStyle.Italic;
                outline.Action      = gotoPage;
                root.Items.Add(outline);
            }
            root.Expanded = true;

            // Create an outline that will launch a link in the browser.
            PDFUriAction uriAction = new PDFUriAction();

            uriAction.URI = "http://www.o2sol.com/";

            PDFOutlineItem webOutline = new PDFOutlineItem();

            webOutline.Title  = "http://www.o2sol.com/";
            webOutline.Color  = new PDFRgbColor(0, 0, 255);
            webOutline.Action = uriAction;
            document.Outline.Add(webOutline);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "outlines.pdf") };
            return(output);
        }
예제 #3
0
        static void Main(string[] args)
        {
            // Create the pdf document
            //PDF4NET v5: PDFDocument doc = new PDFDocument();
            PDFFixedDocument doc = new PDFFixedDocument();

            // Create the graphic objects
            //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 12);
            PDFStandardFont fontText = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12);

            PDFBrush blackBrush = new PDFBrush(new PDFRgbColor());

            // Create 3 pages
            //PDF4NET v5: PDFPage page = doc.AddPage();
            PDFPage page = doc.Pages.Add();

            //PDF4NET v5: page.Canvas.DrawText("Page 1", fontText, null, blackBrush, 20, 30);
            page.Canvas.DrawString("Page 1", fontText, blackBrush, 20, 30);

            //PDF4NET v5: page = doc.AddPage();
            page = doc.Pages.Add();

            //PDF4NET v5: page.Canvas.DrawText("Page 2", fontText, null, blackBrush, 20, 30);
            page.Canvas.DrawString("Page 2", fontText, blackBrush, 20, 30);

            //PDF4NET v5: page = doc.AddPage();
            page = doc.Pages.Add();

            //PDF4NET v5: page.Canvas.DrawText("Page 3", fontText, null, blackBrush, 20, 30);
            page.Canvas.DrawString("Page 3", fontText, blackBrush, 20, 30);

            /// URI Action
            // create a web action
            //PDF4NET v5: PDFURIAction uriAction = new PDFURIAction();
            PDFUriAction uriAction = new PDFUriAction();

            uriAction.URI = "http://www.o2sol.com/";

            // create a bookmark to point to the url above
            //PDF4NET v5: PDFBookmark url = new PDFBookmark();
            PDFOutlineItem url = new PDFOutlineItem();

            url.Title  = "www.o2sol.com";
            url.Color  = new PDFRgbColor();
            url.Action = uriAction;
            // add the bookmark to the document
            //PDF4NET v5: doc.Bookmarks.Add(url);
            doc.Outline.Add(url);
            /// URI Action

            /// Javascript Action
            // create a javascript action to print the document
            PDFJavaScriptAction jsAction = new PDFJavaScriptAction();

            jsAction.Script = "this.print(true);\n";

            // create a bookmark to point to execute the action
            //PDF4NET v5: PDFBookmark js = new PDFBookmark();
            PDFOutlineItem js = new PDFOutlineItem();

            js.Title  = "Print me from JavaScript";
            js.Color  = new PDFRgbColor();
            js.Action = jsAction;
            // add the bookmark to the document
            //PDF4NET v5: doc.Bookmarks.Add(url);
            doc.Outline.Add(js);
            /// Javascript Action

            /// OpenDocument action
            // Create an action to be executed when the document is opened
            // The action will open the document at the
            // second page of the document using a 800% zoom
            //PDF4NET v5: PDFPageDestination pageDestination = new PDFPageDestination();
            PDFPageDirectDestination pageDestination = new PDFPageDirectDestination();

            pageDestination.Page = doc.Pages[1];
            //PDF4NET v5: pageDestination.MagnificationMode = PDFMagnificationMode.XYZ;
            pageDestination.ZoomMode = PDFDestinationZoomMode.XYZ;

            pageDestination.Left = 0;
            pageDestination.Top  = 0;
            pageDestination.Zoom = 800;
            PDFGoToAction goToAction = new PDFGoToAction();

            goToAction.Destination = pageDestination;

            // set the action on the document
            doc.OpenAction = goToAction;
            /// OpenDocument action

            // Save the document to disk
            doc.Save("Sample_Actions.pdf");
        }