实际上,我已经使用url和静态html页面将html转换为pdf。但现在,从我的网址或html页面,我不希望整个页面通过pdf转换。我只想通过我的网页的几个内容为html到pdf转换。
假设下面是我的html,我只想将html的第2‘div传递到pdf转换,而不是整个html。那么,如何只传递一部分html来进行转换。
<!DOCTYPE html>
<head>
</head>
<body>
<div id="print-area">
<div id="header">
This is an example header.
</div>
<div id="content">
<h1>Demo</h1>
<p>This is example content</p>
</div>
<div id="footer">
This is an example footer.
</div>
</div>
</body>
</html>下面是我的php代码--实际上,从我的html页面中,我将url发布到这个php页面,并且不希望整个网页转换为pdf,.i只想将一个div转换为pdf。
<?php
require_once('WkHtmlToPdf.php');
$url = trim($_POST['textLink']);
$urlLink = "'$url'";
$date = date("Y-m-d");
$pdfNm = 'testPDF' . $date . '.pdf';
// Create a new WKHtmlToPdf object with some global PDF options
$pdf = new WkHtmlToPdf(array(
'use-xserver',
'no-outline', // Make Chrome not complain
'margin-top' => 0,
'margin-right' => 0,
'margin-bottom' => 0,
'margin-left' => 0,
));
// Set default page options for all following pages
$pdf->setPageOptions(array(
'disable-smart-shrinking',
'user-style-sheet' => 'css/pdf.css',
));
$pdf->addPage($urlLink); //we can also pass html file for conversion
//$pdf->addPage('demo.html');
//$pdf->saveAs('/tmp/new.pdf'); //Save as rather than sending it to user to save
$pdf->send($pdfNm)现在,我不希望整个网页内容的html到pdf转换使用wkhtmltopdf。我只想要一个特殊的设计资料。
发布于 2013-11-26 09:07:42
如何GETting文件,parsing it using some HTML parser,提取您想要的内容,然后提供给$pdf?我不知道您使用的包装器,但我认为这是可能的,即使您不使用流在这里。
如果没有,请将提取的部分保存为文件,并将该文件提供给$pdf。
在PHP中提取部分HTML有一个很好的答案:https://stackoverflow.com/a/3577654/694325
https://stackoverflow.com/questions/20193781
复制相似问题