简体   繁体   English

网页转换为PDF按钮

[英]Webpage convert to PDF button

I have a website now and I want to create a button on it to convert this page to PDF. 我现在有一个网站,我想在其上创建一个按钮以将该页面转换为PDF。 Is there any code to make this happen? 是否有任何代码可以实现这一目标? I cannot find it on the internet. 我无法在互联网上找到它。

So I want to have a button and when I press on it it converts the page to a .PDF file. 所以我想有一个按钮,当我按下它时,它将页面转换为.PDF文件。

I do not want to use a third party website to generate the PDF's. 我不想使用第三方网站来生成PDF。 I want to use it for internal purposes to generate files with PHP. 我想将其用于内部目的以通过PHP生成文件。 So I need the code what can make a PDF for each page. 因此,我需要可以为每页制作PDF的代码。

I use wkhtmltopdf - works very well - http://code.google.com/p/wkhtmltopdf/ there is a PHP wrapper 我使用wkhtmltopdf-效果很好-http: //code.google.com/p/wkhtmltopdf/有一个PHP包装器

Updated based on comments below on usage : 根据以下有关用法的评论进行了更新:

How to use the integration class : 如何使用集成类

require_once('wkhtmltopdf/wkhtmltopdf.php');     // Ensure this path is correct !
$html = file_get_contents("http://www.google.com");
$pdf = new WKPDF();
$pdf->set_html($html);
$pdf->render();
$pdf->output(WKPDF::$PDF_EMBEDDED,'sample.pdf');

Use FPDF . 使用FPDF It's a well-respected PDF-generating library for PHP that is written in pure PHP (so installing it should be dead simple for you). 这是一个备受尊敬的PHP PDF生成库,它是用纯PHP编写的(因此,安装对您来说应该很简单)。

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

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