This topic is locked
[SOLVED]

New User - PDF Template Questions

12/11/2024 4:43:32 PM
PHPRunner General questions
E
ecornwell author

Hello Everyone,

I'm a new PHPRunner user and purchased the software for a specific purpose / project. We've got a PDF that we're required to fill out and submit on a freqent basis by a 3rd party. We're working on automating it. I've got the SQL query already written that returns all the data needed.

I've got the intial template up and working but I've got a question on the filling portion. The query will return multiple rows, I need to use R1, C1 for one field and R2, C1 for another field, I've not seen where that looks like it's possible, am I missing something?

Addtionally, I'd like to get a specific page created and I'm not sure how. My goal is to have a field that takes a free entry that acts as the WHERE clause on the SQL with a Fill PDF button. The basic work flow would look something like this:

  1. User Logs in with their domain credentails
  2. They enter the invoice number for the data they needed filled out and hit the "Fill PDF" button.
  3. The pre-configured PDF gets filled out with the invoice number they filled in in the where clause

Is this possible?

Thanks!

Sergey Kornilov 12/12/2024

A few things are possible here. Let me explain a few options.

  1. Changing your SQL query so it returns a single record. Should be possible with the help of a subquery. If this can be done, you can just use the built-in export to PDF option on the View page.


  2. Another option is to use PDFForms template: https://xlinesoft.com/pdfforms. You will need to create a PDF form with placeholders for your data and the rest is easy.


  3. Yet another option for generating PDF files on the server side:
    https://xlinesoft.com/blog/2022/11/05/generate-pdf-files-using-nodejs-and-pdfmake/



E
ecornwell author 12/12/2024

Thanks Sergey. I'm using the PDFForms template to acomplish this. What wasn't clear was if I had to try and combine the the rows or if the PDFForms template would accomidate multiple rows.

One of our requirements is to use the PDF provided to us. That's why we're using the PDFForms template.

Any thoughts on creating a page for the filter to just output results from one PDF?

Sergey Kornilov 12/13/2024

I have checked PDFForms template API one more time and it appears that it works with a single data record only.

So, basically you have two options here.

  1. Change your SQL query the way that it returns a single data record.
  2. Or inspect those API functions like saveFormToDisk() and create a new one that can accept the array of data instead of just key values.

E
ecornwell author 12/16/2024

Thanks! I think I'm going to work on getting the SQL to return a single row with all the required data.

Any thoughts on the specific page? So far it looks like I can create my own welcome page. I'd just have to figure out how to add an input box and pass it to the SQL.

Sergey Kornilov 12/16/2024

I guess creating your own page for this purpose is the best option.

Maybe you can get away with using one of the Add pages for this purpose. Create a new dummy table with a single field in it. After the login redirect user to that Add page and make them enter that value. In BeforeAdd event save that value in the session variable and use it on all pages.

E
ecornwell author 12/17/2024

I think I'm slowly getting there.

I was looking at the extensiblity section and I think I want to try and use the showFormInBrowser() function triggered by a button. Where can I find the defintion of that function? I need to figure out how to amend the query to use the filter that I'll be defining with an input field.

Sergey Kornilov 12/17/2024

You can find this function description at https://xlinesoft.com/pdfforms

The SQL query and fiter are irrevevant here as all you need to do is to pass the value of the key column there which points to the desired record.

E
ecornwell author 12/17/2024
E
ecornwell author 12/17/2024

The SQL query and fiter are irrevevant here as all you need to do is to pass the value of the key column there which points to the desired record.

I'm not sure what you mean by this... It is the array("id" => "1") section of the function?

if my view has a column say, "orderid", I can pass it something like "array("orderid" -> TextBoxValue)" and it will pick the the right row?

E
ecornwell author 12/17/2024

Thank you for all the help! I think I'm close. I have my page, the input box, and a custom button that is trying to execute the showFormInBrowser() function.

I'm running into a stacktrace error however now:

[17-Dec-2024 15:08:38 America/New_York] PHP Fatal error: Uncaught Error: Call to a member function fetchAssoc() on bool in C:\Projects\pdftest\output\include\pdfform_functions.php:111
Stack trace:
#0 C:\Projects\pdftest\output\buttonhandler.php(361): showFormInBrowser('Input Capable G...', Array, 100002)
#1 C:\Projects\pdftest\output\buttonhandler.php(77): buttonHandler_Fill_pdftest(Array)
#2 {main}
thrown in C:\Projects\pdftest\output\include\pdfform_functions.php on line 111

