最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - generate PDF from window.print() result - Stack Overflow

programmeradmin4浏览0评论

Is there any way to get and download a pdf from the output of the window.print () mand.

For example:

I have a button that launches the window.print () method, this launches a popup of browser print options with print options, and I can select pdf and generate the document correctly.

What I need is that by clicking I download the PDF file automatically.

Is there any way to use the result of windows.print to download the pdf, either bining it with some js library. All on the client side?

thank you.

ok I'll try. The plugin that I use to generate the pdf is datable buttons and exports the table to pdf, all this works fine, but there is a screen print button that also generates a tab with the view to print, the problem is that when using this function in chrome, everything works ok, but it allows me to return to the main view, and the printing tab for this is linked to the main view so no action is allowed in the main view, I would like to block the main view when it opens the printing tab

Is there any way to get and download a pdf from the output of the window.print () mand.

For example:

I have a button that launches the window.print () method, this launches a popup of browser print options with print options, and I can select pdf and generate the document correctly.

What I need is that by clicking I download the PDF file automatically.

Is there any way to use the result of windows.print to download the pdf, either bining it with some js library. All on the client side?

thank you.

ok I'll try. The plugin that I use to generate the pdf is datable buttons and exports the table to pdf, all this works fine, but there is a screen print button that also generates a tab with the view to print, the problem is that when using this function in chrome, everything works ok, but it allows me to return to the main view, and the printing tab for this is linked to the main view so no action is allowed in the main view, I would like to block the main view when it opens the printing tab

Share edited Dec 14, 2017 at 23:17 Carlos Aguilar asked Aug 18, 2017 at 13:59 Carlos AguilarCarlos Aguilar 731 gold badge1 silver badge6 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 0

I think you might want to have a look at something like jsPDF from Parallax (https://parall.ax/products/jspdf).

This is a clientside PDF generation library that should be able to render your page and offer it as a download.

You may try to use the download attribute inside your <a> tag:

<a href="content/yourfile.pdf" download > pdf link of your choice </a>
<a href="content/yourfile.doc" download > doc link of your choice  </a>
发布评论

评论列表(0)

  1. 暂无评论