Précédent   Forum des professionnels en informatique > PHP > Outils > Zend > Zend Framework > Autres composants
Autres composants Forum de support sur les autres composants de Zend Framework.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 09/07/2007, 12h00   #1
Membre confirmé
 
Avatar de TheDrev
 
Inscription : novembre 2006
Messages : 302
Détails du profil
Informations personnelles :
Âge : 28
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : novembre 2006
Messages : 302
Points : 209
Points : 209
Par défaut zend_pdf retour à la ligne automatique

Bonjour, existe il un moyen d'effectuer des retours a la ligne automatique avec zend_pdf ?

De plus, j'aimerai savoir quel est le caractere retour chariot pour mes retour a la ligne 'manuel' .

Merci
TheDrev est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/07/2007, 15h00   #2
Membre chevronné
 
Avatar de haltabush
 
Développeur Web
Inscription : avril 2005
Messages : 726
Détails du profil
Informations personnelles :
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : avril 2005
Messages : 726
Points : 790
Points : 790
J'ai une petite blague pour toi : le saut de ligne n'est pas encore implémenté
Utilise plutot FPDF.


Edit : bon si tu es aussi acharné (enfin stupide,plutot ) que moi, ut peux jeter un oeil à ma classe perso:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
Zend_Loader::loadClass('Zend_Pdf');
class Models_TableauPdf{
	private $pdfDoc=null;//Zend_Pdf object
	private $trads;//$this->view du controller (to get traductions)
	private $styleTitre=null;//style1
	private $styleGeneral=null;//style2
	private $marge=10;//default margin (top, bottom, left, right)
	private $margeInterne=6;//Text margin
	private $width;//page width
	private $height;//page height
	private $data;//infos maintenance
	private $type;//created or realised
	private $nbByPage=35;
	private $defaultLineHeight=10;
 
	private $curentY=0;//POsition Y de la ligne
	private $curentX=0;// Position X de la colonne
	private $curentLineHeight=0;//Hauteur de la colonne
	private $curentCellWidth=0;//Largeur de la colonne courante
	private $curentFont;
 
