1

In Short...

I have an ASP.NET script that generates a PDF based on parameters passed to it. Firstly, I need to be able to call this script from PHP, and secondly, I need to ensure that the file is not stored once it is sent to the browser.

Calling the Script

So my first question is, how can I execute a .NET application that requires DLL's from PHP? I read something about PHP's Component Object Model, but I am a little unsure as to what this is and how it works (I have read here). Alternatively, would it be better to compile this script into an .exe and call it through that?

Furthermore, is it possible to pass parameters to an .exe when calling it via PHP?

Sending the file without Storing it

Once the file has been generated (either via .NET or via an .exe), I would like to send it to the browser without storing it on the server. I have looked at the following threads:

  1. Creating A Temporary File in Php
  2. Create temporary file and auto removed

The above threads may contain the correct answer, but I wasn't sure whether it was possible to send a PDF using any of these methods...

To Conclude

I would like to write a script that achieves the following:

  1. Calls a script (either a .NET application or an .exe), with parameters!
  2. Outputs the resulting contents (a PDF) to the browser without storing it on the server

I am not asking anybody to write this script for me, I simply would like some pointers to allow me to write this myself :-)

There is no point in storing these PDF's on the server as they will rarely be the same

Community
  • 1
  • 1
Ben Carey
  • 16,540
  • 19
  • 87
  • 169

1 Answers1

1

Answering to your questions....

=>. So my first question is, how can I execute a .NET application that requires DLL's from PHP?

Sure, you must create a COM Object to interact with it. In the same page you write there's an example for it like this one for openning a com object for a word interaction....

<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";

//bring it to front
$word->Visible = 1;

//open an empty document
$word->Documents->Add();

//do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");

//closing word
$word->Quit();

//free the object
$word = null;
?>

=> Calls a script (either a .NET application or an .exe), with parameters!

You must have the cli for php in an accesible route to call it with like a console with parameters. You'll have them in the argv array from PHP.

=> Outputs the resulting contents (a PDF) to the browser without storing it on the server

Send the correct header to the browser type:application/pdf and it will open what you describe. Like this one

The code :

    <?php
$file='/files/the.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="the.pdf"');
@readfile($file);
?>

Well you get the point... :)

Community
  • 1
  • 1
Tony
  • 3,425
  • 10
  • 30
  • 46
  • Sounds promising, I will give it a go and come back to you. In the meantime, how do I run a .NET script instead of loading a specific application as you have suggested? – Ben Carey Jun 13 '13 at 11:55
  • Edited... hope this get you a first approach to the solution. – Tony Jun 13 '13 at 12:01
  • Awesome, will have a play around and come back to you. Thanks for your help so far. +1 :-) – Ben Carey Jun 13 '13 at 12:02