示例#1
0
        private static PDFOutlineItem CreateOutline(string title, PDFPage page)
        {
            PDFPageDirectDestination pageDestination = new PDFPageDirectDestination();

            pageDestination.Page = page;
            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       = title;
            outline.VisualStyle = PDFOutlineItemVisualStyle.Italic;
            outline.Action      = gotoPage;

            return(outline);
        }
示例#2
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream file1Input, Stream file2Input)
        {
            PDFFixedDocument document = new PDFFixedDocument();

            // The documents are merged by creating an empty PDF document and appending the file to it.
            // The outlines from the source file are also included in the merged file.
            document.AppendFile(file1Input);
            int count = document.Pages.Count;

            document.AppendFile(file2Input);

            // Create outlines that point to each merged file.
            PDFOutlineItem file1Outline = CreateOutline("First file", document.Pages[0]);

            document.Outline.Add(file1Outline);
            PDFOutlineItem file2Outline = CreateOutline("Second file", document.Pages[count]);

            document.Outline.Add(file2Outline);

            // Optionally we can add a new page at the beginning of the merged document.
            PDFPage page = new PDFPage();

            document.Pages.Insert(0, page);

            PDFOutlineItem blankPageOutline = CreateOutline("Blank page", page);

            document.Outline.Insert(0, blankPageOutline);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "documentappend.pdf") };
            return(output);
        }
示例#3
0
        /// <summary>
        /// Creates a new bookmark and adds it at the end of the collection.
        /// </summary>
        /// <param name="title">the title of the bookmark</param>
        /// <param name="bookmarkColor">a <see cref="PDFRgbColor"/> object specifying
        /// the color used to draw the bookmark in the bookmark tree.</param>
        /// <param name="visualStyle">a combination of <see cref="PDFOutlineItemVisualStyle"/>
        /// enumeration members, specifying the font style used to draw
        /// the bookmark title.</param>
        /// <param name="destinationPage">a <see cref="PDFPage"/> object
        /// representing the destination of the bookmark.</param>
        /// <returns>a <see cref="PDFBookmark"/> object representing the
        /// newly created bookmark.</returns>
        public static PDFOutlineItem CreateBookmark(string title, PDFRgbColor bookmarkColor, PDFOutlineItemVisualStyle visualStyle, PDFPage destinationPage)
        {
            //PDF4NET 5: PDFBookmark bookmark = new PDFBookmark();
            PDFOutlineItem bookmark = new PDFOutlineItem();

            bookmark.Title = title;
            bookmark.Color = bookmarkColor;
            //PDF4NET 5: bookmark.DisplayStyle = displayStyle;
            bookmark.VisualStyle = visualStyle;

            PDFGoToAction gotoAction = new PDFGoToAction();

            //PDF4NET 5: gotoAction.Destination = new PDFPageDestination();
            gotoAction.Destination = new PDFPageDirectDestination();
            //PDF4NET 5: gotoAction.Destination.Page = destinationPage;
            (gotoAction.Destination as PDFPageDirectDestination).Page = destinationPage;
            bookmark.Action = gotoAction;

            return(bookmark);
        }
示例#4
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);
        }
示例#5
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");
        }