	public function Models_TableauPdf($infosView, $data, $type){
		$this->pdfDoc=new Zend_Pdf();
		$this->trads=$infosView;
		$this->data=$data;
		$this->type=$type;
		$this->pdfDoc->pages[0]=$this->pdfDoc->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE  );
		$this->width=$this->pdfDoc->pages[0]->getWidth();
		$this->height=$this->pdfDoc->pages[0]->getHeight();
		$this->curentX=$this->marge;
		$this->curentY=$this->height-$this->marge;
		$this->curentLineHeight=$this->defaultLineHeight;
 
 
		// Crée un nouveau style
		$this->styleTitre = new Zend_Pdf_Style();
		$this->styleTitre->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
		$this->styleTitre->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
		$this->styleTitre->setLineWidth(1);
		$this->styleTitre->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 9);
 
		$this->styleGeneral=new Zend_Pdf_Style();
		$this->styleGeneral->setFillColor(new Zend_Pdf_Color_RGB(0,0,0));
		$this->styleGeneral->setLineColor(new Zend_Pdf_Color_Grayscale(0.5));
		$this->styleGeneral->setLineWidth(1);
		$this->styleGeneral->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER), 7);
	}
 
	/**
	* Returns the total width in points of the string using the specified
	font and
	* size.
	*
	* This is not the most efficient way to perform this calculation. I'm
	* concentrating optimization efforts on the upcoming layout manager
	class.
	* Similar calculations exist inside the layout manager class, but
	widths are
	* generally calculated only after determining line fragments.
	*
	* @param string $string
	* @param Zend_Pdf_Resource_Font $font
	* @param float $fontSize Font size in points
	* @return float
	*/
	private function widthForStringUsingFontSize($string, $font, $fontSize)
	{
	     $drawingString = iconv('utf-8', 'UTF-16BE', $string);
	     $characters = array();
	     for ($i = 0; $i < strlen($drawingString); $i++) {
	         $characters[] = (ord($drawingString[$i++]) << 8) | ord
	($drawingString[$i]);
	     }
	     $glyphs = $font->cmap->glyphNumbersForCharacters($characters);
	     $widths = $font->widthsForGlyphs($glyphs);
	     $stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) *
	$fontSize;
	     return $stringWidth;
	}
 
	private function formatTextHeight($texte, $width){
		$i=0;
		$nonAssignedTexte=$texte;
		$font=$this->pdfDoc->pages[0]->getStyle()->getFont();
		$fontSize=$this->pdfDoc->pages[0]->getStyle()->getFontSize();
		$texteWidth=$this->widthForStringUsingFontSize($nonAssignedTexte,$font, $fontSize);
		$assignedTexte='';
		$tabTexteRetour=array();
		while(mb_strlen($nonAssignedTexte, 'utf-8')>0){
			$position=0;
			$assignedTexte='';
			$texteWidth=$this->widthForStringUsingFontSize($nonAssignedTexte,$font, $fontSize);;
			$j=0;
			while ($texteWidth>$width){
				$assignedTexte=mb_substr($nonAssignedTexte, 0, (mb_strlen($nonAssignedTexte, 'utf-8')-$j), 'utf-8');
				$texteWidth=$this->widthForStringUsingFontSize($assignedTexte,$font, $fontSize);
				$j++;
			}
			if($j==0){
				$tabTexteRetour[]=$nonAssignedTexte;
				$nonAssignedTexte='';
			}else{
				$position=mb_strlen($assignedTexte, 'utf-8');
				$nonAssignedTexte=mb_substr($nonAssignedTexte,$position,mb_strlen($nonAssignedTexte, 'utf-8'), 'utf-8');
				$tabTexteRetour[]=$assignedTexte;
			}
			$i++;
		}
		if ($this->curentLineHeight<$this->defaultLineHeight*$i){
			$this->curentLineHeight=$this->defaultLineHeight*$i;
		}
		return $tabTexteRetour;
	}
 
	private function createLine($idPage, $data, $widths){
		//1ère étape : on récupère la hauteur max de la ligne
		if (count($data)!=count($widths)){
			return null;
		}
		$nbData=count($data);
		$this->curentX=$this->marge;
		for ($i=0; $i<$nbData; $i++){
			$data[$i]=$this->formatTextHeight($data[$i], $widths[$i]-$this->margeInterne);
			foreach ($data[$i] as $texte){
				$this->pdfDoc->pages[$idPage]->drawText($texte, $this->curentX+$this->margeInterne/2, $this->curentY-$this->defaultLineHeight+2, 'utf-8');
				$this->curentY=$this->curentY-$this->defaultLineHeight;
			}
			$this->curentY=$this->curentY+$this->defaultLineHeight*(count($data[$i]));
			$this->curentX=$this->curentX+$widths[$i];
		}
		$x=$this->marge;
		for ($i=0; $i<$nbData;$i++){
			$this->pdfDoc->pages[$idPage]->drawLine($x, $this->curentY, $x, $this->curentY-$this->curentLineHeight);
			$x=$widths[$i]+$x;
		}
		$x=$this->width-$this->marge;
		$this->pdfDoc->pages[$idPage]->drawLine($x, $this->curentY, $x, $this->curentY-$this->curentLineHeight);
		$this->pdfDoc->pages[$idPage]->drawLine($this->marge, $this->curentY-$this->curentLineHeight, $this->width-$this->marge, $this->curentY-$this->curentLineHeight);
	}
 
	private function createTitre($idPage, $widths){
		$data=array();
		$data[]=$this->trads->trad_reference;
		$data[]=$this->trads->trad_status;
		$data[]=$this->trads->trad_ligne;
		$data[]=$this->trads->trad_machine;
		$data[]=$this->trads->trad_responsable_realisation;
		$data[]=$this->trads->trad_description_probleme;
		$data[]=$this->trads->trad_suggestions;
		$data[]=$this->trads->trad_date_creation;
		if ($this->type=='crees'){
			$data[]=$this->trads->trad_date_realisation_prevue;
		}else{
			$data[]=$this->trads->trad_date_realisation;
		}
		$this->pdfDoc->pages[$idPage]->setStyle($this->styleTitre);
		$this->createLine($idPage, $data, $widths);
		$this->curentY=$this->curentY - $this->curentLineHeight;
	}
	public function render(){
		//error_reporting('NONE');
		$nbMaintenance=count($this->data);
		$tableWidth=array(50, 40,35,100,125,150,147,95,95);
		$idPage=0;
 
		$this->createTitre($idPage, $tableWidth);
		$this->pdfDoc->pages[0]->setStyle($this->styleGeneral);
		foreach ($this->data as $infosMaintenance){
			$dataCurLine=array();
			$this->curentLineHeight=$this->defaultLineHeight;
			if (($this->curentY)<=$this->marge+$this->defaultLineHeight*3){
				$idPage++;
				$this->pdfDoc->pages[$idPage]=$this->pdfDoc->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
				$this->curentY=$this->height-$this->marge;
				$this->createTitre($idPage,$tableWidth);
				$this->pdfDoc->pages[$idPage]->setStyle($this->styleGeneral);
 
			}
			$dataCurLine[]=$infosMaintenance['m_a_o_id'].'-'.$infosMaintenance['m_a_ref'].'-'.$infosMaintenance['m_a_chrono_id'];
			$dataCurLine[]=$this->trads->{'trad_status'.$infosMaintenance['m_a_g_status_id']};
			$dataCurLine[]=$this->trads->{'trad_ligne'.$infosMaintenance['m_a_g_lignes_id']};
			$dataCurLine[]=$this->trads->{'trad_machine'.$infosMaintenance['m_a_g_machines_id']};
			$texteRespReal='';
			foreach ($infosMaintenance['listeRespReal'] as $respReal){
				$texteRespReal.=$respReal['g_u_nom'].' '.$respReal['g_u_prenom']."\r\n";
			}
			$dataCurLine[]=$texteRespReal;
			$dataCurLine[]=$infosMaintenance['m_a_desc_probleme'];
			$dataCurLine[]=$infosMaintenance['m_a_suggestion'];
			$dataCurLine[]=$infosMaintenance['m_a_date_creation'];
			if ($this->type=='crees'){
				$dataCurLine[]=$infosMaintenance['m_a_date_prevue'];
			}else{
				$dataCurLine[]=$infosMaintenance['m_a_date_realisation'];
			}
 
			$this->createLine($idPage, $dataCurLine, $tableWidth);
			$this->curentY=$this->curentY - $this->curentLineHeight;
		}
		return $this->pdfDoc->render();
	}
}
__________________
HADOPI : black-out du net!
haltabush est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/07/2007, 12h44   #3
Membre confirmé
 
Avatar de TheDrev
 
Inscription : novembre 2006
Messages : 302
Détails du profil
Informations personnelles :
Âge : 28
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : novembre 2006
Messages : 302
Points : 209
Points : 209
Apres avoir lu et relu la doc sans resultat, c'est ce que je craigais.
Merci quand meme pour le complement d'info !
TheDrev est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 20h24.


 
 
 
 
Partenaires

Hébergement Web