将另一个php网页转换为pdf,并在当前php页面上点击按钮保存在服务器中

时间:2017-03-31 14:25:17

标签: php pdf

我使用的是PHP4.4。并希望将其他网页转换为PDF,并在我当前的PHP页面点击按钮时将其保存在服务器中。

有很多选项,但都支持PHP> 5版。

我想要一些API,如果我将传递网页网址并点击当前网页上的按钮,那么它应该将该网页转换为PDF并保存在服务器中。

请推荐一些免费版API。已经尝试了许多选项,如wkhtmltopdf,FPDF,PDFJs等。但是没有任何效果,因为我使用的是PHP 4.4。

1 个答案:

答案 0 :(得分:0)

Mybe,你帮忙using Pdfcrowd。 简单的例子:

require 'pdfcrowd.php';

try
{   
    // create an API client instance
    $client = new Pdfcrowd("username", "apikey");

    // convert a web page and store the generated PDF into a $pdf variable
    $pdf = $client->convertURI('http://example.com/');

    // set HTTP response headers
    header("Content-Type: application/pdf");
    header("Cache-Control: no-cache");
    header("Accept-Ranges: none");
    header("Content-Disposition: attachment; filename=\"created.pdf\"");

    // send the generated PDF 
    echo $pdf;
}
catch(PdfcrowdException $e)
{
    echo "Pdfcrowd Error: " . $e->getMessage();
}

Pdfcrowd是简单的库结束,如果你捕获异常,你将更改库。 Mybe对你很有帮助。

相关问题