1

I want to use wkhtmltopdf to convert a web page to a PDF file. I have a test with a static template and this syntax works perfectly:

wkhtmltopdf my.html my.pdf

The problem is the actual page is a dynamic PHP page with tables that rely on three HTML GET variables.

An example would be:

http://mypage.php?clientid=SJC&datestart=201201&dateend=201202

I can't do this directly like so:

wkhtmltopdf mypage.php?clientid=SJC&datestart=201201&dateend=201202 my.pdf

Someone suggested I needed to call the PHP from the command line with the variables first to get the HTML source code for that set of variables, and convert it using wkhtmltopdf.

How do I do this? What is the process using the above URL as an example?

4

2 回答 2

2

The cleanest way would be using $_SERVER['argv'] instead of the GET variables.

However, if you HAVE to use the GET variables, you can set them in a custom script:

$_REQUEST['var1'] = $_SERVER['argv'][0];

and then require() the PHP script itself.

Another way would be to set the environment variables QUERY_STRING and REQUEST_METHOD:

export REQUEST_METHOD=GET
exprt QUERY_STRING='var1=blub&var2=blah'
于 2012-02-20T14:59:48.797 回答
1

在 Linux 中,您可以使用wget命令从 URL 获取结果 HTML 文件:

wget "http://localhost/mypage.php?clientid=SJC&datestart=201201&dateend=201202"

或者

wget -O myfile.html "http://localhost/mypage.php?clientid=SJC&datestart=201201&dateend=201202"

将结果输出到特定文件,例如myfile.html

笔记:

wget wget -O myfile.html "http://localhost/mypage.php?clientid=SJC&datestart=201201&dateend=201202"

双引号似乎解决了&符号编码问题。

于 2012-02-20T15:01:05.710 回答