File: /home/awaldron/_accomods/apidev.accomods.com/v1/pdf.php
<?php
//**********************************************************************************************************//
// Method: POST
// Endpoint: pdf/generate
// Params:
function post_v1_pdf_generate( $args, $body, $uid, $is_admin, $db ) {
$needs = $body['data']['builder']['needs'];
$strengths = $body['data']['builder']['strengths'];
$accomods = $body['data']['cart']['items'];
$html = pdf_template($strengths, $needs, $accomods);
$apiClient = new \Api2Pdf\Api2Pdf('056f01e1-684c-416d-ae8c-d75c26545eb0');
$apiClient->setInline(true);
$result = $apiClient->headlessChromeFromHtml($html);
$pdfLink = $result->getPdf();
response(200, ['success'=>true, 'url'=>$pdfLink]); // $pdfLink
}
//**********************************************************************************************************//
// Method: POST
// Endpoint: pdf/generate
// Params:
function post_v1_pdf_email( $args, $body, $uid, $is_admin, $db ) {
$needs = $body['data']['builder']['needs'];
$strengths = $body['data']['builder']['strengths'];
$accomods = $body['data']['cart']['items'];
$html = pdf_template($strengths, $needs, $accomods);
$apiClient = new \Api2Pdf\Api2Pdf('056f01e1-684c-416d-ae8c-d75c26545eb0');
$apiClient->setInline(true);
$result = $apiClient->headlessChromeFromHtml($html);
$pdfLink = $result->getPdf();
// SAVE THE FILE TO THE SERVER
// $pdf_filename = ROOT_DIR."/files/accomods-".time().".pdf";
$pdf_filename = "files/accomods-".time().".pdf";
file_put_contents($pdf_filename, fopen($pdfLink, 'r'));
// EMAIL THE FILE
if (pdf_email( $body, $pdf_filename )) {
response(200, ['success'=>true] );
} else {
response(200, ['success'=>false, 'error' => 'An error occurred sending your email.'] );
}
}
//**********************************************************************************************************//
// Method: POST
// Endpoint: pdf/monitorform
// Params:
function post_v1_pdf_monitorform( $args, $body, $uid, $is_admin, $db ) {
$html = monitoring_form_template($body);
$apiClient = new \Api2Pdf\Api2Pdf('056f01e1-684c-416d-ae8c-d75c26545eb0');
$apiClient->setOptions([
'landscape' => true
]);
$apiClient->setInline(true);
$result = $apiClient->headlessChromeFromHtml($html);
$pdfLink = $result->getPdf();
response(200, ['success'=>true, 'url'=>$pdfLink]); // $pdfLink
}