Bookmarks and cross ref in pdf

Hi
I’m developing a pdf converter based on aspose solution, I use aspose.word for converting .doc to pdf.
My client wants to be able to get a bookmark tree in the pdf is this possible with aspose?
and I’m now converting the cross refernces to bookmarks to make them work in pdf, but is there a way to format them, (they are now black as in the word) to “hyperlink” format i.e. blue and underlined?
Thanx for great products (using the pdf.kit for merging and replacing pages in pdf documents)

Hi

Thanks for your inquiry.

  1. Yes, you can achieve this using Aspose.Words. You should use PdfOptions.BookmarksOutlineLevel property. See the following link to learn more:
    https://reference.aspose.com/words/net/aspose.words.saving/outlineoptions/defaultbookmarksoutlinelevel/
    Here is code example.
Document doc = new Document(@"Test213\in.doc");
PdfOptions opt = new PdfOptions();
opt.BookmarksOutlineLevel = 2;
doc.SaveToPdf(0, doc.PageCount, @"Test213\out.pdf", opt);
  1. Regarding cross reference. Could you please attach a sample document for testing? I will investigate the issue and provide you more information.

Best regards.

Hi

thank you for the quick response.

I attach both the original doc and the rendered pdf. Under 1.2 I have
created a cross ref that I need to have the same look as the links in
the Toc. Can this be done?

/Daniel

Hi

Thanks for your request. You can try using the following code:

// Open document and Create DocumentBuilder
Document doc = new Document(@"Test220\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get collection of fieldStarts from the document
NodeCollection starts = doc.GetChildNodes(NodeType.FieldStart, true);
// Create Array list. We will store nodes that will be removed in this list
ArrayList removeList = new ArrayList();
// Loop though all field starts
foreach (FieldStart start in starts)
{
    // Check whether current field start is start of REF field
    if (start.FieldType == FieldType.FieldRef)
    {
        // We should get field code and field value 
        string fieldCode = string.Empty;
        string fieldValue = string.Empty;
        Node currentNode = start;
        // Get Field code
        while (currentNode.NodeType != NodeType.FieldSeparator)
        {
            if (currentNode.NodeType == NodeType.Run)
                fieldCode += (currentNode as Run).Text;
            removeList.Add(currentNode);
            currentNode = currentNode.NextSibling;
        }
        // Get field value
        while (currentNode.NodeType != NodeType.FieldEnd)
        {
            if (currentNode.NodeType == NodeType.Run)
                fieldValue += (currentNode as Run).Text;
            removeList.Add(currentNode);
            currentNode = currentNode.NextSibling;
        }
        removeList.Add(currentNode);
        // We should get ref name from field code
        Regex regex = new Regex(@"\s*(?\S+)\s+(?\S+)\s+(?.+)");
        Match match = regex.Match(fieldCode);
        string refName = match.Groups["name"].Value;
        // Now we should insert HYPERLINK instead REF field
        // move DocumentBuilder cursor to Field Start
        builder.MoveTo(start);
        // Set formating of Hyperlink
        builder.Font.Color = Color.Blue;
        builder.Font.Underline = Underline.Single;
        // Insert Hyperlink
        builder.InsertHyperlink(fieldValue, refName, true);
    }
}
// now we can remove REF fields
foreach (Node node in removeList)
{
    node.Remove();
}
// Save document
doc.Save(@"Test220\out.pdf");

Hope this helps.
Best regards.