1

I have an external php file that contains the code to generate pdf using DOMPDF. I needed to access WordPress built-in functions in that file. So, by following this link here, I included the following line:

require_once(plugins_url().'/../../wp-load.php');

Now, I am able to call WP functions, but the generated pdf is broken i.e I get "error trying to open the pdf..".

If I comment out the require_once line, the pdf comes out fine. Any ideas why this might happen?

3
  • Adding this information, in case someone might find it useful. If I open the generated report in Notepad++ It contains all php comments of my file in it, while a normal report (the one generated without putting wp-load) does not contain those comments. Commented Jul 25, 2014 at 7:07
  • The actual PHP code, or just random comments? If the PDF is being produced then you probably have output buffering enabled. This can cause problems when parsing a file because some output (PHP notices, for example) can get caught in the output stream before dompdf creates the PDF. Commented Jul 28, 2014 at 23:04
  • @BrianS It is the actual php comments. Commented Aug 4, 2014 at 7:45

1 Answer 1

1

Figured out my problem. What I was doing was this: I was fetching contents from a POST variable, and appending its content into the dompdf html. The problem, was I was including the wp-load.php file before fetching the POST variables. Hence my post variables were getting garbled, I suppose. Now, I changed the order i.e I read all the POST variables, saved them into other variables and then did include wp-load.php. Everything worked smooth then. Not sure whether this is the correct way, but it worked for me. Thanks for everyones help. I am marking this thread as solved

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

Comments

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.