菜单

PHP7.27: pdf

2018年11月16日 - Php

http://www.fpdf.org/

 http://www.devshed.com/c/a/PHP/PHP-Services-Layers-Data-Mappers/

https://github.com/Setasign/FPDF

https://stackoverflow.com/questions/1980015/model-mapper-relationship

https://www.ntaso.com/fpdf-and-chinese-characters/

http://assets.en.oreilly.com/1/event/36/PHP%20Object-Relational%20Mapping%20Libraries%20In%20Action%20Presentation.pdf

<?php
 // 1.8.1
//define("FPDF_FONTPATH","font/");

try
{
require("../fpdf.php"); 
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial","B",16);
$pdf->Cell(40,10,"Hello World! 涂聚文"); //中文乱码
$pdf->Output();
}
catch(Exception $ex)
{
 echo($ex->getMessage());
}

?>

https://github.com/marcelgsantos/learning-oop-in-php

  

https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/DataMapper

https://www.phpbook.jp/fpdf/japan/index2.html

Handling Collections of Aggregate Roots – the Repository Pattern

缓解中文题目:

Building a Domain Model – Integrating Data Mappers

http://www.fpdf.org/en/script/script92.php 

https://github.com/TwisterMW/php-dal-model

把中文后缀为.tff字体文件放入到:tfpdf\font\unifont
的文夹下即可。参考 http://www.fpdf.org/en/script/script92.php 

http://www.phpdao.com/

下载: http://www.fpdf.org/en/script/dl.php?id=92&f=zip

 

https://dejavu-fonts.github.io/Download.html

 

<?php

// Optionally define the filesystem path to your system fonts
// otherwise tFPDF will use [path to tFPDF]/font/unifont/ directory
// define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/");  tFPDF
//http://www.fpdf.org/en/script/script92.php

require('tfpdf/tfpdf.php');

$pdf = new tFPDF();
$pdf->AddPage();

// Add a Unicode font (uses UTF-8)
//tfpdf\font\unifont 把中文的字体文件放入其内则可。
$pdf->AddFont('DejaVu','','3pdwg6wqe1jpcgh.ttf',true);   //msyh.ttf  设置字体即可,字体名称不可以定义为中文 简体篆体 :3pdwg6wqe1jpcgh.ttf
$pdf->SetFont('DejaVu','',14);

// Load a UTF-8 string from a file and print it
// 在操作系统下可以选择的字体可以显示,则也可以生成
$txt ="English: Hello World
Greek: Γειά σου κόσμος
Polish: Witaj świecie
Portuguese: Olá mundo
Russian: Здравствулте мир
Vietnamese: Xin chào thế giới,中国智造0123456789 涂聚文geovindu 生命的意义,涂聚文,中华人民共和国";// file_get_contents('HelloWorld.txt');
$pdf->Write(8,$txt);

// Select a standard font (uses windows-1252)
$pdf->SetFont('Arial','',14);
$pdf->Ln(10);
$pdf->Write(5,'The file size of this PDF is only 13 KB.');

$pdf->Output();
?>
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">  
<meta charset="utf-8">
<title>object 对象</title>
<meta name="keywords" content="geovindu">
<meta name="description" content="涂聚文">  
</head>

<body>

<?php

// object
class User
{
 public $username,$password;

 function getName()
 {
  return $this->username;
 }

 function getPassword()
 {
  return $this->password;

 }



 function Save()
 {
  echo("保存成功!");
 }

}
// UserDesc 继承 User类
class UserDesc extends User
{
 public $realname,$email,$birthday;

 function getRealname()
 {
  return $this->realname;

 }

 function getEmail()
 {
  return $this->email;
 }

 function getBirthday()
 {
  return $this->birthday; 
 }

}

function getMillisecond()
{ 
 list($s1,$s2) = explode(' ', microtime());
 return (float)sprintf('%.0f', (floatval($s1)+floatval($s2)) * 1000); 
}

$object=new User;
print_r($object);echo("<br/>");

$object->username="geovindu"; //
$object->password="888888";// 赋值
print_r($object);echo("<br/>");
$object->Save() ;//显示文字
echo("姓名:".$object->getName()); //显示对象的name值
echo("密码:".$object->getPassword());
$object2=new UserDesc;
$object2->birthday=date('Y-m-d H:i:s');
$object2->email='geovindu@163.com';
$object2->realname='涂聚文';
$object2->username='geovindu';
$object2->password='8888';

