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); }
private static void CreateDocumentActions(PdfFixedDocument document) { // Create an action that will open the document at the last page with 200% zoom. PdfPageDirectDestination pageDestination = new PdfPageDirectDestination(); pageDestination.Page = document.Pages[document.Pages.Count - 1]; pageDestination.Zoom = 200; pageDestination.Top = 0; pageDestination.Left = 0; PdfGoToAction openAction = new PdfGoToAction(); openAction.Destination = pageDestination; document.OpenAction = openAction; // Create an action that is executed when the document is closed. PdfJavaScriptAction jsCloseAction = new PdfJavaScriptAction(); jsCloseAction.Script = "app.alert({cMsg: \"The document will close now.\", cTitle: \"Xfinium.Pdf Actions Sample\"});"; document.BeforeCloseAction = jsCloseAction; // Create an action that is executed before the document is printed. PdfJavaScriptAction jsBeforePrintAction = new PdfJavaScriptAction(); jsBeforePrintAction.Script = "app.alert({cMsg: \"The document will be printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});"; document.BeforePrintAction = jsBeforePrintAction; // Create an action that is executed after the document is printed. PdfJavaScriptAction jsAfterPrintAction = new PdfJavaScriptAction(); jsAfterPrintAction.Script = "app.alert({cMsg: \"The document has been printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});"; document.AfterPrintAction = jsAfterPrintAction; }
/// <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.Graphics.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.xfiniumsoft.com/"; PdfOutlineItem webOutline = new PdfOutlineItem(); webOutline.Title = "http://www.xfiniumsoft.com/"; webOutline.Color = new PdfRgbColor(0, 0, 255); webOutline.Action = uriAction; document.Outline.Add(webOutline); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.outlines.pdf") }; return output; }
private static void CreateGoToActions(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; Random rnd = new Random(); for (int i = 0; i < document.Pages.Count; i++) { int destinationPage = rnd.Next(document.Pages.Count); document.Pages[i].Graphics.DrawString("Go To actions:", font, blackBrush, 400, 240); document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 260, 200, 20); slo.X = 500; slo.Y = 270; document.Pages[i].Graphics.DrawString("Go To page: " + (destinationPage + 1).ToString(), sao, slo); // Create a link annotation on top of the widget. PdfLinkAnnotation link = new PdfLinkAnnotation(); document.Pages[i].Annotations.Add(link); link.VisualRectangle = new PdfVisualRectangle(400, 260, 200, 20); // Create a GoTo action and attach it to the link. PdfPageDirectDestination pageDestination = new PdfPageDirectDestination(); pageDestination.Page = document.Pages[destinationPage]; pageDestination.Left = 0; pageDestination.Top = 0; pageDestination.Zoom = 0; // Keep current zoom PdfGoToAction gotoPageAction = new PdfGoToAction(); gotoPageAction.Destination = pageDestination; link.Action = gotoPageAction; } }
/// <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.Graphics.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.xfiniumsoft.com/"; PdfOutlineItem webOutline = new PdfOutlineItem(); webOutline.Title = "http://www.xfiniumsoft.com/"; webOutline.Color = new PdfRgbColor(0, 0, 255); webOutline.Action = uriAction; document.Outline.Add(webOutline); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.outlines.pdf") }; return(output); }