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?
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