How to generate new page in zend PDF in foreach loop - loops

please explain how can generate new pages in pdf for foreach loop content
$pdf = new Zend_Pdf();
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
$items = array();
foreach ($items as $item) {
$page->setFont($font, 9)
->setFillColor(Zend_Pdf_Color_Html::color('#000000'))
->drawText('Text 1', 0, 800);
}
$pdf->pages[] = $page;
$pdf->save('wishlist.pdf');

You have to use the below code to add new blank pages in your pdf file.
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
and than assign to
$pdf->pages[] = $page;

Related

How to extract all URL's from webpage in an array an see if certain value is there

I am trying to extract all the links from a webpage and put them into an array that I can then compare values with to see if there is a match. The problem that I'm having is I cannot seem to get the values into an array. I am able to see all the links and I see that there is a match with the one I'm trying to compare with but it's not recognizing that it's there. My code is as follows. Any help would be greatly appreciated.
$content = file_get_contents("sample_url");
$content = strip_tags($content, "<a>");
$subString = preg_split("/<\/a>/", $content);
$items = array();
foreach ( $subString as $val ){
if( strpos($val, "<a href=") !== FALSE ) {
$val = preg_replace("/.*<a\s+href=\"/sm", "", $val);
$val = preg_replace("/\".*/", "", $val);
$items[] = $val;
var_dump($val . "<br />");
}
}
if (in_array($testing_link, $items, true)) {
echo 'It is here!';
}
else {
echo 'it is NOT here :( ';
}
Better to use the DOMDocument to get the links into an array. Like this:
$doc = new DOMDocument();
// the string containing all the URLs and stuff
$doc->loadHTML($content);
//Extract the links from the HTML. From https://thisinterestsme.com/php-find-links-in-html/
$links = $doc->getElementsByTagName('a');
//Array that will contain our extracted links.
$extracted_links = array();
//Loop through the DOMNodeList.
//We can do this because the DOMNodeList object is traversable.
foreach ($links as $link) {
//Get the link text.
//$linkText = $link->nodeValue;
//Get the link in the href attribute.
$linkHref = $link->getAttribute('href');
}
Now all the HREFS are in the $linkHref array.
Better to use DOMDocument rather than RegEx. Much easier, and more accurate and consistent in results.

docusign checkbox value based on API call not working

I am trying to pass selected checkbox values from a real estate contract via the REST API. Currently I am able to make the check boxes show up on the document but they do not show checked or uncheck based on the True/False data passed. What am I doing wrong? I've tried setting them as read only and mandatory on the template and they still don't populate the checks in the boxes.
*updated with correct code below
$sellerTabs = new \DocuSign\eSign\Model\Tabs();
$count_fields = 0;
foreach ($fields_data as $key => $field_value) {
//echo $field_value."\n";
$seller_address[$count_fields] = new
\DocuSign\eSign\Model\Text(["tab_label" => $key,
"value" => $field_value]);
$count_fields++;
}
$tab_group = $_REQUEST["group"];
$sellerTabs = new \DocuSign\eSign\Model\Tabs();
$count_checks = 0;
foreach ($checks_data as $key => $check_value) {
//echo $check_value."\n";
$seller_checks[$count_checks]= new
DocuSign\eSign\Model\Checkbox(["tab_label" => $key,
"selected" =>
$check_value,"Checkbox_Group"=>$tab_group]);
$count_checks++;
}
//file_put_contents("create_event.log",
"json_decode($checks, true);" ,FILE_APPEND;
"json_decode($fields, true);", FILE_APPEND);
//exit();
$sellerTabs->setTextTabs($seller_address);
$sellerTabs->setCheckboxTabs($seller_checks);
$envelop_definition = new
DocuSign\eSign\Model\EnvelopeDefinition();
$b_roles = array();
//exit();
// echo $roles_data;
foreach ($roles_data as $role_data) {
// echo $role_data;
$data = explode("|", $role_data);
$role_data = new DocuSign\eSign\Model\TemplateRole();
$role_data->setName($data[0]);
$role_data->setEmail($data[1]);
$role_data->setRoleName($data[2]);
$role_data->setRoutingOrder($data[3]);
$role_data->setTabs($sellerTabs);
//echo $role_data;
array_push($b_roles, $role_data);
}
//var_dump($b_roles);
/*echo "<pre>";
print_r($_REQUEST["templateID"]);
exit();*/
// $envelop_definition-
>setTemplateRoles(array($sellerRole /,
$templateRole3/));

How to pass all arrays into formArray maatwebsite-laravel-excel

