diff --git a/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php b/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php
index c4a1150d505f398dca2649e36a412fa376b7d9f7..adf1b8689b158254eee1ffd0b63567f516e5527d 100644
--- a/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php
+++ b/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php
@@ -38,6 +38,22 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  */
 class pdf_typhon extends ModelePDFDeliveryOrder
 {
+    var $db;
+    var $name;
+    var $description;
+    var $type;
+
+    var $phpmin = array(4,3,0); // Minimum version of PHP required by module
+    var $version = 'dolibarr';
+
+    var $page_largeur;
+    var $page_hauteur;
+    var $format;
+	var $marge_gauche;
+	var	$marge_droite;
+	var	$marge_haute;
+	var	$marge_basse;
+
 	var $emetteur;	// Objet societe qui emet
 
 	/**
@@ -75,26 +91,26 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 
 		$this->franchise=!$mysoc->tva_assuj;
 
-		// Recupere emmetteur
+		// Get source company
 		$this->emetteur=$mysoc;
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
+		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
 
-		// Defini position des colonnes
+		// Define position of columns
 		$this->posxdesc=$this->marge_gauche+1;
-		$this->posxcomm=120;
+		$this->posxcomm=111;
 		//$this->posxtva=111;
-		$this->posxup=132;
-		$this->posxqty=168;
-		$this->posxdiscount=162;
-		$this->postotalht=177;
+		//$this->posxup=126;
+		$this->posxqty=174;
+		//$this->posxdiscount=162;
+		//$this->postotalht=174;
 		if ($this->page_largeur < 210) // To work with US executive format
 		{
 			$this->posxcomm-=20;
 			//$this->posxtva-=20;
-			$this->posxup-=20;
+			//$this->posxup-=20;
 			$this->posxqty-=20;
-			$this->posxdiscount-=20;
-			$this->postotalht-=20;
+			//$this->posxdiscount-=20;
+			//$this->postotalht-=20;
 		}
 
 		$this->tva=array();
@@ -104,15 +120,19 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 
 
 	/**
-	 *	Fonction generant le bon de livraison sur le disque
-	 *
-	 *	@param	Object		$object   		Object livraison a generer
-	 *	@param	Translate	$outputlangs	Lang output object
-	 *	@return	int         				1 if OK, <=0 if KO
+     *  Function to build pdf onto disk
+     *
+     *  @param		Object		$object				Object to generate
+     *  @param		Translate	$outputlangs		Lang output object
+     *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
+     *  @param		int			$hidedetails		Do not show line details
+     *  @param		int			$hidedesc			Do not show desc
+     *  @param		int			$hideref			Do not show ref
+     *  @return     int             			1=OK, 0=KO
 	 */
-	function write_file($object,$outputlangs)
+	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
 	{
-		global $user,$langs,$conf;
+		global $user,$langs,$conf,$mysoc,$hookmanager;
 
 		if (! is_object($outputlangs)) $outputlangs=$langs;
 		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
@@ -126,17 +146,23 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 		$outputlangs->load("deliveries");
 		$outputlangs->load("sendings");
 
-		if ($conf->expedition->dir_output."/receipt")
+		if ($conf->expedition->dir_output)
 		{
 			$object->fetch_thirdparty();
 
-			$nblines = count($object->lines);
-
-			$objectref = dol_sanitizeFileName($object->ref);
-			$dir = $conf->expedition->dir_output."/receipt";
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
-			$file = $dir . "/" . $objectref . ".pdf";
-
+			// Definition of $dir and $file
+			if ($object->specimen)
+			{
+				$dir = $conf->expedition->dir_output."/receipt";
+				$file = $dir . "/SPECIMEN.pdf";
+			}
+			else
+			{
+				$objectref = dol_sanitizeFileName($object->ref);
+				$dir = $conf->expedition->dir_output."/receipt/" . $objectref;
+				$file = $dir . "/" . $objectref . ".pdf";
+			}
+			
 			if (! file_exists($dir))
 			{
 				if (dol_mkdir($dir) < 0)
@@ -148,9 +174,12 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 
 			if (file_exists($dir))
 			{
-                $pdf=pdf_getInstance($this->format);
+				$nblines = count($object->lines);
+				
+				// Create pdf instance
+				$pdf=pdf_getInstance($this->format);
                 $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
-                $heightforinfotot = 50;	// Height reserved to output the info and total part
+                $heightforinfotot = 30;	// Height reserved to output the info and total part
 		        $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
 	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
                 $pdf->SetAutoPageBreak(1,0);
@@ -195,7 +224,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 
 				/*
 				 // Positionne $this->atleastonediscount si on a au moins une remise
-				 for ($i = 0 ; $i < $nblignes ; $i++)
+				 for ($i = 0 ; $i < $nblines ; $i++)
 				 {
 				 if ($object->lines[$i]->remise_percent)
 				 {
@@ -214,7 +243,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 				$pdf->SetTextColor(0,0,0);
 
 				$tab_top = 90;
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?22:10);
+				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
 				$tab_height = 130;
 				$tab_height_newpage = 150;
 
@@ -223,7 +252,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 				{
 					$tab_top = 88;
 
-					$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page
+					$pdf->SetFont('','', $default_font_size - 1);
 					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
 					$nexY = $pdf->GetY();
 					$height_note=$nexY-$tab_top;
@@ -252,13 +281,46 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 					$pdf->SetTextColor(0,0,0);
 
 					$pdf->setTopMargin($tab_top_newpage);
-					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext);	// The only function to edit the bottom margin of current page to set it.
+					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
 					$pageposbefore=$pdf->getPage();
 
 					// Description of product line
 					$curX = $this->posxdesc-1;
-                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,108,3,$curX,$curY);
 
+                    $showpricebeforepagebreak=1;
+                    
+                    $pdf->startTransaction();
+                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxcomm-$curX,3,$curX,$curY,$hideref,$hidedesc);
+                    $pageposafter=$pdf->getPage();
+                    if ($pageposafter > $pageposbefore)	// There is a pagebreak
+                    {
+                    	$pdf->rollbackTransaction(true);
+                    	$pageposafter=$pageposbefore;
+                    	//print $pageposafter.'-'.$pageposbefore;exit;
+                    	$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
+                    	pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxcomm-$curX,4,$curX,$curY,$hideref,$hidedesc);
+                    	$posyafter=$pdf->GetY();
+                    	if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
+                    	{
+                    		if ($i == ($nblines-1))	// No more lines, and no space left to show total, so we create a new page
+                    		{
+                    			$pdf->AddPage('','',true);
+                    			if (! empty($tplidx)) $pdf->useTemplate($tplidx);
+                    			if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
+                    			$pdf->setPage($pagenb+1);
+                    		}
+                    	}
+                    	else
+                    	{
+                    		// We found a page break
+                    		$showpricebeforepagebreak=0;
+                    	}
+                    }
+                    else	// No pagebreak
+                    {
+                    	$pdf->commitTransaction();
+                    }
+                    
 					$nexY = $pdf->GetY();
                     $pageposafter=$pdf->getPage();
 					$pdf->setPage($pageposbefore);
@@ -266,17 +328,15 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
 
 					// We suppose that a too long description is moved completely on next page
-					if ($pageposafter > $pageposbefore) {
+					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
 						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
 					}
 
 					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
 
-					$nexY = $pdf->GetY()+4;
-
 					/*
 					 // TVA
-					 $pdf->SetXY($this->posxtva, $curY);
+					 $pdf->SetXY($this->posxcomm, $curY);
 					 $pdf->MultiCell(10, 4, ($object->lines[$i]->tva_tx < 0 ? '*':'').abs($object->lines[$i]->tva_tx), 0, 'R');
 
 					 // Prix unitaire HT avant remise
@@ -284,8 +344,9 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 					 $pdf->MultiCell(20, 4, price($object->lines[$i]->subprice), 0, 'R', 0);
 					 */
 					// Quantity
+					//$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
 					$pdf->SetXY($this->posxqty, $curY);
-					$pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'R');
+					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->posxqty, 3, $object->lines[$i]->qty_shipped, 0, 'R');
 					/*
 					 // Remise sur ligne
 					 $pdf->SetXY($this->posxdiscount, $curY);
@@ -307,7 +368,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 					 */
 
 					// Add line
-					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
+					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
 					{
 						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(210,210,210)));
 						//$pdf->SetDrawColor(190,190,200);
@@ -333,6 +394,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 						$pagenb++;
 						$pdf->setPage($pagenb);
 						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
 					}
 					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
 					{
@@ -349,34 +411,38 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 						$pdf->AddPage();
 						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
 						$pagenb++;
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
 					}
 				}
 
 				// Show square
 				if ($pagenb == 1)
 				{
-					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0);
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1;
+					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
+					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
 				}
 				else
 				{
-					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1);
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1;
+					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
+					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
 				}
 
