Hi Team,RelativePtah.zip (1.2 MB)
I have uploaded two pdf files zipped into single folder.
I want code create external hyperlink from pdf1 to pdf2.
the link should be work properly even in change the location of destination file.
That is I am failed to create external link with relative path.
Please help me with the code as earlier as possible.
Thanks,
Harish G.
@HarishGali
In order to achieve your requirements, you need to embed destination PDF file as an attachment and use the below code:
Document doc = new Document(dataDir + "sample.pdf");
var page = doc.Pages[1];
FileSpecification fs = new FileSpecification(dataDir + "input.pdf");
doc.EmbeddedFiles.Add(fs);
var absorber = new TextFragmentAbsorber("Link Text");
page.Accept(absorber);
foreach(var fragment in absorber.TextFragments)
{
FileAttachmentAnnotation fileAttachment = new FileAttachmentAnnotation(page, fragment.Rectangle, doc.EmbeddedFiles[doc.EmbeddedFiles.Count]);
fileAttachment.Icon = FileIcon.Paperclip;
// add FileAttachment Annotation to Annotations collection of first page
fileAttachment.Opacity = 0;
fileAttachment.File.IncludeContents = false;
page.Annotations.Add(fileAttachment);
}
doc.Save(dataDir + "linktofile.pdf");
Hi asad,
Thanks for your quick replay.
in the above code we are attaching the destination file to input pdf.
But, I need hyperlink functionality when we change the location of the destination file, the Hyperlink path in also updated to new location we have changed.
please help me with the code to achieve the above functionality.
I have to apply inherit zoom ,color etc… This type of link properties to external hyperlink.
Thanks and Regards,
Harish
@HarishGali
If you are going to change the location of destination file, there is nothing in it that could trigger something in the source PDF to change the hyperlink URL or file path for that file. However, if you already have such file with you, could you please share it with us? We will test the functionality in our environment and address it accordingly.
Hi asad,
I too don’t have that type of file.
I am looking for creating hyperlinks with relative path like this “…/xyz/filename.pdf”.
Not like “D://xyz/filename.pdf”.
please let me know any chance to create links with the relative path.
Thanks and regards,
Harish
@HarishGali
It is unfortunately not possible at the moment using any direct method or approach in the API. Also, we are not aware of such feature in the Adobe Reader as well. The API mimics the behavior of Adobe Reader and is built on its standards. If any feature is not offered by Adobe Reader, it is highly unlikely that Aspose.PDF will support it.
We have also logged an investigation ticket as PDFNET-53316 in our issue tracking system for the sake of further analysis. We will look into its details and let you know in case we find some feasibility. Please spare us some time.
We are sorry for the inconvenience.