Is it possible to generate automatically a pdf from a grid and send it attached to a mail every day?

Hello, I am currently trying scriptcase and I was wondering if it possible to generate automatically a pdf from a grid and send it attached to a mail every day. My goal is to create an app with grids and charts with various data and then export the results with a pdf attached to a mail. I already saw that it was possible to send a mail manually , but is it possible automatically directly with ScriptCase ?
If not, is it still possible with a script that will run every day apart from the app ?

I assume that you want to have a scheduled program. That means that you will run your application most likely in a cron procedure. Such an application cannot have user interaction, so you cannot use form components here. You must use a blank application and perform that tasks manually. I think that it will be quite a challenge in scriptcase.

Well, you can create two apps, one grid app that creates the PDF, and you can setup it as returns the PDF directly, then you can create a blank app where you call the first grid app and save the output (file pdf) on a folder (using file_get_contents) once saved the file, you can send email with the PDF attached.

If you need to run the blank app every day, just make a cron that call the blank app.

New for me. You can call a grid application from blank application in a cron? The Grid needs a trigger to generate the pdf, so who is doing that. I don’t think that the user means to manually generate the pdf, at least that’t not how I read it :wink:

With cron you schedule a php -f or curl or wget to call the blank application.

In the blank app, you use this code to get the PDF , and save it, then you can send the email.

$path = 'http://someserver/somepath/gridoutpdf/index.php';
$storeLocation = '/pdf/mypdf.pdf';
$PDF_CONTENTS = file_get_contents($path);
file_put_contents($storeLocation, $PDF_CONTENTS);

Maybe, you ave to add some context to the file_get_contents, since it isn’t a browser that call the grid app, but it’s possible to create one, and pass it to the function there are plenty examples, and google helps a lot :smiley:

Yes, this is common practice. But how do you integrate the pdf creation from the grid in a cron? My point is that to generate a pdf from a grid requires manual action by the end-user. In a cron, there is no end-user. So my approach would be to create a blank application with a regular sql query on the database creating the information and pdf. And not from a grid as that simply will not work in an automated procedure. But if you know a trick that I can emulate user action in a cron, then I sure would like to know.

I see, no tricks, in the grid app, in Initial Settings, you can choose how tha app start, the grid, or the search window, or, in our case, PDF, if you set PDF, when you run (call) the grid you get PDF, so no manual action.

If I got what you meant. :smiley:

I made a quick test, actually, for SC grid, you don’t get the PDF content, but an HTML with code


so it’s not necessary save the file, but you know where is it.

If I summarize, I have to create my grid and set it as a PDF in the Initial Module, then create a blank app with the file_get_content to run the grid, and finally retrive the PDF with the path of the file (and use a cron or curl to do it automatically). So I tried doing that, but when I run the grid with file_get_content and then use file_put_contents, I get the file “index.php” from my grid, and I can’t find the line:


Am I doing something wrong ?

I’ve been searching for a while now, and I might have found some sort of solution. I created a grid and set it as a PDF in the initial setting and deployed the app on my web server. I noticed that every time I exported a PDF, it was stored in a directory named “./_lib/tmp”. So I created a php script that copy and rename the PDF and delete the one in /tmp, then it sends a mail with the new PDF attached. But, I had one problem, it was the fact that we can’t call the SC grid without an Internet page. So, I created a .bat file that opens an Internet page with the grid which generates the PDF in ./_lib/tmp and then I use my php script. Finally I used a schedule task to do it automatically.
I don’t think it is the best solution, but it’s the only one I could figure out, hope it helps someone one day ! :slight_smile:
Now I’m wondering if it is also possible with a chart and then regroup the two PDF :thinking:

Puoi provare ad utilizzare pdftk (pdftk nomefilegriglia nomefilegrafico cat output nomefilenew)