-				/*
-				 * Pied de page
-				 */
+				// Affiche zone infos
+				$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
+				
+				// Pied de page
 				$this->_pagefoot($pdf,$object,$outputlangs);
-
+				$pdf->AliasNbPages();
+				
 				// Check product remaining to be delivered
 				// TODO doit etre modifie
 				//$waitingDelivery = $object->getRemainingDelivered();
+				/*
 				$waitingDelivery='';
 
 				if (is_array($waitingDelivery) & !empty($waitingDelivery))
 				{
-					$pdf->AddPage('P', 'A4');
+					$pdf->AddPage();
 
 					$this->_pagehead($pdf, $object, 1, $outputlangs);
 					$pdf-> SetY(90);
@@ -426,17 +492,28 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 
 					$this->_pagefoot($pdf,$object,$outputlangs);
 
-				}
-
-				$pdf->AliasNbPages();
+					$pdf->AliasNbPages();
+				}*/
 
 				$pdf->Close();
 
 				$pdf->Output($file,'F');
+
+				// Add pdfgeneration hook
+				if (! is_object($hookmanager))
+				{
+					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
+					$hookmanager=new HookManager($this->db);
+				}
+				$hookmanager->initHooks(array('pdfgeneration'));
+				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
+				global $action;
+				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
+
 				if (! empty($conf->global->MAIN_UMASK))
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
+					@chmod($file, octdec($conf->global->MAIN_UMASK));
 
