简体   繁体   English

在将网页打印为PDF时保留内部链接

[英]Keeps internal links when printing webpage to PDF

I am working with Chrome (up to date) 我正在使用Chrome(最新)

I would like to export a webpage to PDF (via print) and keep internal links like : 我想将网页导出为PDF(通过打印),并保留以下内部链接:

<a href="#Section1">Section 1</a>

For now it seems to keep the "a" tag because the element is clickable, but clicking on it doesn't do anything. 目前,由于该元素是可单击的,因此似乎保留了“ a”标记,但是单击该元素不会执行任何操作。

It is even possible ? 甚至有可能吗?

You can use the pdf-converter built into LibreOffice Writer. 您可以使用LibreOffice Writer内置的pdf转换器。 I have had good results with that, including working internal links. 在此方面,包括在工作内部链接方面,我都取得了不错的成绩。

  1. Save the page as html 将页面另存为html
  2. Open the saved html file in LibreOffice Writer 在LibreOffice Writer中打开保存的html文件
  3. Tweak the layout, remove unwanted sidebars, etc. 调整布局,删除不需要的侧边栏等。
  4. Export to pdf. 导出为pdf。

This has the added advantage that you get the chance to tweak your results in step 3 to avoid things, like lines only filling about half the page width, that often occur when directly printing from the browser. 这样做还有一个好处,就是您有机会在步骤3中调整结果以避免出现诸如仅填充页面宽度一半的行之类的情况,而这种情况通常是在从浏览器直接打印时经常发生的。

A possible drawback may be that this could fail for websites that are dynamically generated so they don't save well as html. 可能的缺点是,对于动态生成的网站,这可能会失败,因此它们无法很好地保存为html。 I have not had the desire to print/convert one of those pages yet though. 不过,我还不想打印/转换这些页面之一。

In my own testing of a fresh Chrome download, viewing an HTML page that uses internal links ( this one from the United States Access Board on some technical standards), I found that it offers a "Save as PDF" option on its Print menu (select the Change... button, and find the first option under the Local Destinations subhead), and that does emit a PDF file with working internal links. 在我自己对全新的Chrome下载进行的测试中,查看了使用内部链接的HTML页面(根据某些技术标准, 链接来自美国访问委员会),我发现它在“打印”菜单上提供了“另存为PDF”选项(选择“更改...”按钮,然后在“本地目标”子标题下找到第一个选项),它会发出带有有效内部链接的PDF文件。

I should add that I'm not 100% certain that it came with Chrome, because all my test machines have Acrobat installed as well, but I don't see the same entry in the Print menu of my IE browsers, so I believe "Save as PDF" is an actual Chrome feature, and not just an Acrobat plug-in. 我应该补充一点,就是我不确定100%都安装了Chrome,因为我所有的测试计算机也都安装了Acrobat,但是我在IE浏览器的“打印”菜单中没有看到相同的条目,因此我相信“另存为PDF”是Chrome的实际功能,而不仅仅是Acrobat插件。

There are also various other products out there offering HTML-to-PDF conversions, including those that specifically promise to preserve internal links, so if you chose one that installed as a Print driver, you could then have that same full-featured HTML-to-PDF capability in any browser, not just Chrome, by simply picking that conversion tool from your printer menu. 还有许多其他产品提供HTML到PDF的转换,包括专门承诺保留内部链接的产品,因此,如果选择安装为打印驱动程序的产品,则可以使用相同的全功能HTML-to。只需从打印机菜单中选择该转换工具,即可在任何浏览器(不仅限于Chrome)中提供-PDF功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM