Вы можете манипулировать ссылками внутри PDF-документа, чтобы запустить JavaScript, чтобы открывать ссылки в новом окне / вкладке. Вот как я это сделал с C#
и iTextSharp
public static MemoryStream OpenLinksInNewWindow(MemoryStream mySource)
{
PdfReader myReader = new PdfReader(mySource);
int intPageCount = myReader.NumberOfPages;
PdfDictionary myPageDictionary = default(PdfDictionary);
PdfArray myLinks = default(PdfArray);
//Loop through each page
for (int i = 1; i <= intPageCount; i++)
{
//Get the current page
myPageDictionary = myReader.GetPageN(i);
//Get all of the annotations for the current page
myLinks = myPageDictionary.GetAsArray(PdfName.ANNOTS);
//Make sure we have something
if ((myLinks == null) || (myLinks.Length == 0))
continue;
//Loop through each annotation
foreach (PdfObject myLink in myLinks.ArrayList)
{
//Convert the itext-specific object as a generic PDF object
PdfDictionary myLinkDictionary = (PdfDictionary)PdfReader.GetPdfObject(myLink);
//Make sure this annotation has a link
if (!myLinkDictionary.Get(PdfName.SUBTYPE).Equals(PdfName.LINK))
continue;
//Make sure this annotation has an ACTION
if (myLinkDictionary.Get(PdfName.A) == null)
continue;
//Get the ACTION for the current annotation
PdfDictionary myLinkAction = (PdfDictionary)myLinkDictionary.Get(PdfName.A);
//Test if it is a URI action
if (myLinkAction.Get(PdfName.S).Equals(PdfName.URI))
{
//Replace the link to run a javascript function instead
myLinkAction.Remove(PdfName.F);
myLinkAction.Remove(PdfName.WIN);
myLinkAction.Put(PdfName.S, PdfName.JAVASCRIPT);
myLinkAction.Put(PdfName.JS, new PdfString(String.Format("OpenLink('{0}');", myLinkAction.Get(PdfName.URI))));
}
}
}
//Next we create a new document add import each page from the reader above
MemoryStream myMemoryStream = new MemoryStream();
using (Document myDocument = new Document())
{
using (PdfCopy myWriter = new PdfCopy(myDocument, myMemoryStream))
{
myDocument.Open();
for (int i = 1; i <= myReader.NumberOfPages; i++)
{
myWriter.AddPage(myWriter.GetImportedPage(myReader, i));
}
// Insert JavaScript function to open link
string jsText = "function OpenLink(uri) { app.launchURL(uri, true); }";
PdfAction js = PdfAction.JavaScript(jsText, myWriter);
myWriter.AddJavaScript(js);
myDocument.Close();
}
}
return new MemoryStream(myMemoryStream.GetBuffer());
}
Я получил большую часть кода из этого ответа: https://stackoverflow.com/a/8141831/596758