Skip to content

Instantly share code, notes, and snippets.

@jonathanmaron
Last active October 23, 2018 10:31
Show Gist options
  • Save jonathanmaron/07e9ce9103c5dc34275de40ee6443c85 to your computer and use it in GitHub Desktop.
Save jonathanmaron/07e9ce9103c5dc34275de40ee6443c85 to your computer and use it in GitHub Desktop.
<?php
use TxTextControl\ReportingCloud\ReportingCloud;
$reportingCloud = new ReportingCloud([
'api_key' => Helper::apiKey(),
]);
$mergeData = [
0 => [
'yourcompany_companyname' => 'Text Control, LLC',
'yourcompany_zip' => '28226',
'yourcompany_city' => 'Charlotte',
'yourcompany_street' => '6926 Shannon Willow Rd, Suite 400',
'yourcompany_phone' => '704 544 7445',
'yourcompany_fax' => '704-542-0936',
'yourcompany_url' => 'www.textcontrol.com',
'yourcompany_email' => 'sales@textcontrol.com',
'invoice_no' => '778723',
'billto_name' => 'Joey Montana',
'billto_companyname' => 'Montana, LLC',
'billto_customerid' => '123',
'billto_zip' => '27878',
'billto_city' => 'Charlotte',
'billto_street' => '1 Washington Dr',
'billto_phone' => '887 267 3356',
'payment_due' => '20/1/2016',
'payment_terms' => 'NET 30',
'salesperson_name' => 'Mark Frontier',
'delivery_date' => '20/1/2016',
'delivery_method' => 'Ground',
'delivery_method_terms' => 'NET 30',
'recipient_name' => 'Joey Montana',
'recipient_companyname' => 'Montana, LLC',
'recipient_zip' => '27878',
'recipient_city' => 'Charlotte',
'recipient_street' => '1 Washington Dr',
'recipient_phone' => '887 267 3356',
'item' => [
0 => [
'qty' => '1',
'item_no' => '1',
'item_description' => 'Item description 1',
'item_unitprice' => '2663',
'item_discount' => '20',
'item_total' => '2130.40',
],
1 => [
'qty' => '1',
'item_no' => '2',
'item_description' => 'Item description 2',
'item_unitprice' => '5543',
'item_discount' => '0',
'item_total' => '5543',
],
],
'total_discount' => '532.60',
'total_sub' => '7673.4',
'total_tax' => '537.138',
'total' => '8210.538',
],
];
// copy data 4 times
// total record sets = 5
for ($i = 0; $i < 5; $i++) {
array_push($mergeData, $mergeData[0]);
}
$mergeSettings = [
'creation_date' => time(),
'last_modification_date' => time(),
'remove_empty_blocks' => true,
'remove_empty_fields' => true,
'remove_empty_images' => true,
'remove_trailing_whitespace' => true,
'author' => 'James Henry Trotter',
'creator_application' => 'The Giant Peach',
'document_subject' => 'The Old Green Grasshopper',
'document_title' => 'James and the Giant Peach',
'user_password' => '123456789',
];
$templateName = 'test_template.tx';
$arrayOfBinaryData = $reportingCloud->mergeDocument($mergeData, 'PDF', $templateName, null, false, $mergeSettings);
foreach ($arrayOfBinaryData as $index => $binaryData) {
$destinationFile = sprintf('test_document_%d.pdf', $index);
$destinationFilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destinationFile;
file_put_contents($destinationFilename, $binaryData);
var_dump("Merged {$templateName} was written to {$destinationFilename}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment