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?

Community
  • 1
  • 1
user1314305
  • 2,777
  • 2
  • 16
  • 14
  • 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. – user1314305 Jul 25 '14 at 07: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. – BrianS Jul 28 '14 at 23:04
  • @BrianS It is the actual php comments. – user1314305 Aug 04 '14 at 07:45

1 Answers1

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

user1314305
  • 2,777
  • 2
  • 16
  • 14