This topic is locked
[SOLVED]

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

Tandy author 6/25/2025

Thanks Guys for trying to help. I have tried all different kinds of way.. Tried changing stock code and adding my own custom button. Nothing I have found will change the filename to a listing that is on that page (TripSheet645234.pdf. I am at the point that I do not have the knowleage or really wondering if it can or not be done. I have searched the forums as was as the manual. Just can not find anything that will do it.

Thanks again all..

C
Chris Whitehead 6/26/2025

Are you clicking the PDF view button on the print page rather than a custom button?

This is where I mean in designer click the print tab and then click the pdf view button, the filename is on the right, is this the filename you want to change?
img alt

If it is that button, you can rename the filename on the button. You could get the any other value and store in a proxy then pass to the javascript on load.
This is placed in the events page and in the "printer friendly page / javascript on loan" event.

$(document).ready(function () {

// get the proxy value which is set in the before display event
var loan_agreement_number = proxy.master['loan_agreement_number'];

// Get the original filename from the button
var $pdfBtn = $("a.pdflink[data-filename]");

if ($pdfBtn.length) {

// Build the new filename
var baseName = "loan_" + loan_agreement_number + ".pdf";

// Update the attribute
$pdfBtn.attr("data-filename", baseName);
}
});

This is in the before display event in the "printer friendly page"

$master = $pageObject->getMasterRecord();
$pageObject->setProxyValue("master",$master );
C
cristi 6/27/2025

This action of yours takes place where?? List page, View page, Custom page?

C
Chris Whitehead 6/27/2025

Sorry, I thought I'd said, it's just the printer friendly page which prints the records on the list page but I'm guessing this works on all pages that can produce a PDF view.

If Printer friendly and PDF view are enabled in the pages section within PHPRunner.
img alt

On the list page there's the print button, clicking this displays the printer friendly page.
img alt

You will see the PDF view button in the printer friendly page.
img alt

When then PDF view button is viewed in inspector, you can see the PDF filename stored in the data attribute, all the javascript does it change this value.
img alt

fhumanes 6/27/2025

Hello everyone,

I am aware that my answer does not conform 100% to the question, but I believe that a more powerful and quite simple solution is what is explained in this article: https://asprunner.com/forums/topic/31059-Create-Invoice-or-Reports-with-PDFMake

The problem of the name of the file, the quality of the generated PDF document, etc., is resolved "easily" with the solution of the example.

I have been reading the answers and only, for opening an alternative to consider, I have decided to write this note.

Greetings,
fernando

Tandy author 6/28/2025

Thanks Guys, Still trying to figure this out but it is on hold. Some how I screwed up my coding some where and trying to fix that first to get my site back up and running. Once I get whatever I did to it figured out I will be back trying this again.

Tandy author 6/28/2025

Trying to figure this code out I have now. Has to be something I did or hit working on this. It is in my Designer part at the bottom:

{"message":"Uncaught (in promise): HttpErrorResponse: {\"headers\":{\"normalizedNames\":{\"_t\":\"Map\",\"_i\":{},\"_s\":0},\"lazyUpdate\":null,\"headers\":{\"_t\":\"Map\",\"_i\":{},\"_s\":0}},\"status\":0,\"statusText\":\"Unknown Error\",\"url\":null,\"ok\":false,\"name\":\"HttpErrorResponse\",\"message\":\"Http failure response for (unknown url): 0 Unknown Error\",\"error\":{\"message\":\"Http failure response for (pd/api/buildstyle)\",\"notes\":\"The operation failed and didn't complete.\"}}","stack":"Error: Uncaught (in promise): HttpErrorResponse: {\"headers\":{\"normalizedNames\":{\"_t\":\"Map\",\"_i\":{},\"_s\":0},\"lazyUpdate\":null,\"headers\":{\"_t\":\"Map\",\"_i\":{},\"_s\":0}},\"status\":0,\"statusText\":\"Unknown Error\",\"url\":null,\"ok\":false,\"name\":\"HttpErrorResponse\",\"message\":\"Http failure response for (unknown url): 0 Unknown Error\",\"error\":{\"message\":\"Http failure response for (pd/api/buildstyle)\",\"notes\":\"The operation failed and didn't complete.\"}}\n at resolvePromise (http://localhost:8085/polyfills.bundle.js:7313:25)\n at Anonymous function (http://localhost:8085/polyfills.bundle.js:7223:17)\n at Anonymous function (http://localhost:8085/polyfills.bundle.js:7239:17)\n at ZoneDelegate.prototype.invoke (http://localhost:8085/polyfills.bundle.js:6872:13'>http://localhost:8085/polyfills.bundle.js:6872:13)\n at onInvoke (http://localhost:8085/vendor.bundle.js:57777:17)\n at ZoneDelegate.prototype.invoke (http://localhost:8085/polyfills.bundle.js:6872:13'>http://localhost:8085/polyfills.bundle.js:6872:13)\n at Zone.prototype.run (http://localhost:8085/polyfills.bundle.js:6632:17)\n at Anonymous function (http://localhost:8085/polyfills.bundle.js:7371:17)\n at ZoneDelegate.prototype.invokeTask (http://localhost:8085/polyfills.bundle.js:6904:13'>http://localhost:8085/polyfills.bundle.js:6904:13)\n at onInvokeTask (http://localhost:8085/vendor.bundle.js:57768:17)\n at ZoneDelegate.prototype.invokeTask (http://localhost:8085/polyfills.bundle.js:6904:13'>http://localhost:8085/polyfills.bundle.js:6904:13)\n at Zone.prototype.runTask (http://localhost:8085/polyfills.bundle.js:6677:21)\n at drainMicroTaskQueue (http://localhost:8085/polyfills.bundle.js:7083:25)\n at ZoneTask.invokeTask (http://localhost:8085/polyfills.bundle.js:6984:21)\n at invokeTask (http://localhost:8085/polyfills.bundle.js:8226:9)\n at globalZoneAwareCallback (http://localhost:8085/polyfills.bundle.js:8252:17)"}
C
Chris Whitehead 6/28/2025

That looks like something gone wrong in the built in server. I know code in the style section can affect that sometimes but other than that, I can't help with that.

Tandy author 6/28/2025

Yea, I re-installed the program. Think something is going on with my PC to do that. Don't think it had anything to do with PHPRunner at all.. Just had to re-install it. Then re-upload my last saved file.. That error went away. Now trying to fix different parts that got messed up or not on my last save.. Thank You..