Hyperlink is not working after merging the two documents(Save as PDF)

Hello,

I have an issue while converting PDF from the merged documents.

I have merge the two word documents(TestDoc1.docx, TestDoc2.docx). Then I find & update the hyperlinks in merged document(Result_MergedDocument.docx).

The hyperlink works in word document but not in PDF(Result_MergedDocument.pdf).
I have attached the document and source code.

Please suggest.

Thanks.

Hi Mani,

Thanks for your inquiry. FieldHyperlink class implements the HYPERLINK field. Please use FieldHyperlink.SubAddress property to get or set a location in the file, such as a bookmark, where this hyperlink jumps.

Unfortunately, this property does not work for your case. We have logged this problem in our issue tracking system as WORDSNET-13865. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Mani,

Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-13865) as ‘Not a Bug’.

As a workaround of this issue, please adjust such hyperlinks as shown in following code example. We have attached the output document with this post for your kind reference. Hope this helps you.

Document doc1 = new Document(MyDir + "TestDoc1.docx");
Document doc2 = new Document(MyDir + "TestDoc2.docx");
doc1.AppendDocument(doc2, ImportFormatMode.UseDestinationStyles);
DocumentBuilder builder = new DocumentBuilder(doc1);
List<Paragraph> headings = doc1.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>().Where(p => p.ParagraphFormat.IsHeading).ToList();
foreach (FieldHyperlink field in doc1.Range.Fields.OfType<FieldHyperlink>())
{
    field.Address = null;
    if (doc1.Range.Bookmarks[field.SubAddress] == null)
    {
        foreach (Paragraph heading in headings)
        {
            if (heading.GetText().TrimEnd(ControlChar.ParagraphBreakChar) == field.SubAddress)
            {
                builder.MoveTo(heading);
                builder.StartBookmark(field.SubAddress);
                builder.EndBookmark(field.SubAddress);
                break;
            }
        }
    }
}
doc1.Save(MyDir + "output.pdf");