Here is the code int he server section of the button:

$filename = "file_" + $params["phid"] + ".pdf";
$result["pdf"] = showFormInBrowser("Input Capable Form",array("orderid" => $params["phid"]),$filename);

Thoughts?

Edit: I think I figured it out. The code looks like it searches for "where" and does a substring then appends. My query is quite long, complex, and contains "where" 12 times in the query before even getting to the end. Looks like I need to make a couple changes there to support this better.

Edit2: Yes, that did it. I ended up putting my query in a view and then called the view and was able to get farther. I've got one more question.
From the Example:

$res = showFormInBrowser($formname, $keys, $pathfile)

/*
Arguments:
$formname - name of the form
$keys - array with key columns values
$pathfile - name of the file

Example:
showFormInBrowser("testform",array("id" => "1"),"temp_filename.pdf");

*/

How do I pass the "$res" object back from the server tri-part? I created a DIV section I could try to display it in but I'm fine with it opening another window was well.

Sergey Kornilov 12/17/2024

I think you need to make sure that $params["phid"] variable is populated and in fact points to one of the records in the database table.

E
ecornwell author 12/17/2024

Thanks Sergey, I was able to get the response back but now it's throwing an error that looks like it's the contents of the PDF. Using the "showFormInBrowser" function in the Server Tri-Part, how do I pass it back to view on the screen? My guess is I have to do something in the "client after" section but I'm at a loss right now.

Sergey Kornilov 12/17/2024

You need to read this function description one more time at https://xlinesoft.com/pdfforms. It explains where you can use this function, which event is suitable for it.

E
ecornwell author 12/18/2024

I read it multiple times before posting. It seemed to indicate those were some options but not the only way to do it.

I'm just about done now but I eneded up having to use the "saveFormToDisk" function instead. This means I'll have to do something on the server to clean up old files but I can write a script easy enough for that.

With that in mind, I think I found a bug in the pdfform_functions.php file. What's the best way to report it?

Here's the DB String for saveFormToDisk:

DB::Select("pdf_forms", array("formname"=>str_replace("'","\'",$formname)."'"))

Here's the showFormInBrowser:

DB::Select("pdf_forms",array("formname"=>$formname))

I couldn't get the Save to work and it was because there was always and extra ' added to the end.

E
ecornwell author 12/19/2024

I got it to work! For future reference, for those interested, here is what I did.

  1. Used the PDFForms Template
  2. Created a new menu and set it to be the default and unchecked skip the menu page option.
  3. Added 3 objects on the page, a code snippet, custom button, and HTML->Text object.
    3a. Code Snippet: (Replaced the sensitive fields with 'aaaa') echo '<label for = "aaaa">aaaa: </label> <input type="number" name="aaaa" id="aaaa" min="100000"></input> ';

    3b. Custom Button
    I. Client Before:

    params["aaaa"] = document.getElementById('aaaa').value;
    if (params["aaaa"].length == 0 || params["aaaa"] == ''){
    Swal.fire({
    icon: "error",
    title: "aaaa must be filled in!"
    });
    return false;
    } else if (params["aaaa"] < 10000) {
    Swal.fire({
    icon: "error",
    title: "aaaa must be a valid number!"
    });
    return false;
    } else {
    var message = "Sending request for " + params["aaaa"] + " to server...";
    ajax.setMessage(message);
    }


II. Server:

$filename = "aaaa_" . $params["aaaa"] . ".pdf";
$path = (__DIR__) . "\\pdftmp\\";
$resp = saveFormToDisk("aaaa",array("aaaa" => $params["aaaa"]),$path . $filename);
$result["resp"] = $resp;
$result["pdfname"] = $filename;
$result["pdflink"] = "/pdftmp/" . $filename;

III. Client After:

ajax.removeMessage();
ajax.setMessage(result["resp"]);
var object = document.getElementById("pdfdisp");
object.setAttribute("data",result["pdflink"]);
var clone = object.cloneNode(true);
var parent = object.parentNode;
parent.removeChild(object);
parent.appendChild(clone);

3c. Text Object

<object class="pdf" width="100%" height="1000px" id="pdfdisp"></object>
  1. Fixed the bug in the code I mentioned in a previous post.
  2. I set my display preferences, security, etc. For my specific application, only people with a specific Group could see the main page and only admins can add/edit PDFs.

The result: When you get to the page.
img alt
When you filled it in. (Data replaced with test data.)
img alt