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 19/01/2011, 15h19   #1
Invité de passage
 
Inscription : novembre 2010
Messages : 35
Détails du profil
Informations forums :
Inscription : novembre 2010
Messages : 35
Points : 2
Points : 2
Par défaut [DOMPDF] Mettre la vue au format PDF

Bonjour, ca fait quelques heures que je gratte sur le net mais je ne trouve pas un tuto convenable pour la mise en place de dompdf

En fait, j'ai une vue qui contient un tableau pour la mise en place d'un planning :
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
<article>
 
<h2> Planning - <?php echo $this->pLib;?></h2> 
 
	<!-- Navigation entre les portails -->
	<nav class="navPortail">
		<ul>
			<?php 
				foreach ($this->portails as $p){
			?>
				<li>
					<a href="/planning/index/portail/<?php echo $p->cdPortail;?>/semaine/<?php echo $this->s; ?>"><?php echo $p->libPortail; ?></a>
				</li>
			<?php
				}
			?>
		</ul>
	</nav>
 
	<!-- Navigation entre les semaines -->
	<nav class="navDate">
		<?php
			// On n'affiche pas le bouton de retour Ã* la semaine précédente si on est en semaine 1 ou semaineCourante-5
			if($this->s!=1 && $this->sCourante-5<$this->s) {
		?>
		<a class="previous" href="<?php echo $this->url(
						array('module'=>'default', 
						'controller'=>'planning', 
						'action'=>'index',
						'portail'=>$this->p,
						'semaine'=>$this->s-1));?>">Précédente</a>
 
 
		<?php
			}
		?>
 
		<?php echo $this->lundi; ?> au <?php echo $this->samedi; ?>
 
 
		<?php
			// On n'affiche pas le bouton semaine suivante si on est en ou semaineCourante+5
			if($this->sCourante+5>$this->s) {
		?>			
 
		<a class="next" href="<?php echo $this->url(
						array('module'=>'default', 
						'controller'=>'planning', 
						'action'=>'index',
						'portail'=>$this->p,
						'semaine'=>$this->s+1
						));?>">Suivante</a>
		<?php 
			}
		?>
	</nav>
 
	<!-- Affichage du planning -->
	<table id="planning"> 
		<tr>
			<th> &nbsp; </th>
			<th> Lundi </th>
			<th> Mardi </th>
			<th> Mercredi </th>
			<th> Jeudi </th>
			<th> Vendredi </th>
			<th> Samedi </th>
		</tr>
 
 	<?php 
 	// On parcourt tous les horaires
 	for($i=0; $i<count($this->horaires); $i++){
 		echo "\n".'<tr>'."\n" ;
 		// les indices pairs correspondent Ã* 8h, 9h, etc. (on ne veut pas afficher les 8h30 etc.)
 		if ($i%2==0){
 			echo '<td rowspan="2" class="horaire">' .$this->horaires[$i]. '</td>'."\n";
 		}
 
 		//on parcourt les jours de la semaine
 		for($j=1; $j<=count($this->jours); $j++){
 			//s'il n'y a pas de conflits pour l'affichage de l'horaire
 			if(!$this->horaireObj->searchConflictOK(0, $i, null, $j, $this->s, $this->p)){
 				try{
 					// On essaye de récupérer l'horaire (marche pas forcément)
 					$hor=$this->horaireObj->searchHoraireOK($i, $j, $this->s, $this->p);
 
 					// si l'horaire est trouvé, on procède au reste de l'affichage
 					// on récupère la classe de l'horaire en fonction de si c'est un horaire ou non
 					if($hor['isDevoir']) $class="devoir";
 					else $class="soutien";
 
 					// La différence permet de savoir sur combien de ligne s'étend l'horaire
 					$diff=$hor['finHoraire']-$hor['debutHoraire'];
 
 					// On affiche la cellule
 					echo '<td rowspan="'.$diff.'" class="'.$class.'" >';
					echo '<h4>'.$hor['libHoraire'].'</h4>';
					echo $hor['infoHoraire'];
 					echo '</td>'."\n";
	 			}
	 			catch(Exception $e){
	 				// si la recherche a échoué, c'est qu'il n'y a pas d'horaire ici
	 				echo '<td class="vide"> &nbsp; </td>'."\n";
	 			}
 		}	
 
 
 		}
 
   		echo '</tr>'."\n";
 	}
 
 	?>
 	</table>
 
 </article>
et j'aimerai ajouter un bouton "Avoir le planning au format PDF".

Seulement, je ne vois vraiment pas comment faire. Si je pouvais avoir un peu d'aide au moins pour débuter, sans qu'on me redirige essentiellement vers des tutos sur le net.
Kai231 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/01/2011, 09h31   #2
Invité de passage
 
Inscription : novembre 2010
Messages : 35
Détails du profil
Informations forums :
Inscription : novembre 2010
Messages : 35
Points : 2
Points : 2
Je suis en train de continuer.

J'essaye d'utiliser "DomPDF", le fichier PDF est bien généré mais impossible de l'ouvrir.

Voici l'erreur qui est contenue dans le PDF

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
 