im getting all the array what i need. but when i don't know how to pass all the arrayes
$data = array('JOB NO','INVOICE NO','CUSTOMER','VAT(OUT PUT)','ACTUAL VAT');
foreach($jobs as $row){
$client =$row->company->name;
if($row->company->name != "PSL"){
$client = $row->job->customer_name;
}
$data1[]=array($row->job_no,$row->invoice_no,$client,number_format(($row->amount)*15/115,2,'.',','));
}
// dd($data1);
$data3 = array($data,$data1[0]);
$sheet->fromArray($data3,null,'A5',false,false);
when i check here like this $data3 = array($data,$data1[0]); im getting one row in my Excel i don't know how to pass all the array ?
Here's what you can do.
// Array that will be used to generate the sheet
$sheetArray = array();
// Add the headers
$sheetArray[] = array('JOB NO','INVOICE NO','CUSTOMER','VAT(OUT PUT)','ACTUAL VAT');
// Add space between headers and results if needed
$sheetArray[] = array(); // Add an empty row
$sheetArray[] = array(); // Add an empty row
// Add the results
foreach($jobs as $row){
$client = $row->company->name;
if($row->company->name != "PSL"){
$client = $row->job->customer_name;
}
$sheetArray[] = array($row->job_no,$row->invoice_no,$client,number_format(($row->amount)*15/115,2,'.',','));
}
// Generating the sheet from the array
$sheet->fromArray($sheetArray);

cakephp - Save file syncronized and send as attachment

Hi have a strange problem with File::write() in cakephp.
I write this code to generate a pdf view and save it on a file.
private function generate( $id ){
$order = $this->Order->read( null, $id );
$this->set('order', $order);
$view = new View($this);
$viewdata = $view->render('pdf');
//set the file name to save the View's output
$path = WWW_ROOT . 'ordini/' . $id . '.pdf';
$file = new File($path, true);
//write the content to the file
$file->write( $viewdata );
//return the path
return $path;
}
I need generate this pdf and send it as attacchment so, this is my code
public function publish ($id) {
$pdf_file = $this->generate( (int)$id );
$Email = new CakeEmail();
$Email->from(array('info#.....com' => '......'));
$Email->to('....#gmail.com');
$Email->subject('Nuovo ordine');
$filepath = WWW_ROOT . 'ordini/' . $id . '.pdf';
$Email->attachments(array('Ordine.pdf' => $filepath));
$Email->send('......');
}
The first time i run this code the email doesn't works, the email works nice only if the pdf is alredy in the folder.
I think that File::write perform some kind of async writing and when system execute Email::attachments the file ins't ready.
How can i insert a while() in this code to check file avability?
thanks a lot.
if($file->write( $viewdata ))
{
return $path;
}
using the return value wasn't enough.
I changed this line
$file = new File($path, false);
Opening file without forcing worked for me.

Drupal 7 db_query

The perfect little module for what I am looking to do was made for drupal 6 but to my dismay it doesn't work on drupal 7. I've have learned that drupal 7 has a new api for the database. I have tried to get it to work but I am admittedly out of my league here. I am hoping some one could give me a little guidance. Specifically with the db_query.
function webform_image_validation_webform_validation_validate($validator_name, $items,
$components, $rule) {
$errors = array();
if ($items) {
switch ($validator_name) {
case 'max_image_size':
$dimensions = explode('x', $rule['data']);
foreach ($items as $key => $val) {
if (is_numeric($val['_fid'])) {
$result = db_query("select * from {files} where fid = %d", $val['_fid']);
while ($data = db_fetch_object($result)) {
$thefile = $data;
}
$image_info = image_get_info($thefile->filepath);
if (webform_image_validation_validate_image($image_info, $dimensions[0], $dimensions[1], FALSE) === FALSE) {
$errors[$key] = t('Your image did not match the required width and/or height. (') . $dimensions[0] . t(' x ') . $dimensions[1] . t(')');
}
}
}
This is the error I receive.
Argument 2 passed to db_query() must be an array, string given, called in
/home/designco/public_html/dev/sites/all/modules/webform_image_validation/
webform_image_validation.module on line 69 and defined in
/home/designco/public_html/dev/includes/database/database.inc on line 2310
It appears I need to add an array but I get lost there. Any help would be appreciated. I'm just trying to find out if I'm the right track.
db_query works differently in Drupal7.
$result = db_query("select * from {files} where fid = %d", $val['_fid']);
while ($data = db_fetch_object($result)) {
$thefile = $data;
}
becomes
$results = db_query("select * from {files} where fid = :fid", array(':fid' => $val['_fid']));
foreach($results as $result) {
// Do your thing for each result.
}
Try changing
$result = db_query("select * from {files} where fid = %d", $val['_fid']);
while ($data = db_fetch_object($result)) {
$thefile = $data;
}
to
$query = db_select('files', 'f')
->fields('f')
->condition('fid', $val['_fid']);
$thefile = $query->execute()->fetchObject();
The Drupal 7 database API docs http://drupal.org/node/310069
thanks JurgenR for the answer.
Just to add one more thing: In drupal 6, we use '%s' for strings. In drupal 7, it is same for all.
For example:
$results = db_query("select * from {files}
where filename = :fname", array(':fname' => $filename));
If you want to search for records starting with a pattern then query will be:
$results = db_query("select * from {files}
where filename = :fname", array(':fname' => $filename.'%'));
Hope this is useful.

Resources