This topic is locked

PDF filename

6/23/2025 7:12:20 AM
PHPRunner General questions
Tandy author

Was just wondering if there is a code or a way to change the PDF filename? Something like username with the ID to make the PDFs different from each other? Been trying to find it in the Manual but did not find anything.

ChatGPT 6/23/2025

Yes, you can customize the PDF filename in PHPRunner. To achieve this, you will need to use the BeforeExport event for the PDF export. Here’s a general guide on how to modify the filename to include the username and ID:

  1. Open your project in PHPRunner.


  2. Go to the "Events" section for the table you are working with.


  3. Select the "BeforeExport" event. This event allows you to modify the export settings before the PDF is generated.


  4. Insert the following code into the "BeforeExport" event:

    $username = $_SESSION["UserName"]; // Get the username from session
    $id = $data['ID']; // Replace 'ID' with your actual field name for the ID

    // Set the new filename for the PDF
    $pdf->SetFileName($username . '_' . $id . '.pdf');

    Make sure to replace 'ID' with the actual field name that contains the ID of the record you are exporting.


  5. Save your changes and test the PDF export.



This code will generate a PDF with a filename that includes the username and the record ID, making each filename unique.

If you need further customization or run into any issues, you might want to consult the PHPRunner documentation or reach out to their support for more specific guidance.

Tandy author 6/23/2025

Thank you ChatGPT. Sorry that is not working for me.. It still has the file.pdf when exporting it..

Tandy author 6/23/2025

I have change the name as it says in the documents. Mine is called TripSheet but I can not figure out how to add the file stuff in that name. like username_TripSheet_tripnumber.pdf was just wondering if there is a code like %username% to put in to auto pull the informatin from the so call TripSheet itself.. Been looking through the manual and even done a search. I was wondering if it was even posible..

Tandy author 6/23/2025

Copper21 that is to upload to the server. I am trying to take a PDF from the server but have it as the files number.

See the problem I am having. Say I have 5 different Trip Sheets. 5 different drivers. If I want a PDF each sheet they all say TripSheet.pdf on downloading them.
I would like it to say TripSheet_65378.pdf because each Trip Sheet has it own number that is what the 65378 is..

Sergey Kornilov admin 6/23/2025

I recommend checking PDF API where you can create PDF files and have a full control over PDF file name:
https://xlinesoft.com/phprunner/docs/about_pdf_api.htm

Tandy author 6/23/2025

Thanks Sergey. I was trying that as well. But still having the same problem. Trying to figure out what code to use. Here is what I have that is not right.

ajax.addPDF( 'pdf', {}, function() {

return ctrl.dialog( {
title: 'Save results as PDF',
fields: [{
name: 'filename',
value: 'Trip Sheet $record["trip_number"].pdf'
}]
});
});
return false;

It gives me:
Trip Sheets .$_SESSION[currentRecord][_tripid]

Trying to find out on the manual where I can learn how I can make it say:
Trip Sheet 64534.pdf

The 64534 is the trip number for that trip sheet on the page

C
cristi 6/23/2025

That's because you are mixing php variables with js code more precisely $record["trip_number"] is a php variable that you are using in js code.
If you need to get that value in a row custom button use grid row js row.getFieldText(): https://xlinesoft.com/phprunner/docs/row_getfieldtext.htm

Tandy author 6/23/2025

Thank you cristi,
I do not see how I can add that code into the code already there? I have tried and if throws error codes every way I tried to add it..

C
cristi 6/23/2025

Assuming you are using a custom button inserted in grid you use it like this in "client before":

var filename=row.getFieldText("trip_number"); //asuming your field of interest is called trip_number.

ajax.addPDF( 'pdf', {}, function() {

return ctrl.dialog( {
title: 'Save results as PDF',
fields: [{
name: 'filename',
value: 'Trip Sheet ' + filename + '.pdf'
}]
});
});
return false;
Tandy author 6/23/2025

Thank you very much on trying but that code there came as an error as well:

TypeError: row is null
/include/button_Trip_Sheet_PDF.js?1513_1750617912:8