public static function Documento($id_documento, $preview = FALSE, $params = NULL)
 {
     $dbase = DocumentoBaseDAO::getByPK($id_documento);
     $dbase->setJsonImpresion(str_replace("\\n", "", $dbase->getJsonImpresion()));
     $dbase->setJsonImpresion(str_replace("\\t", "", $dbase->getJsonImpresion()));
     $dbase->setJsonImpresion(stripslashes($dbase->getJsonImpresion()));
     if ("\"" == substr($dbase->getJsonImpresion(), 0, 1)) {
         $dbase->setJsonImpresion(substr($dbase->getJsonImpresion(), 1, -1));
     }
     $decoded_json = json_decode($dbase->getJsonImpresion());
     #echo $dbase->getJsonImpresion(); die;
     if (is_null($decoded_json)) {
         throw new InvalidDataException("json invalido");
     }
     $pdf = new Cezpdf(array(0, 0, $decoded_json->width, $decoded_json->height));
     if (is_file(POS_PATH_TO_SERVER_ROOT . "libs/ezpdf/fonts/Helvetica.afm")) {
         $pdf->selectFont(POS_PATH_TO_SERVER_ROOT . "libs/ezpdf/fonts/Helvetica.afm");
     } else {
         throw new Exception();
     }
     for ($i = 0; $i < sizeof($decoded_json->body); $i++) {
         switch ($decoded_json->body[$i]->type) {
             case "text":
                 if (!$preview) {
                     while (($posI = strpos($decoded_json->body[$i]->value, "{")) !== FALSE) {
                         $posF = strpos($decoded_json->body[$i]->value, "}");
                         $key = substr($decoded_json->body[$i]->value, $posI + 1, $posF - $posI - 1);
                         if (TRUE === array_key_exists($key, $params)) {
                             $decoded_json->body[$i]->value = substr_replace($decoded_json->body[$i]->value, $params[$key], $posI, $posF - $posI + 1);
                         } else {
                             $decoded_json->body[$i]->value = substr_replace($decoded_json->body[$i]->value, "", $posI, $posF - $posI + 1);
                         }
                     }
                 }
                 $pdf->addText($decoded_json->body[$i]->x, $decoded_json->body[$i]->y, $decoded_json->body[$i]->fontSize, utf8_decode($decoded_json->body[$i]->value));
                 break;
             case "round-box":
                 $x = $decoded_json->body[$i]->x;
                 $y = $decoded_json->body[$i]->y;
                 $w = $decoded_json->body[$i]->w;
                 $h = $decoded_json->body[$i]->h;
                 $pdf->setStrokeColor(0.3359375, 0.578125, 0.89453125);
                 $pdf->setLineStyle(1);
                 $pdf->line($x + 2, $y, $x + $w - 2, $y);
                 //arriba
                 $pdf->line($x, $y - 2, $x, $y - $h + 2);
                 //izquierda
                 $pdf->line($x + 2, $y - $h, $x + $w - 2, $y - $h);
                 //abajo
                 $pdf->line($x + $w, $y - 2, $x + $w, $y - $h + 2);
                 //derecha
                 $pdf->partEllipse($x + 3, $y - 3, 90, 180, 3);
                 //top-left
                 $pdf->partEllipse($x + $w - 3, $y - 3, 0, 90, 3);
                 //top-right
                 $pdf->partEllipse($x + $w - 3, $y - $h + 3, 360, 240, 3);
                 //bottom-right
                 $pdf->partEllipse($x + 3, $y - $h + 3, 180, 270, 3);
                 //bottom-left
                 break;
         }
     }
     //margenes de un centimetro para toda la pagina
     $pdf->ezSetMargins($decoded_json->marginTop, $decoded_json->marginBottom, $decoded_json->marginLeft, $decoded_json->marginRight);
     /**************************
      * ENCABEZADO
      ***************************/
     //$pdf->addText( self::puntos_cm(7.1), self::puntos_cm(26.1), 18, utf8_decode($title));
     //$pdf->addText( self::puntos_cm(7.1), self::puntos_cm(25.5), 12, utf8_decode($subtitle));
     $pdf->ezStream();
     exit;
 }