1

wkhtmltopdf is an open source (LGPLv3) command line tools to render HTML into PDF. You can find more information about wkhtmltopdf from here

wkhtmltopdf is not working if input file name has special characters.

Let me put an example to clear the scienerio

Below code is working fine

shell_exec('wkhtmltopdf http://example.com/docs/Export_import_data_masters.html test.pdf');

But below code is not working if url have brackets in file name

shell_exec('wkhtmltopdf http://example.com/docs/Export_(import_data)_masters.html test.pdf');

It fails to create pdf from url if url has special characters in the file name.

Hope i am able to clear the question.

NOTE: File Link is provided by the third party so i can't change the file name or file path.

1
  • Yes, you can change the file name - download the file using file_get_contents() and save it into a file with a simple name. You can then run the exec command without any difficulties. Commented Mar 31, 2016 at 7:38

1 Answer 1

2

There are two issues here:

  1. The second URL is actually invalid. You remember the saying? "Garbage in, garbage out"? Brackets are not amongst the characters allowed in URLs, you have to escape them to form a valid URL:

    http://example.com/docs/Export_%28import_data%29_masters.html

  2. You have to consider that a command you execute in such manner will be interpreted by the shell that is invoked by the exec() call. Shells interpret the input they process, especially control characters. So you might have to put quote chars around a URL argument or escape some characters to make things work.

Sign up to request clarification or add additional context in comments.

1 Comment

yes, its' working. Thank you for reminding me a basic thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.