Simple code, goal is to add PAGEREF to internal hyperlinks to get page numbers displayed. Issue originates from SSRS rendering to PDF so now rendering to Word which retains the bookmarks but since SSRS report definition does not have the concept of a page reference resorting to post processing.
Any help?
class AddXRefToHyperlinks
{
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithHyperlink();
Document doc = new Document(dataDir + "BookmarkTest.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// For each Hyperlink the document
foreach (Field field in doc.Range.Fields)
{
if (field.Type == FieldType.FieldHyperlink)
{
FieldHyperlink hyperlink = (FieldHyperlink)field;
// Hyperlink must be to internal bookmark
if (hyperlink.SubAddress != null)
{
builder.MoveToField(hyperlink, true);
FieldPageRef pageRef = (FieldPageRef)builder.InsertField(FieldType.FieldPageRef, false);
pageRef.BookmarkName = hyperlink.SubAddress;
pageRef.Update();
}
}
}
dataDir = dataDir + "BookmarkTest_out.pdf";
doc.Save(dataDir);
Console.WriteLine("\nHyperlinks have cross ref added\nFile saved at " + dataDir);
}
}