Html 从 PDF 文件在新选项卡中打开链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39762965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:51:57  来源:igfitidea点击:

Open link in new tab from PDF file

htmlpdf

提问by Rakesh Soni

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.

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

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

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

<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.

但是当将此 PDF 打开到 chrome 或 firefox 浏览器并单击 PDF 中存在的任何链接时。正在打开的链接是相同的 TAB 而不是新的 TAB。请帮助找出解决方案。以便我的 PDF 驻留在一个选项卡中,链接将在浏览器的另一个选项卡中打开。

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.

但没有什么对我有用。

回答by flyx

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.

长答案:PDF 中的超链接与 HTML 中的超链接不同。PDF 并非旨在作为浏览体验的一部分进行查看。因此,没有选项可用于 PDF 超链接在新选项卡中打开它们,因为 PDF 不知道选项卡的概念。

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

Adobe 的论坛中有一些关于它的讨论,归结为“不能直接实现,但您可以在 PDF 中嵌入 JavaScript 来实现”。他们以 EPS 文件为例:

%!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.

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