protected override void DoRegisterArtefacts(PDFLayoutContext context, PDFArtefactRegistrationSet set, Style fullstyle) { base.DoRegisterArtefacts(context, set, fullstyle); LinkAction actiontype = this.Action; if (actiontype == LinkAction.Undefined) { actiontype = this.ResolveActionType(this.Destination, this.File); } object[] entries = null; PDFAction action; if (this.IsNamedAction(actiontype)) { PDFNamedAction named = new PDFNamedAction(this, this.Action); action = named; } else if (actiontype == LinkAction.Uri) { string url = this.File; if (!string.IsNullOrEmpty(url)) { action = new PDFUriDestinationAction(this, actiontype, url); } else { throw new PDFLinkException(Errors.NoFileLinkSpecifiedOnUriAction); } } else if (actiontype == LinkAction.Destination) { //If we start with a # then we are an ID, otherwise we are a uniqueID or Name PDFDestination dest; Component comp; if (string.IsNullOrEmpty(this.Destination)) { //if there is no destination then there is no link. So do not register comp = null; return; } else if (this.Destination.StartsWith(ComponentIDPrefix)) { string id = this.Destination.Substring(ComponentIDPrefix.Length); comp = this.Document.FindAComponentById(id); } else { comp = this.Document.FindAComponentByName(this.Destination); } if (null == comp) { if (context.Conformance == ParserConformanceMode.Strict) { throw new PDFLayoutException(string.Format(Errors.LinkToDestinationCouldNotBeMade, this.Destination)); } else { context.TraceLog.Add(TraceLevel.Error, "PDFLink", string.Format(Errors.LinkToDestinationCouldNotBeMade, this.Destination)); } //cannot continue as we dont have anything to link to return; } dest = new PDFDestination(comp, this.DestinationFit, this.UniqueID); PDFDestinationAction destact = new PDFDestinationAction(this, actiontype, dest); action = destact; if (null != dest) { object link = context.DocumentLayout.RegisterCatalogEntry(context, PDFArtefactTypes.Names, dest); set.SetArtefact(LinkArtefactName, link); } } else if (actiontype == LinkAction.ExternalDestination) { string name = this.Destination; string file = this.File; PDFRemoteDestinationAction remote = new PDFRemoteDestinationAction(this, actiontype, file, name); remote.NewWindow = this.NewWindow; action = remote; } else { throw RecordAndRaise.Argument("actiontype"); } if (null != action) { entries = this.AddActionAnnotationToChildren(context, fullstyle, action); set.SetArtefact(LinkAnnotationChildEntries, entries); } }
private static void CreateNamedActions(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("Named actions:", font, blackBrush, 400, 20); ///////////// // First page ///////////// document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 40, 200, 20); slo.X = 500; slo.Y = 50; document.Pages[i].Canvas.DrawString("Go To First Page", 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, 40, 200, 20); // Create a named action and attach it to the link. PDFNamedAction namedAction = new PDFNamedAction(); namedAction.NamedAction = PDFActionName.FirstPage; link.Action = namedAction; ///////////// // Prev page ///////////// document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 80, 200, 20); slo.Y = 90; document.Pages[i].Canvas.DrawString("Go To Previous Page", sao, slo); // Create a link annotation on top of the widget. link = new PDFLinkAnnotation(); document.Pages[i].Annotations.Add(link); link.DisplayRectangle = new PDFDisplayRectangle(400, 80, 200, 20); // Create a named action and attach it to the link. namedAction = new PDFNamedAction(); namedAction.NamedAction = PDFActionName.PrevPage; link.Action = namedAction; ///////////// // Next page ///////////// document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 120, 200, 20); slo.Y = 130; document.Pages[i].Canvas.DrawString("Go To Next Page", sao, slo); // Create a link annotation on top of the widget. link = new PDFLinkAnnotation(); document.Pages[i].Annotations.Add(link); link.DisplayRectangle = new PDFDisplayRectangle(400, 120, 200, 20); // Create a named action and attach it to the link. namedAction = new PDFNamedAction(); namedAction.NamedAction = PDFActionName.NextPage; link.Action = namedAction; ///////////// // Last page ///////////// document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 160, 200, 20); slo.Y = 170; document.Pages[i].Canvas.DrawString("Go To Last Page", sao, slo); // Create a link annotation on top of the widget. link = new PDFLinkAnnotation(); document.Pages[i].Annotations.Add(link); link.DisplayRectangle = new PDFDisplayRectangle(400, 160, 200, 20); // Create a named action and attach it to the link. namedAction = new PDFNamedAction(); namedAction.NamedAction = PDFActionName.LastPage; link.Action = namedAction; ///////////// // Print document ///////////// document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 200, 200, 20); slo.Y = 210; document.Pages[i].Canvas.DrawString("Print Document", sao, slo); // Create a link annotation on top of the widget. link = new PDFLinkAnnotation(); document.Pages[i].Annotations.Add(link); link.DisplayRectangle = new PDFDisplayRectangle(400, 200, 200, 20); // Create a named action and attach it to the link. namedAction = new PDFNamedAction(); namedAction.NamedAction = PDFActionName.Print; link.Action = namedAction; } }