-				return 1;
+				return 1;	// pas d'erreur
 			}
 			else
 			{
@@ -449,66 +526,90 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 		return 0;
 	}
 
-
+	/**
+	 *   Show miscellaneous information (payment mode, payment term, ...)
+	 *
+	 *   @param		PDF			&$pdf     		Object PDF
+	 *   @param		Object		$object			Object to show
+	 *   @param		int			$posy			Y
+	 *   @param		Translate	$outputlangs	Langs object
+	 *   @return	void
+	 */
+	function _tableau_info(&$pdf, $object, $posy, $outputlangs)
+	{
+		global $conf;
+		$default_font_size = pdf_getPDFFontSize($outputlangs);
+	
+		$pdf->SetFont('','', $default_font_size);
+		$pdf->SetXY($this->marge_gauche, $posy);
+		
+		$larg_sign = ($this->page_largeur-$this->marge_gauche-$this->marge_droite)/3;
+		$pdf->Rect($this->marge_gauche, $posy + 1, $larg_sign, 25);
+		$pdf->SetXY($this->marge_gauche + 2, $posy + 2);
+		$pdf->MultiCell($larg_sign,2, $outputlangs->trans("For").' '.$outputlangs->convToOutputCharset($mysoc->name).":",'','L');
+		
+		$pdf->Rect(2*$larg_sign+$this->marge_gauche, $posy + 1, $larg_sign, 25);
+		$pdf->SetXY(2*$larg_sign+$this->marge_gauche + 2, $posy + 2);
+		$pdf->MultiCell($larg_sign,2, $outputlangs->trans("ForCustomer").':','','L');
+	}
+	
 	/**
 	 *   Show table for lines
 	 *
 	 *   @param		PDF			&$pdf     		Object PDF
 	 *   @param		string		$tab_top		Top position of table
 	 *   @param		string		$tab_height		Height of table (rectangle)
-	 *   @param		int			$nexY			Y
+	 *   @param		int			$nexY			Y (not used)
 	 *   @param		Translate	$outputlangs	Langs object
-	 *   @param		int			$hidetop		Hide top bar of array
+	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
 	 *   @param		int			$hidebottom		Hide bottom bar of array
 	 *   @return	void
 	 */
 	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
 	{
 		global $conf,$mysoc;
+		
+		// Force to disable hidetop and hidebottom
+		$hidebottom=0;
+		if ($hidetop) $hidetop=-1;
+		
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
+		
+		// Amount in (at tab_top - 1)
+		$pdf->SetTextColor(0,0,0);
+		$pdf->SetFont('','', $default_font_size - 2);
 
-		$pdf->SetDrawColor(128,128,128);
+		// Output Rec
+		$this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
 
-		// Rect prend une longueur en 3eme param
-		$pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
-		// line prend une position y en 3eme param
 		if (empty($hidetop))
+		{
 			$pdf->line($this->marge_gauche, $tab_top+6, $this->page_largeur-$this->marge_droite, $tab_top+6);
-
-		$pdf->SetTextColor(0,0,0);
+		}
+		
+		$pdf->SetDrawColor(128,128,128);
 		$pdf->SetFont('','', $default_font_size - 1);
 
-		if (empty($hidetop)) {
+		if (empty($hidetop)) 
+		{
 			$pdf->SetXY($this->posxdesc-1, $tab_top+1);
-			$pdf->MultiCell(80,2, $outputlangs->transnoentities("Designation"),'','L');
+			$pdf->MultiCell($this->posxcomm - $this->posxdesc,2, $outputlangs->transnoentities("Designation"),'','L');
 		}
 
 		// Modif SEB pour avoir une col en plus pour les commentaires clients
 		$pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
 		if (empty($hidetop)) {
 			$pdf->SetXY($this->posxcomm, $tab_top+1);
-			$pdf->MultiCell(80,2, $outputlangs->transnoentities("Comments"),'','L');
+			$pdf->MultiCell($this->posxqty - $this->posxcomm,2, $outputlangs->transnoentities("Comments"),'','L');
 		}
 
 		// Qty
 		$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
 		if (empty($hidetop)) {
 			$pdf->SetXY($this->posxqty-1, $tab_top+1);
-			$pdf->MultiCell(30, 2, $outputlangs->transnoentities("QtyShipped"),'','R');
+			$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->posxqty, 2, $outputlangs->transnoentities("QtyShipped"),'','R');
 		}
 
-		if (empty($hidebottom)) {
-			// Modif Seb cadres signatures
-			$pdf->SetFont('','', $default_font_size);
-			$larg_sign = ($this->page_largeur-$this->marge_gauche-$this->marge_droite)/3;
-			$pdf->Rect($this->marge_gauche, ($tab_top + $tab_height + 3), $larg_sign, 25);
-			$pdf->SetXY($this->marge_gauche + 2, $tab_top + $tab_height + 5);
-			$pdf->MultiCell($larg_sign,2, $outputlangs->trans("For").' '.$outputlangs->convToOutputCharset($mysoc->name).":",'','L');
-
-			$pdf->Rect(2*$larg_sign+$this->marge_gauche, ($tab_top + $tab_height + 3), $larg_sign, 25);
-			$pdf->SetXY(2*$larg_sign+$this->marge_gauche + 2, $tab_top + $tab_height + 5);
-			$pdf->MultiCell($larg_sign,2, $outputlangs->trans("ForCustomer").':','','L');
-		}
 	}
 
 	/**
@@ -522,22 +623,29 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 	 */
 	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
 	{
-		global $langs,$conf,$mysoc;
+		global $conf,$langs,$hookmanager;
+
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
 
 		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
 
-		$pdf->SetTextColor(0,0,60);
-		$pdf->SetFont('','B', $default_font_size + 3);
-
-        $posx=$this->page_largeur-$this->marge_droite-100;
-		$posy=$this->marge_haute;
-
-		$pdf->SetXY($this->marge_gauche,$posy);
-
+		// Show Draft Watermark
+		if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
+		{
+			pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
+		}
+		
+		$pdf->SetTextColor(0,0,60);
+		$pdf->SetFont('','B', $default_font_size + 3);
+		
+		$posy=$this->marge_haute;
+		$posx=$this->page_largeur-$this->marge_droite-100;
+		
+		$pdf->SetXY($this->marge_gauche,$posy);
+		
 		// Logo
-		$logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
-		if ($mysoc->logo)
+		$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
+		if ($this->emetteur->logo)
 		{
 			if (is_readable($logo))
 			{
@@ -548,8 +656,8 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 			{
 				$pdf->SetTextColor(200,0,0);
 				$pdf->SetFont('','B', $default_font_size - 2);
-				$pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
-				$pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
+				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
+				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
 			}
 		}
 		else $pdf->MultiCell(100, 4, $this->emetteur->name, 0, 'L');
@@ -557,7 +665,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 		$pdf->SetFont('','B', $default_font_size + 2);
 		$pdf->SetXY($posx,$posy);
 		$pdf->SetTextColor(0,0,60);
-		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("DeliveryOrder")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
+		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DeliveryOrder")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
 
 		$pdf->SetFont('','',$default_font_size + 2);
 
@@ -585,69 +693,42 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 
 		$pdf->SetTextColor(0,0,60);
 
-		// Add origin linked objects
-		// TODO extend to other objects
-	    $object->fetchObjectLinked('','',$object->id,'delivery');
-
-	    if (! empty($object->linkedObjects))
-		{
-			$outputlangs->load('orders');
-
-			foreach($object->linkedObjects as $elementtype => $objects)
-			{
-				$object->fetchObjectLinked('','',$objects[0]->id,$objects[0]->element);
-
-				foreach($object->linkedObjects as $elementtype => $objects)
-				{
-					$num=count($objects);
-					for ($i=0;$i<$num;$i++)
-					{
-						$order=new Commande($this->db);
-						$result=$order->fetch($objects[$i]->id);
-						if ($result >= 0)
-						{
-							$posy+=5;
-							$pdf->SetXY($posx,$posy);
-							$pdf->SetFont('','', $default_font_size - 1);
-							$text=$order->ref;
-							if ($order->ref_client) $text.=' ('.$order->ref_client.')';
-							$pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
-						}
-					}
-				}
-			}
-		}
-
+		$posy+=2;
+		
+		// Show list of linked objects
+		$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
+		
 		if ($showaddress)
 		{
-			// Emetteur
+			// Sender properties
+			$carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
+			
+			// Show sender
 			$posy=42;
+			$posx=$this->marge_gauche;
+			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
 			$hautcadre=40;
+			
+			// Show sender frame
 			$pdf->SetTextColor(0,0,0);
 			$pdf->SetFont('','', $default_font_size - 2);
-			$pdf->SetXY($this->marge_gauche,$posy-5);
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":");
-
-
-			$pdf->SetXY($this->marge_gauche,$posy);
+			$pdf->SetXY($posx,$posy-5);
+			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
+			$pdf->SetXY($posx,$posy);
 			$pdf->SetFillColor(230,230,230);
 			$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
-
-
-			$pdf->SetXY($this->marge_gauche+2,$posy+3);
-
-			// Nom emetteur
 			$pdf->SetTextColor(0,0,60);
+
+			// Show sender name
+			$pdf->SetXY($posx+2,$posy+3);
 			$pdf->SetFont('','B',$default_font_size);
 			$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
 
-			// Sender properties
-			$carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
-
-			$pdf->SetFont('','', $default_font_size - 1);
-			$pdf->SetXY($this->marge_gauche+2,$posy+9);
-			$pdf->MultiCell(80, 3, $carac_emetteur, 0, 'L');
-
+			// Show sender information
+			$pdf->SetXY($posx+2,$posy+8);
+			$pdf->SetFont('','', $default_font_size - 1);
+			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
+			
 			// Client destinataire
 			$posy=42;
 			$pdf->SetTextColor(0,0,0);
@@ -655,7 +736,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 			$pdf->SetXY(102,$posy-5);
 			$pdf->MultiCell(80,5, $outputlangs->transnoentities("DeliveryAddress").":", 0, 'L');
 
-			// If SHIPPING contact defined on invoice, we use it
+			// If SHIPPING contact defined on order, we use it
 			$usecontact=false;
 			$arrayidcontact=$object->commande->getIdContact('external','SHIPPING');
 			if (count($arrayidcontact) > 0)
@@ -677,7 +758,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 				$carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
 			}
 
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
+			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,($usecontact?$object->contact:''),$usecontact,'target');
 
 			// Show recipient
 			$widthrecbox=100;
@@ -700,7 +781,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 
 			// Show recipient information
 			$pdf->SetFont('','', $default_font_size - 1);
-			$pdf->SetXY($posx+2,$posy+8);
+			$pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($carac_client_name,50)*4));
 			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
 		}
 
@@ -713,7 +794,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 	 * 		@param	Object		$object				Object to show
 	 *      @param	Translate	$outputlangs		Object lang for output
 	 *      @param	int			$hidefreetext		1=Hide free text
-	 *      @return	void
+	 *      @return	int								Return height of bottom margin including footer text
 	 */
 	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
 	{