<text fontsize="12" fontlaguage="cn" align="center">建表日期:20020611</text> </foot> </pdfreport> 用XMLParser对该XML文档解析后,得到一个包含所有信息的对象树,我们可以非常方便的访问其中的内容。生成的PDF报表如下图:
程序片断如下:
<? include( "../include/pc_init.inc" );?> <? include( "xmlparser.inc" ); <? $xmlobject=getRootNode("report.xml"); // get the attrs of root element $pageSet=$xmlobject->attrs; // get the report-head $head=$xmlobject->nodes[0]; // code ignored... ?> <?
function draw_line(&$parent,$line){ $line = &pc_create_object( $parent, "line" ); $line->pc_set_linestyle( $line->attrs["LINETYPE"]); $line->pc_set_width( $line->attrs["SIZE"] ); $line->pc_set_alignment( "center" ); if($line->attrs["SHOW"]==false){ $line->pc_set_linecolor( "white" ); } $line->pc_set_margin( array( "top" => $line->attrs["TOP"], "bottom" => $line->attrs["BOTTOM"], "left" => 0, "right" => 0 ) ); }
function draw_text(&$parent,$text){ // code ignored... } function draw_table(&$parent,$table){ // code ignored... }
function addhead(&$parent,$head){ for($i=0;$i< $head->n;$i++){ switch ($head->nodes[$i]->name){ case "LINE":draw_line($parent,$head->nodes[$i]);break; case "TEXT":draw_text($parent,$head->nodes[$i]);break; } } } //.. ?> <? // Create a PDF Document $PDF = &pc_create_pdf( array( "Author" => "cyman", "Title" => "a report example" ) ); // Create an A4-format page $Page1 = &pc_create_page( $PDF, $pageSet["PAGETYPE"]); addhead($Page1,$head); $PDF->pc_draw(); ?> |