print_r($object2);echo("<br/>");

//
class Collection implements ArrayAccess,IteratorAggregate
{
    public $objectArray = Array();
    //**these are the required iterator functions    
    function offsetExists($offset)
    {          
        if(isset($this->objectArray[$offset]))  return TRUE;
        else return FALSE;          
    }    

    function & offsetGet($offset)
    {   
        if ($this->offsetExists($offset))  return $this->objectArray[$offset];
        else return (false);
    }

    function offsetSet($offset, $value)
    {          
        if ($offset)  $this->objectArray[$offset] = $value;
        else  $this->objectArray[] = $value;
    }

    function offsetUnset($offset)
    {
        unset ($this->objectArray[$offset]);
    }

    function & getIterator()
    {
        return new ArrayIterator($this->objectArray);
    }
    //**end required iterator functions

    public function doSomething()
    {
        echo "I'm doing something";
    }
}

// 
class CustomContact
{
    protected $name = NULL;
 protected $tel=null;

    public function set_name($name)
    {
        $this->name = $name;
    }

    public function get_name()
    {
        return ($this->name);
    }

 public function settel($tel)
 {
  $this->tel=$tel;
 }

 public function gettel()
 {
  return ($this->tel);
 }
} 

//
$bob = new Collection();
$bob->doSomething();
$du[]=new CustomContact();
$du[5]=new CustomContact();
$du[0]->set_name("geovindu");
$du[0]->settel("13824350518");
$du[5]->set_name("sibodu");
$du[5]->settel("075582397507");
echo("<br/>");
$num=1;
foreach ($du as $aContact)
{

  echo("序号:".$num."<br/>");
     echo("姓名:".$aContact->get_name() . "\r\n<br/>");
  echo("电话:".$aContact->gettel() . "\r\n<br/>");
 $num=$num+1;
}

$arry =new ArrayObject($du);
print_r($arry);
// 显示
foreach($arry as $obj) 
{
     echo "姓名:" . $obj->get_name();
     echo "电话:". $obj->gettel();
}


?>

</body>
</html>

  图片 1

  

 

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">  
<meta charset="utf-8">
<title>接口Creating a Data Abstraction Layer in PHP</title>
<meta name="keywords" content="geovindu">
<meta name="description" content="涂聚文"> 
<meta name="author" content="涂聚文">  
</head>

<body>
<?php
//https://github.com/ADOdb/ADOdb
//https://github.com/AdamB7586/pdo-dbal
//https://github.com/daijulong/generator


interface Maxmin{
 public function getMax();

 public function getMin();

}

class msm implements Maxmin{
 private $aa=33;
 private $bb=66;
 //具体实现接口声明的方法
 public function getMax()
 {
  return $this->bb;
 }

 public function getMin()
 {
  return $this->aa;
 }

 public function getOther(){
  return 'geovindu:hi,how are you.';
 }
} 

$msm=new msm();
echo($msm->getMax());
echo("<br/>");
echo($msm->getMin());
echo("<br/>");
echo($msm->getOther());

?>
</body>
</html>
<?php

// Optionally define the filesystem path to your system fonts
// otherwise tFPDF will use [path to tFPDF]/font/unifont/ directory
// define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/");  tFPDF
//http://www.fpdf.org/en/script/script92.php

require('tfpdf/tfpdf.php');

$pdf = new tFPDF();
$pdf->AddPage();

// Add a Unicode font (uses UTF-8)
//tfpdf\font\unifont 把中文的字体文件放入其内则可。
$pdf->AddFont('DejaVu','','3pdwg6wqe1jpcgh.ttf',true);   //msyh.ttf  设置字体即可,字体名称不可以定义为中文 简体篆体 :3pdwg6wqe1jpcgh.ttf
$pdf->SetFont('DejaVu','',14);

