Create Action Button in PDO
$action = "../../pdf/generate_chartrequest.php?id={id}"; // Just Creates the PDF
$action = "../../pdf/generate_chartrequest.php?id={id}&action=sendfax"; // Creates the PDF and Sends the Fax
Folder Structure
public_html/pdf/faxes/ <-- Where the Fax API Documents are kept
public_html/pdf/library/SetaPDF/
public_html/pdf/templates/ <-- This is where the fillable template is
public_html/pdf/dbconnect.php <-- Connection to the database
public_html/pdf/generate_chartrequest.php <-- The API Script
dbconnect.php
//*** BE SURE TO INCLUDE THE PHP TAG AT BEGINNING AND THE END OF THE FILE ***
//*** In Credentials keep the quote marks ***
//DB Credentials
$db_host = 'localhost';
$db_name = 'db_name';
$db_login = 'username';
$db_pass = 'password';
// connect to db
$link = mysqli_connect($db_host, $db_login, $db_pass, $db_name) or
die("Could not connect : " . mysqli_error($link));
generate_chartrequest.php
//*** BE SURE TO INCLUDE THE PHP TAG AT BEGINNING OF THE FILE ***
///Connect to db and get data
include 'dbconnect.php';
//$query = "SELECT * FROM kto_records LIMIT 1";
$id = htmlspecialchars($_GET["id"]);
//echo 'ID is '. $id;
//$query = "SELECT * FROM kto_records WHERE id='603540'";
$query = "SELECT * FROM kto_records WHERE id='$id'";
//echo $query;
if ($result = $link->query($query)) {
//var_dump($result);
while ($row = $result->fetch_assoc()) {
//var_dump($result);
$owner_full = $row["owner_full"];
$pcp_fax = $row["pcp_fax"];
$pcp_name = $row["pcp_name"];
$pcp_name1 = $row["pcp_name"];
$pcp_name2 = $row["pcp_name"];
$id = $row["id"];
$id1 = $row["id"];
$pt_firstname = $row["pt_firstname"];
$pt_lastname = $row["pt_lastname"];
$fax_date = $row["fax_date"];
$insurance_mbi = $row["insurance_mbi"];
$pt_dob = $row["pt_dob"];
$pt_address = $row["pt_address"];
$dos = $row["dos"];
$pt_city = $row["pt_city"];
$pt_state = $row["pt_state"];
$pt_zip = $row["pt_zip"];
$comments = $row["comments"];
}
}
$pt_city_state_zip = $pt_city .', '. $pt_state .' '. $pt_zip;
$pt_name = $pt_firstname .' '. $pt_lastname;
//echo $pt_name;
// your variables
$template = 'templates/cn-1.pdf';
require_once('library/SetaPDF/Autoload.php');
// or if you use composer require_once('vendor/autoload.php');
// create the writer for the resulting file
//$date = date("Ymd");
$filled = '../script/uploads/chart_requests/'."$id".'_'."$fax_date".'.pdf';
//echo $filled;
//$writer = new SetaPDF_Core_Writer_File('formfiller-fill-same-named-fields.pdf');
$writer = new SetaPDF_Core_Writer_File($filled);
// create the document by filename
$document = SetaPDF_Core_Document::loadByFilename($template, $writer);
// create the form filler instance
$formFiller = new SetaPDF_FormFiller($document);
// get the fields from the form filler
$fields = $formFiller->getFields();
/* echo 'All field names: ';
print_r($fields->getNames());
echo "\n";
*/
// set the value for both fields
// changing one field value will change all fields with the same name
$fields['pcp_fax']->setValue($pcp_fax);
$fields['pcp_name']->setValue($pcp_name);
$fields['pcp_name#1']->setValue($pcp_name1);
//$fields['pcp_name#2']->setValue($pcp_name2);
$fields['id']->setValue($id);
$fields['id#1']->setValue($id1);
$fields['pt_name']->setValue($pt_name);
$fields['fax_date']->setValue($fax_date);
$fields['insurance_mbi']->setValue($insurance_mbi);
$fields['pt_dob']->setValue($pt_dob);
$fields['pt_address']->setValue($pt_address);
$fields['dos']->setValue($dos);
$fields['pt_city_state_zip']->setValue($pt_city_state_zip);
$fields['comments']->setValue($comments);
$fields['owner_full']->setValue($owner_full);
$fields['owner_full#1']->setValue($owner_full);
//echo 'Let\'s check the value of Text#4. It has to be "' . $text . '": ';
//echo $fields['Text#4']->getValue() . ' (' . ($fields['Text#4']->getValue() === $text ? 'ok' : 'no') . ")\n";
// save the document and finish
$document->save()->finish();
//echo $_GET['action'];
if($_GET['action'] == 'sendfax') {
include 'faxes/queue_fax.php';
} else {
//Display in browser
// Header content type
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filled . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
// Read the file
@readfile($filled);
}