简体   繁体   English

将浏览器窗口的打印部分打印为PDF并发送到服务器进行传真

[英]Print Portion of the Browser Window to PDF and Send To Server to be Faxed

Like the title says, I have a requirement to print a part of the browser window to PDF and then send it to the server so that it can be faxed. 就像标题中所说的,我需要将浏览器窗口的一部分打印为PDF,然后将其发送到服务器,以便可以进行传真。 I have already found a faxing service so the real problem is in figuring out how to generate the pdf to begin with. 我已经找到了传真服务,所以真正的问题在于弄清楚如何生成pdf文件。 I have come up with several options to do this, however all of them come with significant downsides. 我想出了几种方法可以做到这一点,但是所有这些方法都有很大的缺点。 They are: 他们是:

  • Use window.print() on a button click along with print media queries and have the user download the resulting PDF and re-upload it to be faxed. 在单击按钮时使用window.print()以及打印介质查询,并让用户下载生成的PDF并重新上传以进行传真。 The problem with this is that it is a multi-step process and my users would prefer to just click a single button 问题是这是一个多步骤的过程,我的用户希望只单击一个按钮
  • Use a library like jspdf to generate the pdf, output to a byte array and upload it to the server. 使用jspdf之类的库来生成pdf,输出到字节数组并将其上传到服务器。 This will work, however it looks terrible because I lose all styling and my print media queries will not be applied. 这将起作用,但是看起来很糟糕,因为我丢失了所有样式,并且将不应用我的打印媒体查询。 So far, this is my best option 到目前为止,这是我最好的选择
  • Render the HTML server side and generate a PDF from that. 渲染HTML服务器端并从中生成PDF。 This will work fine, however it requires duplicating all of the work I have done client side (this is a SPA app) along with duplicating the maintenance. 这将很好地工作,但是它需要复制我在客户端完成的所有工作(这是一个SPA应用程序)以及复制维护。
  • Use a rendering service or library to run the client side application in a headless browser and generate the PDF from that output. 使用渲染服务或库在无头浏览器中运行客户端应用程序,并从该输出生成PDF。 This would be very complicated from a security perspective as the application lives behind a login page. 从安全角度来看,这将非常复杂,因为该应用程序位于登录页面的后面。

I would appreciate any suggestions not listed above as well as any advice on how to eliminate the cons posed by these options. 我会很感激上面未列出的任何建议,以及关于如何消除这些选项带来的弊端的任何建议。 Thanks in advance! 提前致谢!

Looks like using jspdf to render the PDF along with a library such as html2canvas to convert the printable region into an image to preserve styles will get the job done. 看起来像使用jspdf渲染PDF以及html2canvas的库将可打印区域转换为图像以保留样式一样,可以完成工作。 It has taken some work to configure everything properly (and I'm not through yet) but I am confident this solution will be effective. 正确配置所有内容已花费了一些工作(并且我还没有完成),但是我相信该解决方案将是有效的。

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

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