// Load a UTF-8 string from a file and print it
// 在操作系统下可以选择的字体可以显示,则也可以生成
$txt ="English: Hello World
Greek: Γειά σου κόσμος
Polish: Witaj świecie
Portuguese: Olá mundo
Russian: Здравствулте мир
Vietnamese: Xin chào thế giới,中国智造0123456789 涂聚文geovindu 生命的意义,涂聚文,中华人民共和国";// file_get_contents('HelloWorld.txt');
$pdf->Write(8,$txt);
$pdf->Ln(16);
$sheader=array("姓名","年龄","性别","工资","学历");
$data=array();
$data[0]=array("geovindu","1","男","100","");
$data[1]=array("sibodu","2","男","200","");
$data[2]=array("涂聚文","3","女","300","");
$data[3]=array("小涂","4","女","400","");
$data[4]=array("阿文","5","男","500","");
$data[5]=array("小文","6","女","600","");
$width=array(40,40,40,40); //设置每列宽度
for($i=0;$i<count($sheader);$i++)
{
 $pdf->Cell($width[$i],6,$sheader[$i],1);
}
$pdf->Ln(6);
foreach($data as $row)
{
 $pdf->Cell($width[0],6,$row[0],1);
 $pdf->Cell($width[1],6,$row[1],1);
 $pdf->Cell($width[2],6,$row[2],1);
 $pdf->Cell($width[3],6,$row[3],1);
 $pdf->Cell($width[4],6,$row[4],1);
 $pdf->Cell($width[5],6,$row[5],1);
 $pdf->Ln(6);
}
// Select a standard font (uses windows-1252) 
$pdf->SetFont('Arial','',14);
$pdf->Ln(10);
$pdf->Write(5,'The file size of this PDF is only 13 KB.');

$pdf->Output();
?>

  

  

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">  
<meta charset="utf-8">
<title>多态性</title>
<meta name="keywords" content="geovindu">
<meta name="description" content="涂聚文"> 
<meta name="author" content="涂聚文">  
</head>

<body>
<?php
//定义蔬菜抽象类
abstract class Vegetables{
 //抽象方法
 abstract function go_Vegetables();
} 

//马铃薯继承蔬菜类
class Vegetables_potato extends Vegetables{
 //重写抽象方法
 public function go_Vegetables(){
  echo("我是马铃薯");
 }
}
//萝卜继承蔬菜类
class Vegetables_radish extends Vegetables{
 public function go_Vegetables()
 {
  echo("我是萝卜");
 }
} 
//自定义方法根据对象调用不同的方法
function change($obj)
{

 if($obj instanceof Vegetables)
 {
  $obj->go_Vegetables();
 }
 else
 {
  echo("输入的参数不是一个对象");
 }
}

try
{ 
echo("实例化Vegetables_potato:");
change(new Vegetables_potato());
echo("<br/>");
echo("<br/>");
echo("实例化Vegetables_radish:"); 
change(new Vegetables_radish());
}
catch(Exception $ex)
{
 echo("异常信息:".$ex->getMessage());
} 
?>
</body>
</html>
<?php

// Optionally define the filesystem path to your system fonts
// otherwise tFPDF will use [path to tFPDF]/font/unifont/ directory
// define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/");

require('tfpdf\tfpdf.php');

$pdf = new tFPDF();
$pdf->AddPage();

// Add a Unicode font (uses UTF-8)
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu','',14);

// Load a UTF-8 string from a file and print it
$txt = file_get_contents('./tfpdf/HelloWorld.txt', FALSE, NULL, 20, 1400); //
$pdf->Write(8,$txt);

// Select a standard font (uses windows-1252)
$pdf->SetFont('Arial','',14);
$pdf->Ln(10);
$pdf->Write(5,'The file size of this PDF is only 13 KB.');

$pdf->Output();
?>

  

  

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">  
<meta charset="utf-8">
<title>通过接口实现多态</title>
<meta name="keywords" content="geovindu">
<meta name="description" content="涂聚文"> 
<meta name="author" content="涂聚文">  
</head>

<body>
<?php
//定义接口
interface Vegetables{
 //定义接口方法
 public function go_Vegetables();
} 

//马铃薯继承蔬菜类
class Vegetables_potato implements Vegetables{
 //重写抽象方法
 public function go_Vegetables(){
  echo("我是马铃薯");
 }
}
//萝卜继承蔬菜类
class Vegetables_radish implements Vegetables{
 public function go_Vegetables()
 {
  echo("我是萝卜");
 }
} 
//自定义方法根据对象调用不同的方法
function change($obj)
{

 if($obj instanceof Vegetables)
 {
  $obj->go_Vegetables();
 }
 else
 {
  echo("输入的参数不是一个对象");
 }
}

try
{
echo("实例化Vegetables_potato:");
change(new Vegetables_potato());
echo("<br/>");
echo("<br/>");
echo("实例化Vegetables_radish:"); 
change(new Vegetables_radish());
}
catch(Exception $ex)
{
 echo("异常信息:".$ex->getMessage());
}
?> 
</body>
</html>

  

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图