从PDF文件的新选项卡中打开链接 [英] Open link in new tab from PDF file

查看:188
本文介绍了从PDF文件的新选项卡中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式创建了PDF文件。为此,我使用了HTML到PDF转换库。在我的PDF中有一些网页的链接。

我通过以下方式实现了html,然后以编程方式将其转换为PDF。

 < a target =_ blankhref =http://mywebsite_url_here.html>连结< / a> 

但是,在PDF中打开此PDF到Chrome或Firefox浏览器并单击任何链接时,链接打开是相同的TAB而不是新的TAB。请帮助找出解决方案。所以我的PDF驻留在一个标签中,链接将在浏览器的另一个标签中打开。



我已经试过了

< pre $ target =_ blank

target =_ top

return falsehref =javascript:void(0);>< / a>

但对我来说什么都没有。

简短回答:这是不可能的跨平台,保证工作的方式。



长答案:超链接在PDF中与HTML中的超链接不同。 PDF并非旨在被视为浏览体验的一部分。因此,PDF Hyperlinks没有选项可以在新选项卡中打开它们,因为PDF不知道制表符的概念。



有一些在Adobe的论坛中讨论,它归结为不是直接可能的,但你可以 >在JavaScript中嵌入JavaScript来完成它。他们以EPS文件为例:

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

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

/ ANN pdfmark

%% EOF

现在在尝试将这个EPS文件嵌入到PDF中之前,请注意,Chrome的PDF查看器具有对嵌入式JavaScript的支持很少,所以不能保证能正常工作。它也可能向用户发出警告,如果他们点击它,将会执行JavaScript代码。我会说这是不值得的麻烦。


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.

解决方案

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.

这篇关于从PDF文件的新选项卡中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