Fatal error: Uncaught exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent in , line 0' in /var/www/html/zendTest/library/Zend/Controller/Response/Abstract.php on line 321
 
Zend_Controller_Response_Exception: Cannot send headers; headers already sent in , line 0 in /var/www/html/zendTest/library/Zend/Controller/Response/Abstract.php on line 321
 
Call Stack:
    0.0004     331324   1. {main}() /var/www/html/zendTest/public/index.php:0
    0.0559    5087628   2. Zend_Application->run() /var/www/html/zendTest/public/index.php:26
    0.0559    5087628   3. Zend_Application_Bootstrap_Bootstrap->run() /var/www/html/zendTest/library/Zend/Application.php:366
    0.0560    5087684   4. Zend_Controller_Front->dispatch() /var/www/html/zendTest/library/Zend/Application/Bootstrap/Bootstrap.php:97
    0.1706   11136688   5. Zend_Controller_Response_Abstract->sendResponse() /var/www/html/zendTest/library/Zend/Controller/Front.php:992
    0.1706   11136688   6. Zend_Controller_Response_Abstract->sendHeaders() /var/www/html/zendTest/library/Zend/Controller/Response/Abstract.php:766
    0.1706   11136716   7. Zend_Controller_Response_Abstract->canSendHeaders() /var/www/html/zendTest/library/Zend/Controller/Response/Abstract.php:339
Voici l'Action de mon contrôleur :

Code :
1
2
3
4
5
6
7
8
9
10
11
public function planningpdfAction() {
		$this->_helper->layout->disableLayout();
		require_once('../library/dompdf/dompdf_config.inc.php');
        spl_autoload_register('DOMPDF_autoload');
        $html = "<html><body>Test</body></html>";
 
        $dompdf = new DOMPDF();
        $dompdf->load_html($html);
        $dompdf->render();
        $dompdf->stream("sample.pdf");
	}
Quelqu'un a une idée ?
Kai231 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/01/2011, 10h12   #3
Membre chevronné
 
Homme Taoufiq Ben
Développeur Web
Inscription : mai 2009
Messages : 456
Détails du profil
Informations personnelles :
Nom : Homme Taoufiq Ben
Âge : 25
Localisation : Maroc

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : mai 2009
Messages : 456
Points : 639
Points : 639
J'ai jamais utiliser le domPDF mais j'utilise html2pdf et ça marche bien.
m4riachi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/01/2011, 10h51   #4
Invité de passage
 
Inscription : novembre 2010
Messages : 35
Détails du profil
Informations forums :
Inscription : novembre 2010
Messages : 35
Points : 2
Points : 2
Cela fonctionne à peu près en ajoutant :

Code :
$this->_helper->viewRenderer->setNoRender();
dans le contrôleur.
Kai231 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/01/2011, 15h30   #5
Invité de passage
 
Inscription : novembre 2010
Messages : 35
Détails du profil
Informations forums :
Inscription : novembre 2010
Messages : 35
Points : 2
Points : 2
En revanche, on a un sacré soucis pour les tableaux. Quelqu'un a déjà réussi ?
Kai231 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/01/2011, 15h33   #6
Membre expérimenté
 
Avatar de manuscle
 
Homme Emmanuel Belair
Développeur informatique
Inscription : septembre 2004
Messages : 463
Détails du profil
Informations personnelles :
Nom : Homme Emmanuel Belair
Âge : 32
Localisation : France, Gironde (Aquitaine)

Informations professionnelles :
Activité : Développeur informatique
Secteur : Distribution

Informations forums :
Inscription : septembre 2004
Messages : 463
Points : 597
Points : 597
Un exemple avec FPDF:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
// Dans ton controleur:
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        require_once('html2pdf/html2pdf.class.php');
        $pdf=new HTML2PDF('P','A4','fr');
        $string = $this->view->render('tonTemplate.phtml');
 
        $pdf->WriteHTML($string);
        $body = $pdf->Output('html.pdf','S');
            $filename = 'nomDeTonFichier.pdf';
            $this->getResponse()->setHeader('Content-type','application/pdf')
                                ->setheader('Content-Disposition','attachement; filename='.$filename.';');
            $this->getResponse()->setBody($body);
Ne te reste plus qu'a remplacer FPDF par DOMPDF et le tour est joué!
__________________
Les idiots sont ceux qui ne posent jamais de question!
manuscle est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/02/2011, 20h54   #7
Invité de passage
 
Fabien
Inscription : février 2008
Messages : 3
Détails du profil
Informations personnelles :
Nom : Fabien
Âge : 26
Localisation : France, Charente Maritime (Poitou Charente)

Informations forums :
Inscription : février 2008
Messages : 3
Points : 1
Points : 1
Bonjour, je suis un développeur de la librairie DOMPDF, est ce que je peux aider ?A premiere vue, tu utilises la version 0.5, l'autoloader a changé dans la nouvelle version (encore en beta), elle doit gérer ce genre de problème.
PhenXDesign est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h25.


 
 
 
 
Partenaires

Hébergement Web