/// <summary> /// Creates a link to an external PDF document using a named destination. /// </summary> /// <param name="rect">The link area in default page coordinates.</param> /// <param name="documentPath">The path to the target document.</param> /// <param name="destinationName">The named destination's name in the target document.</param> /// <param name="newWindow">True, if the destination document shall be opened in a new window. /// If not set, the viewer application should behave in accordance with the current user preference.</param> public static PdfLinkAnnotation CreateDocumentLink(PdfRectangle rect, string documentPath, string destinationName, bool?newWindow = null) { PdfLinkAnnotation link = new PdfLinkAnnotation(); link._linkType = LinkType.NamedDestination; link.Rectangle = rect; link._action = PdfRemoteGoToAction.CreateRemoteGoToAction(documentPath, destinationName, newWindow); return(link); }
private static void CreateRemoteGoToActions(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 Remote actions:", font, blackBrush, 400, 300); document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 320, 200, 20); slo.X = 500; slo.Y = 330; document.Pages[i].Graphics.DrawString("Go To page " + (destinationPage + 1).ToString() + " in sample.pdf", 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, 320, 200, 20); // Create a GoToR action and attach it to the link. PdfPageNumberDestination pageDestination = new PdfPageNumberDestination(); pageDestination.PageNumber = destinationPage; pageDestination.Left = 0; pageDestination.Top = 792; pageDestination.Zoom = 0; // Keep current zoom PdfRemoteGoToAction remoteGoToAction = new PdfRemoteGoToAction(); remoteGoToAction.FileName = "sample.pdf"; remoteGoToAction.Destination = pageDestination; link.Action = remoteGoToAction; } }
private static void CreateRemoteGoToActions(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 Remote actions:", font, blackBrush, 400, 300); document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 320, 200, 20); slo.X = 500; slo.Y = 330; document.Pages[i].Graphics.DrawString("Go To page " + (destinationPage + 1).ToString() + " in sample.pdf", 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, 320, 200, 20); // Create a GoToR action and attach it to the link. PdfPageNumberDestination pageDestination = new PdfPageNumberDestination(); pageDestination.PageNumber = destinationPage; pageDestination.Left = 0; pageDestination.Top = 792; pageDestination.Zoom = 0; // Keep current zoom PdfRemoteGoToAction remoteGoToAction = new PdfRemoteGoToAction(); remoteGoToAction.FileName = "sample.pdf"; remoteGoToAction.Destination = pageDestination; link.Action = remoteGoToAction; } }