westdc-zf1/application/models/MetadataPDF.php

205 lines
6.7 KiB
PHP

<?php
//生成西部数据中心离线申请表
require_once('fpdf/chinese-unicode.php');
require_once('fpdi/fpdi.php');
class MetadataPDF extends PDF_Unicode
{
public $metadata;
public $fontsize=10;
function draw()
{
$this->init();
$this->drawTitlePage();
$this->drawContent();
}
function init()
{
//$this->AddUniGBhwFont('ugb','AdobeSongStd-Light-Acro');
//$this->AddUniGBhwFont('ugh','AdobeHeitiStd-Light');
$this->AddUniGBhwFont('uGB');
$this->AddFont('uGB');
}
function DrawTitlePage()
{
$this->AddPage();
$this->Image('http://westdc.westgis.ac.cn/images/westdc_logo_white.gif',80,30,0,0,'','http://westdc.westgis.ac.cn/');
$this->SetFont('uGB','B',20);
$this->setXY(0,70);
$this->Cell(0,0,'Cold and Arid Regions Science Data Center',0,2,'C',false,'http://card.westgis.ac.cn/');
$imgurl='http://'.$_SERVER['SERVER_NAME'].'/service/bigthumb/uuid/'.$this->metadata['uuid'];
$imgsize=getimagesize($imgurl);
if ($this->metadata['filetype'] && $imgsize)
{
if ($imgsize[0]/$imgsize[1]>200/180)
$this->Image($imgurl,5,110,200,0,$this->metadata['filetype']);
else
$this->Image($imgurl,100-round(90.0*$imgsize[0]/$imgsize[1]),110,0,180,$this->metadata['filetype']);
}
$this->SetFont('uGB','B',20);
$this->setXY(0,80);
$this->multicell(0,10,$this->metadata['title'],0,'C');
//$this->setFont('Arial','',12);
$this->ln(10);
$this->SetFont('uGB','B',12);
$this->Cell(0,0,'UUID: '.$this->metadata['uuid'],0,2,'C',false,'http://card.westgis.ac.cn/data/'.$this->metadata['uuid']);
}
function DrawContent()
{
$this->addPage();
$this->setfont('uGB','',12);
//$this->setXY(15,80);
$this->multicell(0,10,$this->metadata['title'],0,'C','http://'.$_SERVER['SERVER_NAME'].'/data/'.$this->metadata['uuid']);
if ($this->metadata['title_en'])
{
//$this->setFont('times','',12);
$this->multicell(0,5,$this->metadata['title_en'],0,'C','http://'.$_SERVER['SERVER_NAME'].'/data/'.$this->metadata['uuid']);
}
$this->ln(10);
$this->setfont('uGB','',10);
$this->setFillColor(200,200,200);
$this->Cell(0,8,' Abstract',0,1,'L',true);
//$this->write(5,$this->metadata['description']);
$this->DrawTable($this->metadata['description']);
//todo: table in abstract
$this->ln(5);
$this->Cell(0,8,' Keywords',0,1,'L',true);
$this->write(5,'Theme: '.$this->metadata['keyword']['theme']);
$this->ln(5);
$this->write(5,'Place: '.$this->metadata['keyword']['place']);
$this->ln(5);
$this->write(5,'Temporal: '.$this->metadata['keyword']['temporal']);
$this->ln(5);
$this->write(5,'Discipline: '.$this->metadata['keyword']['discipline']);
$this->ln(5);
$this->write(5,'Statrum: '.$this->metadata['keyword']['stratum']);
$this->ln(5);
$this->Cell(0,8,' ISO 19115 Category',0,1,'L',true);
$this->write(5,'Category: '.$this->metadata['category']);
$this->ln(5);
$this->Cell(0,8,' Detail',0,1,'L',true);
if ($this->metadata['rfdenom'])
{
$this->write(5,'Scale: '.$this->metadata['rfdenom']);
$this->ln(5);
}
if ($this->metadata['resolution'])
{
$this->write(5,'Resolution: '.$this->metadata['resolution']);
$this->ln(5);
}
$this->write(5,'Project: '.$this->metadata['projection']);
$this->ln(5);
$this->write(5,'Data Volume(MB): '.$this->metadata['filesize']);
$this->ln(5);
$this->write(5,'Data Format: '.$this->metadata['fileformat']);
$this->ln(5);
$this->Cell(0,8,' Position and Thumbnail',0,1,'L',true);
$this->ln(5);
$x=$this->getX();$y=$this->getY();
$w=50*abs(($this->metadata['north']-$this->metadata['south'])/($this->metadata['west']-$this->metadata['east']));
if ($this->metadata['filetype']) $this->Image('http://'.$_SERVER['SERVER_NAME'].'/service/thumb/uuid/'.$this->metadata['uuid'],$x+80+$w,$y,0,50,$this->metadata['filetype']);
$this->rect($x+50,$y,$w,50);
$this->setXY($x+55,$y-4);
$this->write(5,'N:'.$this->metadata['north']);
$this->setXY($x+40,$y+20);
$this->write(5,'W:'.$this->metadata['west']);
$this->setXY($x+50+$w,$y+20);
$this->write(5,'E:'.$this->metadata['east']);
$this->setXY($x+55,$y+50);
$this->write(5,'S:'.$this->metadata['south']);
$this->ln(5);
$this->Cell(0,8,' Temporal Range',0,1,'L',true);
$this->write(5,'Start: '.$this->metadata['timebegin']);
$this->ln(5);
$this->write(5,'End: '.$this->metadata['timeend']);
$this->ln(5);
$this->Cell(0,8,' Citation',0,1,'L',true);
$this->write(5,$this->metadata['citation']);
$this->ln(5);
$this->Cell(0,8,' Recommended Publications',0,1,'L',true);
$this->write(5,$this->metadata['reference']);
//$this->ln(5);
$this->Cell(0,8,' DOI',0,1,'L',true);
$this->write(5,$this->metadata['doi']);
$this->ln(5);
$this->Cell(0,8,' Funding',0,1,'L',true);
$this->write(5,$this->metadata['suppinfo']);
$this->ln(5);
$this->Cell(0,8,' Limitation',0,1,'L',true);
$this->write(5,$this->metadata['uselimits']);
$this->Cell(0,8,' Online Resources',0,1,'L',true);
foreach($this->metadata['resources'] as $k=>$r)
{
$this->write(5,($k+1).'. '.$r['name'].' '.$r['linkage'],$r['linkage']);
$this->ln(5);
}
$this->Cell(0,8,' Contacts',0,1,'L',true);
$party_zh=array('resourceProvider'=>'Resource Provider','custodian'=>'Custodian','owner'=>'Owner','user'=>'User','distributor'=>'Distributor','originator'=>'Originator','pointOfContact'=>'Point of Contact','principalInvestigator'=>'Principal Investigator','processor'=>'Process','publisher'=>'Publisher','author'=>'Author');
foreach($this->metadata['contacts'] as $k=>$c)
{
$this->write(5,($k+1).'. '.$party_zh[$c['role']]);$this->ln(5);
$this->write(5,$c['individual'].' Organization: '.$c['organisation']);$this->ln(5);
$this->write(5,'Address: '.$c['country'].' '.$c['administractive'].' '.$c['city'].' '.$c['delivery']);$this->ln(5);
$this->write(5,'Zip code: '.$c['postal'].' Phone: '.$c['phone'].' Email: '.$c['email']);
$this->ln(5);
$this->ln(5);
}
}
function DrawTable($text)
{
$table=explode("{|",$text);
$this->write(5,$table[0]);
$table1=explode("|}",$table[1]);
$table=explode("|-",$table1[0]);
$header=explode("!",str_replace(array("\r\n", "\n", "\r"),'',$table[0]));
$data=array();
foreach($table as $line=>$tr)
{
if ($line>0 && !empty($tr))
{
$tr=substr(trim($tr),1);
$data[]=explode("||",$tr);
}
}
//Header
foreach($header as $k=>$col)
if ($k>0) $this->Cell(40,7,$col,1);
$this->Ln();
//Data
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
$this->write(5,$table1[1]);
}
function Footer()
{
//Page footer
$this->SetY(-15);
$this->SetFont('Arial','I',8);
$this->SetTextColor(128);
if ($this->PageNo()>1) $this->Cell(0,10,' - '.($this->PageNo()-1).' - ',0,0,'C');
}
}
?>