使用TCPDF将特定div转换为PDF [英] Using TCPDF to Convert specific div to PDF

查看:122
本文介绍了使用TCPDF将特定div转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用javascript编写的web应用程序。在应用程序结束时,向用户呈现收据,该收据显示他们在他们的应用程序的操作过程中的所有动作。我想将此收据转换为PDF文件,以便更容易地访问它(例如,下载,打印等)。我无法针对希望用作收据的特定div。

 < div id =receipt> ---一些内容---< / div> 

我想定位特定的div'收据',但只在应用程序结束时(我是修改DOM很多,因此收据div每次都包含新内容,并且只在最后才有关)。我想知道的是,是否有一些PHP命令从网页获取HTML文本,以便我可以将该变量输入到TCPDF PHP调用中:

 ($ html,true,false,true,false,''); 

其中第一个变量是一些html文本。



如何声明一个变量$ html,其中包含.html页面中的特定div?

解决方案


  1. 在收据底部添加一个'打印'按钮。

  2. 在'onclick '打印按钮的事件。获取收据div的内容(使用jquery:$('#receipt')。html()或javascript'document.getEmementById('receipt')。innerHTML')。将此内容添加到表单中的隐藏变量。将表单提交给专用的php文件。 (< form target ='_ blank')

  3. 您在专用php文件中获得了发布数据。
    $ b $ html = $ _POST ['hiddenHtml'];


  4. $ pdf-> writeHTML($ html, true,false,true,false,'');


I have a web application written in javascript. At the end of the application, the user is presented with a receipt that shows all their actions during the course of their operating the application. I want convert this receipt into a PDF file so that it can be accessed more easily (e.g., download, print, etc.) I am having trouble targeting the specific div that I wish to use as the receipt.

<div id="receipt"> --- Some Content --- </div>

I want to target the specific div 'receipt' but only at the end of the application (I am modifying the DOM a lot, and thus the receipt div contains new content each time, and is only relevant at the end). What I am wondering is whether there is some PHP command to get the HTML text from a webpage so that I can input the variable into the TCPDF PHP call:

$pdf->writeHTML($html, true, false, true, false, '');

Where the first variable is some html text.

How can I declare a variable, $html, that contains a specific div from the .html page?

解决方案

  1. Add a 'print' button at the bottom of the receipt.
  2. Add a javascript function at the 'onclick' event of the print button. Get the content of the receipt div ( using jquery: $('#receipt').html() or javascript 'document.getEmementById('receipt').innerHTML'). Add this content to a hidden variable in a form. Submit the form to a dedicated php file. (<form target='_blank')
  3. You got the the post data in the dedicated php file.

    $html = $_POST['hiddenHtml'];

  4. $pdf->writeHTML($html, true, false, true, false, '');

这篇关于使用TCPDF将特定div转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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