文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Zend Framework之PDF实例

Zend Framework之PDF实例

时间:2008-01-07  来源:panzt

众所周之,Zend Framework集成了许多优秀且实用的功能,今天看看它的操作PDF的强大能力。
PDF是一种公认的文档格式,如果能将它应用到公文、OA等系统中去的话,数字签名也就不需要那么麻烦了
OK,闲话少叙,让我们看看在Zend Framework中它的神奇表现吧:

1、建立PDF文件(空的,只是形式没有页面)
save("chomp.pdf");
?>
是不是很简单?

2、建立空的PDF文件(已经有页面,只是页面没有元素)
$pageHeight = $page->getHeight();
$pageWidth = $page->getWidth();
echo 'Height = '.$pageHeight.'\n';
echo 'Width = '.$pageWidth.'\n';
$pdf->pages[0] = ($page);
$pdf->save("chomp.pdf");
?>

3、插入图片至页面中(Image objects should be created with Zend_Pdf_Image::imageWithPath($filePath) method (JPG, PNG and TIFF images are supported now))
   $pdf = new Zend_Pdf();
   $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER);
   /*$pageHeight = $page->getHeight();
   $pageWidth = $page->getWidth();
   echo 'Height = '.$pageHeight;
   echo '
';
   echo 'Width = '.$pageWidth;*/
   
   //echo dirname(__FILE__);

   $chompImage = Zend_Pdf_Image::imageWithPath('public/images/blume.jpg');
   
   $pageHeight = $page->getHeight();
   $pageWidth = $page->getWidth();
   $imageHeight = 72;
   $imageWidth = 72;
   
   $topPos = $pageHeight - 36;
   $leftPos = 36;
   $bottomPos = $topPos - $imageHeight;
   $rightPos = $leftPos + $imageWidth;
   
   //$page->drawImage($chompImage, $leftPos, $bottomPos, $rightPos, $topPos);
   $page->drawImage($chompImage, 100, 100, 400, 300);
   $pdf->pages[0] = ($page);
   $pdf->save("public/pdf/chomp.pdf");
   error_message("Succeed In Creating PDF!");
注:需php的GD支持

4:加入文字:
   $page->drawImage($chompImage, 100, 100, 400, 300);
   
   
   $style = new Zend_Pdf_Style();
   $style->setLineColor(new Zend_Pdf_Color_RGB(0.9, 0, 0));
   $style->setFillColor(new Zend_Pdf_Color_GrayScale(0.2));
   $style->setLineWidth(3);
   $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 32);
   $string="That's OK!";
   $page->setStyle($style);
   
   $page->drawText($string, $rightPos + 32, $topPos - 48);
   
   $pdf->pages[0] = ($page);
   $pdf->save("public/pdf/chomp.pdf");
   error_message("Succeed In Creating PDF!");
5、创建图片
$string="That's OK!";
   
   $style = new Zend_Pdf_Style();
   $style->setLineColor(new Zend_Pdf_Color_RGB(0.9, 0, 0));
   $style->setFillColor(new Zend_Pdf_Color_GrayScale(0.2));
   $style->setLineWidth(3);
   $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 32);
   
   $page->setStyle($style);
   $page->drawText($string, $rightPos + 32, $topPos - 48);
   $page->drawRectangle(18, $pageHeight - 18, $pageWidth - 18,
                           18, Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE);
   
   $pdf->pages[0] = ($page);
   $pdf->save("public/pdf/chomp.pdf");
   error_message("Succeed In Creating PDF!");
如果多行和多个图形及多个图象,只需要将其间隔排版好,在drawText,drawImage,drawRectangle多次就OK了.



相关阅读 更多 +
排行榜 更多 +
祖玛泡泡龙(经典祖玛)下载

祖玛泡泡龙(经典祖玛)下载

休闲益智 下载
网络掠夺者最新版下载

网络掠夺者最新版下载

休闲益智 下载
迷你冲撞小游戏中文版下载

迷你冲撞小游戏中文版下载

休闲益智 下载