public function ajaxpdfAction() { $this->_helper->layout()->disableLayout(); // $this->_helper->viewRenderer->setNoRender(true); $pdf = new Zend_Pdf(); $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $font = Zend_Pdf_Font::fontWithPath('font/simkai.ttf',(Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION | Zend_Pdf_Font::EMBED_DONT_COMPRESS)); //put the personal information to the pdf $contacts = new Employee_Models_ContactMapper(); $arrayContacts = $contacts->fetchAllJoin(); $count = 1;//every page show approximately 20 pieces; //$arrayCount = count($arrayContacts); $totalItems = $arrayContacts->getTotalItemCount(); $arrayContacts->setItemCountPerPage($totalItems); $pageNumber = ceil($totalItems / 25); $x = 0; $y = 750; $currentpage = 1; foreach($arrayContacts as $contact) { if($count == 1) { $page->setLineWidth(0.5); $page->drawLine(50, 770, 560, 770); $page->drawLine(50, 125, 560, 125); $page->setFont($font,13) ->drawText("编号", 50, $y, 'UTF-8') ->drawText("姓名", 100, $y, 'UTF-8') ->drawText("性别", 145, $y, 'UTF-8') ->drawText("生日", 195, $y, 'UTF-8') ->drawText("部门", 275, $y, 'UTF-8') ->drawText("职务", 335, $y, 'UTF-8') ->drawText("入职时间", 415, $y, 'UTF-8') ->drawText("手机号码", 495, $y, 'UTF-8'); $time = Date("Y-m-d,H:i"); $users = new System_Models_UserMapper(); $contactId = $users->getContactId($this->getUserId()); $contacts = new Employee_Models_ContactMapper(); $contactName = $contacts->findContactName($contactId); $page->setFont($font,11) ->drawText("公司员工信息总览", 250, 790, 'UTF-8') ->drawText("导出人:".$contactName, 50, 100, 'UTF-8') ->drawText("导出日期:".$time, 250, 100, 'UTF-8') ->drawText("页数:".$currentpage."(".$pageNumber.")", 500, 100, 'UTF-8'); } $y -= 25;$count++; $page->setFont($font, 11) ->drawText($contact->contactId, $x+=50, $y, 'UTF-8') ->drawText($contact->contactName, $x+=50, $y, 'UTF-8') ->drawText($contact->gender, $x+=45, $y, 'UTF-8') ->drawText($contact->birth, $x+=50, $y, 'UTF-8') ->drawText($contact->deptName, $x+=80, $y, 'UTF-8') ->drawText($contact->dutyName, $x+=60, $y, 'UTF-8') ->drawText($contact->enroll, $x+=80, $y, 'UTF-8') ->drawText($contact->phoneMob, $x+=80, $y, 'UTF-8'); if($count >= 25) { $pdf->pages[] = $page; $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $count = 1; $y = 750; $currentpage++; } $x = 0; } $pdf->pages[] = $page; $name_string = "公司员工信息总览".time().".pdf"; //server $base = General_Models_ServerInfo::$localUrl; $url = 'tmp/'.$name_string; $pdf->save($url); $murl = $base.'/'.$url; $this->view->murl = $murl; }
protected function pageEmployeeIndex($pdf,$page,$font) { //put the personal information to the pdf $contacts = new Employee_Models_ContactMapper(); $arrayContacts = $contacts->fetchAllJoin(); $count = 1;//every page show approximately 20 pieces; //$arrayCount = count($arrayContacts); $totalItems = $arrayContacts->getTotalItemCount(); $arrayContacts->setItemCountPerPage($totalItems); $pageNumber = ceil($totalItems / 25); $x = 0; $y = 750; $currentpage = 1; foreach($arrayContacts as $contact) { if($count == 1) { $page->setLineWidth(0.5); $page->drawLine(50, 770, 560, 770); $page->drawLine(50, 125, 560, 125); $page->setFont($font,13) ->drawText("编号", 50, $y, 'UTF-8') ->drawText("姓名", 100, $y, 'UTF-8') ->drawText("性别", 145, $y, 'UTF-8') ->drawText("生日", 195, $y, 'UTF-8') ->drawText("部门", 275, $y, 'UTF-8') ->drawText("职务", 335, $y, 'UTF-8') ->drawText("入职时间", 415, $y, 'UTF-8') ->drawText("手机号码", 495, $y, 'UTF-8'); $time = Date("Y-m-d,H:i"); $users = new System_Models_UserMapper(); $contactId = $users->getContactId($this->getUserId()); $contacts = new Employee_Models_ContactMapper(); $contactName = $contacts->findContactName($contactId); $page->setFont($font,11) ->drawText("公司员工信息总览", 250, 790, 'UTF-8') ->drawText("导出人:".$contactName, 50, 100, 'UTF-8') ->drawText("导出日期:".$time, 250, 100, 'UTF-8') ->drawText("页数:".$currentpage."(".$pageNumber.")", 500, 100, 'UTF-8'); } $y -= 25;$count++; $page->setFont($font, 11) ->drawText($contact->contactId, $x+=50, $y, 'UTF-8') ->drawText($contact->contactName, $x+=50, $y, 'UTF-8') ->drawText($contact->gender, $x+=45, $y, 'UTF-8') ->drawText($contact->birth, $x+=50, $y, 'UTF-8') ->drawText($contact->deptName, $x+=80, $y, 'UTF-8') ->drawText($contact->dutyName, $x+=60, $y, 'UTF-8') ->drawText($contact->enroll, $x+=80, $y, 'UTF-8') ->drawText($contact->phoneMob, $x+=80, $y, 'UTF-8'); if($count >= 25) { $pdf->pages[] = $page; $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $count = 1; $y = 750; $currentpage++; } $x = 0; } $pdf->pages[] = $page; $name_string = "公司员工信息总览".time().".pdf"; $name_stringEn = urlencode("公司员工信息总览".time()).".pdf"; $url = 'tmp/'.$name_string; $urlEn='tmp/'.$name_stringEn; $pdf->save($url); return $urlEn; }