示例#6
0
        static void Main(string[] args)
        {
            // Create the graphic objects
            //PDF4NET v5: PDFFont fontChapter = new PDFFont(PDFFontFace.Helvetica, 20);
            PDFStandardFont fontChapter = new PDFStandardFont(PDFStandardFontFace.Helvetica, 20);

            fontChapter.Bold = true;
            //PDF4NET v5: PDFFont fontSection = new PDFFont(PDFFontFace.Helvetica, 16);
            PDFStandardFont fontSection = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16);

            fontSection.Italic = true;
            //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 12);
            PDFStandardFont fontText   = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12);
            PDFBrush        blackBrush = new PDFBrush(new PDFRgbColor());

            // Create the pdf document
            //PDF4NET v5: PDFDocument pdfDoc = new PDFDocument();
            PDFFixedDocument pdfDoc = new PDFFixedDocument();

            // Display the outlines when opening the document
            pdfDoc.DisplayMode = PDFDisplayMode.UseOutlines;

            // Create 10 pages
            for (int i = 0; i < 10; i++)
            {
                //PDF4NET v5: PDFPage pdfPage = pdfDoc.AddPage();
                PDFPage pdfPage = pdfDoc.Pages.Add();
                //PDF4NET v5: pdfPage.Canvas.DrawText("Chapter " + (i + 1).ToString(), fontChapter, null, blackBrush, 10, 10, 0, PDFTextAlign.TopLeft);
                pdfPage.Canvas.DrawString("Chapter " + (i + 1).ToString(), fontChapter, blackBrush, 10, 10);
                //PDF4NET v5: pdfPage.Canvas.DrawText("Section " + (i + 1).ToString() + ".1", fontSection, null, blackBrush, 20, 32, 0, PDFTextAlign.TopLeft);
                pdfPage.Canvas.DrawString("Section " + (i + 1).ToString() + ".1", fontSection, blackBrush, 20, 32);
                //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".1.1", fontText, null, blackBrush, 30, 50, 0, PDFTextAlign.TopLeft);
                pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".1.1", fontText, blackBrush, 30, 50);
                //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".1.2", fontText, null, blackBrush, 30, 200, 0, PDFTextAlign.TopLeft);
                pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".1.2", fontText, blackBrush, 30, 200);
                //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".1.3", fontText, null, blackBrush, 30, 300, 0, PDFTextAlign.TopLeft);
                pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".1.3", fontText, blackBrush, 30, 300);
                //PDF4NET v5: pdfPage.Canvas.DrawText("Section " + (i + 1).ToString() + ".2", fontSection, null, blackBrush, 20, 400, 0, PDFTextAlign.TopLeft);
                pdfPage.Canvas.DrawString("Section " + (i + 1).ToString() + ".2", fontSection, blackBrush, 20, 400);
                //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".2.1", fontText, null, blackBrush, 30, 420, 0, PDFTextAlign.TopLeft);
                pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".2.1", fontText, blackBrush, 30, 420);
                //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".2.2", fontText, null, blackBrush, 30, 570, 0, PDFTextAlign.TopLeft);
                pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".2.2", fontText, blackBrush, 30, 570);
                //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".2.3", fontText, null, blackBrush, 30, 650, 0, PDFTextAlign.TopLeft);
                pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".2.3", fontText, blackBrush, 30, 650);
            }

            // Create the bookmarks tree
            // Create a root outline
            //PDF4NET v5: PDFBookmark root = CreateBookmark("Bookmarks", new PDFRgbColor(Color.Black), PDFBookmarkDisplayStyle.Bold, pdfDoc.Pages[0]);
            PDFOutlineItem root = CreateBookmark("Bookmarks", PDFRgbColor.Black, PDFOutlineItemVisualStyle.Bold, pdfDoc.Pages[0]);

            //PDF4NET v5: pdfDoc.Bookmarks.Add(root);
            pdfDoc.Outline.Add(root);

            // Create document bookmarks
            for (int i = 0; i < pdfDoc.Pages.Count; i++)
            {
                // Create chapter bookmark
                //PDF4NET v5: PDFBookmark chapter = CreateBookmark("Chapter " + (i + 1).ToString(), new PDFRgbColor(Color.Blue), PDFBookmarkDisplayStyle.Italic, pdfDoc.Pages[i]);
                PDFOutlineItem chapter = CreateBookmark("Chapter " + (i + 1).ToString(), PDFRgbColor.Blue, PDFOutlineItemVisualStyle.Italic, pdfDoc.Pages[i]);
                //PDF4NET v5: root.Bookmarks.Add(chapter);
                root.Items.Add(chapter);

                // Create section 1 bookmark
                //PDF4NET v5: PDFBookmark section1 = CreateBookmark("Section " + (i + 1).ToString() + ".1", new PDFRgbColor(Color.Green), PDFBookmarkDisplayStyle.Italic, pdfDoc.Pages[i]);
                PDFOutlineItem section1 = CreateBookmark("Section " + (i + 1).ToString() + ".1", PDFRgbColor.Green, PDFOutlineItemVisualStyle.Italic, pdfDoc.Pages[i]);
                //PDF4NET v5: chapter.Bookmarks.Add(section1);
                chapter.Items.Add(section1);

                // Create paragraph bookmarks
                //PDF4NET v5: PDFBookmark paragraph11 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.1", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]);
                PDFOutlineItem paragraph11 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.1", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]);
                //PDF4NET v5: section1.Bookmarks.Add(paragraph11);
                section1.Items.Add(paragraph11);

                //PDF4NET v5: PDFBookmark paragraph12 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.2", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]);
                PDFOutlineItem paragraph12 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.2", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]);
                //PDF4NET v5: section1.Bookmarks.Add(paragraph12);
                section1.Items.Add(paragraph12);

                //PDF4NET v5: PDFBookmark paragraph13 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.3", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]);
                PDFOutlineItem paragraph13 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.3", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]);
                //PDF4NET v5: section1.Bookmarks.Add(paragraph13);
                section1.Items.Add(paragraph13);
                section1.Expanded = true;

                // Create section 2 bookmark
                //PDF4NET v5: PDFBookmark section2 = CreateBookmark("Section " + (i + 1).ToString() + ".2", new PDFRgbColor(Color.Green), PDFBookmarkDisplayStyle.Italic, pdfDoc.Pages[i]);
                PDFOutlineItem section2 = CreateBookmark("Section " + (i + 1).ToString() + ".2", PDFRgbColor.Green, PDFOutlineItemVisualStyle.Italic, pdfDoc.Pages[i]);
                //PDF4NET v5: chapter.Bookmarks.Add(section2);
                chapter.Items.Add(section2);

                // Create paragraph bookmarks
                //PDF4NET v5: PDFBookmark paragraph21 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.1", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]);
                PDFOutlineItem paragraph21 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.1", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]);
                //PDF4NET v5: section2.Bookmarks.Add(paragraph21);
                section2.Items.Add(paragraph21);

                //PDF4NET v5: PDFBookmark paragraph22 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.2", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]);
                PDFOutlineItem paragraph22 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.2", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]);
                //PDF4NET v5: section2.Bookmarks.Add(paragraph22);
                section2.Items.Add(paragraph22);

                //PDF4NET v5: PDFBookmark paragraph23 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.3", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]);
                PDFOutlineItem paragraph23 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.3", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]);
                //PDF4NET v5: section2.Bookmarks.Add(paragraph23);
                section2.Items.Add(paragraph23);
                section2.Expanded = true;

                chapter.Expanded = true;
            }

            root.Expanded = true;

            // Save the document to disk
            pdfDoc.Save("Sample_Bookmarks.pdf");
        }