PDF file name from field names or variables

Like said in the title I need to generate pdf files with the wkhtmltopdf export function named from different fields of the grid itself. E.g. field_name field_date and so on.
I was messing around with the macro sc_set_pdf_name which works well if I’m defining a simple name like “report.pdf”. But I need to use variables or field names.

Trying

sc_set_pdf_name = "[global_variable]  .  '.pdf'";

or

sc_set_pdf_name = "{field_name}.pdf";

or variants of that

doesn’t bring the results I want (in OnScriptInit).

Can anybody help there?

Joe

Hello,
probably is not helpful but try to make a test using ‘[SIZE=12px][global_variable]’ . ‘.pdf’; or ‘[/SIZE][SIZE=12px]{field_name}’ . ‘.pdf’;[/SIZE]

Sorry, I found no way regardless what variants I try. When I use it in OnScriptInit no variables or field names work. But I found out if you use it in onHeader you can get results but nothing I wanted to get (like cutting strings if the string in the variable contains space characters and so on). I have to find another solution.

Would it be possible to use a run button to generate the wkhtmltopdf command line? I think it would be a flexible way to generate the pdf file, name it and save it to a certain directory?
Did anybody already do this?

How do you use wkhtmltopdf? With shell_exec or with exec?
OR do you use passthru?

To be honest I have no clue how to use it. I’m just reading some php stuff about that and security issues.
Could you give me a hint how to use wkhtmltopdf?

Well you need to check the main page http://wkhtmltopdf.org as you see it is an executable. So you would need to call (under windows) something like exec(‘c:/tools/wkhtmltopdf.exe http://www.mysite.com/mypage’); See here: http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
I’m just reading it from the site…
I find creating a pdf in scriptcase itself easy enough to get most work done so I dont use wkhtmltopdf. wkhtmltopdf simply access a webpage and makes a pdf from it.
Anyway there are examples on the forum afaik.

I was trying to read the SC code where the pdfs are generated. But it’s so hard to read because of the many portuguese names in it.
The code is in the index.php of a grids directory.
I wish the variable names were in english and the code was documented.

Further the usage of php code in a button is not documented very well.

Well the best thing I did to learn it was to generate a pdf via setting the fields and their positions on the pdf and just generating one. Then I looked through the generated source code, and saw how it basically worked. It is indeed not documented that well but you should really check this: https://www.youtube.com/user/ScriptCaseVideos
it holds this video: https://www.youtube.com/playlist?list=PLDMYt0EmYW5yFCl2g_20pEkBcvhaY7iPF
That may make it a lot easier to understand to understand the basics.

I think we don’t talk about the same thing. The PDF Report uses tcpdf and not wkhtmltopdf. Wkhtmltopdf has less functions and only converts the displayed grid or form or anything other to a pdf file.
This works for me and is much easier to handle than the tcpdf function. My report is a grid with many nested grids and it’s easy to display this all in all grid and convert it from the toolbar with the pdf function. If I would use the tcpdf I think I would have to combine the report with many lookups to get my end report.

So what I’m looking for is the correct way to create a button and use wkhtmltopdf in the command line in a php script maybe in a blank application, where I can create the pdf from my grid (named from variable or field content), save it to a directory and send it via email.

i have never tried make PDF file name from field or variable but i will do my best. Very interesting…

I was trying to modify the generated code of my grid but that was frustrating. I found the code lines where the pdfs are named and generated but couldn’t use global variables inside the php files.

Now back to the SC own possibilities. I created a PHP button in my grid that executes the wkhtmltopdf command but this is without parameters. I need to give wkhtmltopdf a correct link to the grid with i. e. record id from the database to show the correct record in the grid (shortly said I need to create the WHERE clause of my grid). If I run the commend I get an empty record pdf.

How can I implement the correct record id to my wkhtmltopdf command?

I read in some threads about the macro sc_pdf_output but couldn’t find it in the documentation. So I tried the syntax from the thread

sc_pdf_output('nameofpdf'.{field1}.'.pdf',"/var/www/sc81/tmp");

and put that in grid’s onScriptInit.

Result is the grid loads with a blank page.

How can you use this macro? Where is the documentation?

OK - first step done. This is how you can puzzle your own pdf filename

$_SESSION['sc_session'][$this->Ini->sc_page]['your_grid_name']['pdf_name'] = [glo_var1] . '_' . [glo_var2] . '_' . [glo_var3] . '_' . [glo_var4] . ".pdf";

Set global variables you need in onRecord event of your grid. Put code above in onScriptInit of your grid and use the global variables you defined to make filename. Put the name of your grid in [‘your_grid_name’]
The underscore is only a delimiter for me. Notice: the [‘pdf_name’] keeps as is, don’t change that.
BTW I found no way to use field names instead of global variables.

Maybe someone needs that too.

Joe