To link a location in one document to a location in another, you must do the following:
Here is the text of a complete program that creates a document with an anchor in it, and saves it in a disk file (myDocument1.c1d). It then creates another document, adds a link to the anchor in the first document to it, and shows the second document in a preview dialog box:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' Make target document with an anchor. Dim targetDoc As New C1.C1Preview.C1PrintDocument Dim rt1 As New C1.C1Preview.RenderText("This is anchor1 in myDocument1.") rt1.Anchors.Add(New C1.C1Preview.C1Anchor("anchor1")) targetDoc.Body.Children.Add(rt1) targetDoc.Generate() targetDoc.Save("c:\myDocument1.c1d") ' Make document with a hyperlink to the anchor. Dim sourceDoc As New C1.C1Preview.C1PrintDocument Dim rt2 As New C1.C1Preview.RenderText("This is hyperlink to myDocument1.") Dim linkTarget As C1.C1Preview.C1LinkTarget = New C1.C1Preview.C1LinkTargetExternalAnchor("c:\myDocument1.c1d", "anchor1") rt2.Hyperlink = New C1.C1Preview.C1Hyperlink(linkTarget) sourceDoc.Body.Children.Add(rt2) sourceDoc.Generate() ' Show document with hyperlink in preview. Dim preview As New C1.Win.C1Preview.C1PrintPreviewDialog() preview.Document = sourceDoc preview.ShowDialog() |
To write code in C#
C# |
Copy Code
|
---|---|
// Make target document with an anchor. C1PrintDocument targetDoc = new C1PrintDocument(); RenderText rt1 = new RenderText("This is anchor1 in myDocument1."); rt1.Anchors.Add(new C1Anchor("anchor1")); targetDoc.Body.Children.Add(rt1); targetDoc.Generate(); targetDoc.Save(@"c:\myDocument1.c1d"); // Make document with a hyperlink to the anchor. C1PrintDocument sourceDoc = new C1PrintDocument(); RenderText rt2 = new RenderText("This is hyperlink to myDocument1."); C1LinkTarget linkTarget = new C1LinkTargetExternalAnchor(@"c:\myDocument1.c1d", "anchor1"); rt2.Hyperlink = new C1Hyperlink(linkTarget); sourceDoc.Body.Children.Add(rt2); sourceDoc.Generate(); // Show document with hyperlink in preview. C1PrintPreviewDialog preview = new C1PrintPreviewDialog(); preview.Document = sourceDoc; preview.ShowDialog(); |
Note the following: