Creating relative/absolute links & FileSpec-s.

Q:
We are trying to replace URL in a PDF with a relative link to another
PDF, which may or maynot be within the same folder. The code
sinppet(C#) below works fine when the pdf is within same folder, at
the same level as the working PDF. But when we reference to a document
within a subfolder it fails. So when I send the relative URL as "../
12345/ac bd_ef/wx_yz.pdf" it sets it to "/wx_yz.pdf" in the PDF. Are
we doing something worng here or is it the limitation of the
software?

Rect objRec = objAnnot.GetRect();

FileSpec fsNewFile = FileSpec.Create(objPDFDoc.GetSDFDoc(), "../12345/
ac bd_ef/wx_yz.pdf", false);

Action newAction = Action.CreateGotoRemote(fsNewFile, 0,
true);
Annot annotFileSpec = Annot.CreateLink(objPDFDoc.GetSDFDoc(), objRec,
newAction);

annotFileSpec.SetBorderStyle(new Annot.BorderStyle(0));
pageCurrent.AnnotPushBack(annotFileSpec);

*objPDFDoc is the PDF in which we are finding the e_link annotaion.
----

A:

FileSpec::Create() method currently strips away the relative path and
it assumes that the referenced file is in the same folder as the main
PDF.

You can create relative/absolute FileSpec as follows:

FileSpec CreateRelativeFileSpec(PDFDoc doc, string path) {
  Obj fs = doc.CreateIndirectDict();
  fs.Put("Type", Obj.CreateName("Filespec"));
  fs.Put("F", Obj.CreateString(path));
  return FileSpec(fs);
}

Your relative paths seem to be in correct format, but you may want to
make sure that the path are represented in platform independent format
(section 3.10.1 'File Specification Strings' in PDF Reference Manual).
Alternatively you can put "DOS" file-path instead of "F" entry.
Finally, you can also use URL file-paths (i.e.
FileSpec.CreateURL(...)).