Search code examples
c#hyperlinkpdfboxpspdfkit

How do I add /UF command to a pdf using pdfbox?


I have implemented functionality to add a relative link into a pdf using the pdfbox library.Below is the code that I am using for adding the link:

 PDAnnotationLink txtLink = new PDAnnotationLink();
 PDActionRemoteGoTo remoteGoto = new PDActionRemoteGoTo();
 PDComplexFileSpecification fileDesc = new PDComplexFileSpecification();
 fileDesc.setFile(System.IO.Path.GetFileName(path));
 remoteGoto.setOpenInNewWindow(true);
 remoteGoto.setFile(fileDesc);
 txtLink.setAction(remoteGoto);
 txtLink.setRectangle(rect);
 page.getAnnotations().add(txtLink);

Here is the command entered in the pdf:

14 0 obj
<<
/Type /Filespec
/F (A-201-NORTH & SOUTHSITE ELEVATIONS.pdf)
>>
endobj

The links work in adobe, ios viewer. But does not work in PSPDF. Also, I have file whose link work in PSPDF. But the commands in that file differ slightly from the above.Here is the link command that works in the PSPDF:

113 0 obj
<<
/Type /Filespec
/F (A8.1 - INTERIOR ELEVATION.pdf)
/UF (A8.1 - INTERIOR ELEVATION.pdf)
/Desc()
>>

So, how do I create this command using pdfbox.


Solution

  • To add the /UF entry, use setFileUnicode(String file).

    To add the /Desc entry, use setFileDescription(String description).

    I'm also including the answer by Rad, which is rather a comment and may be deleted:

    If you believe there's an issue in PSPDFKit, please open a support request here. We'd love to help!