Open link in new tab of browser from PDF file
Asked Answered
E

1

36

I have created the PDF file programmatically. For this, I have used the HTML to PDF converting library. In my PDF there are some links for some pages of website.

I have implemented the html by following way and then converted it to PDF programmatically.

<a target="_blank" href="http://mywebsite_url_here.html">Link</a>

But when opening this PDF into chrome or firefox browser and clicking on the any link exist in PDF. Links are opening is same TAB instead of the new TAB. Please help to find out the solution for this. so that my PDF reside in one tab and link will open in another tab in browser.

I have already tried

target="_blank"

target="_top"

<a onclick="window.open ('http://mywebsite_url_here.html', ''); 
 return false" href="javascript:void(0);"></a>

But nothing has worked for me.

Erwinery answered 29/9, 2016 at 6:31 Comment(1)
Usually using Adobe Acrobat if you right click on the link properties. Click the Actions tab. If there are any actions listed delete them and then select Run a Javascript. Click add. A box will appear for you to add the following javascript. app.launchURL("yourlink.com", true); it will open in new tab. so if you can make it programmatically then it may solve your problem.Hoplite
G
44

Short answer: It is not possible in a cross-plattform, guaranteed-to-work way.

Long answer: Hyperlinks in a PDF are different from Hyperlinks in HTML. PDF was not designed to be viewed as part of a browsing experience. Hence there is no option available for PDF Hyperlinks to open them in a new tab, because PDF does not know about the concept of tabs.

There is some discussion in Adobe's forums about it, which boils down to „not directly possible, but you could embed JavaScript in the PDF to do it“. They give an EPS file as example:

%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 100 100
%%EndProlog

[ /Rect [ 0 0 100 100 ]
/Action << /Subtype /JavaScript /JS (app.launchURL\("PLACE-YOUR-URL-HERE", true\);) >>
/Subtype /Link

/ANN pdfmark

%%EOF

Now before you try and get this EPS file embedded in your PDF, be aware that Chrome's PDF viewer has very little support for embedded JavaScript, so it is not guaranteed to work. It may also issue a warning to the User that there is JavaScript code going to be executed if they click on it. I would say it isn't worth the hassle.

Gustation answered 29/9, 2016 at 7:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.