IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

FPDF-FPDI et symfony


Sujet :

Symfony PHP

  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Février 2007
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 46
    Par défaut FPDF-FPDI et symfony
    Bonjour,

    J'utilise Symfony pour une application et j'essaye de créer un pdf avec la librairie FPDF (et son extension FPDI pour repdrendre un pdf existant).

    J'ai d'abord réaliser le code de génération du pdf hors Symfony et tout marche niquel :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?php
    //FPDI permet de reprendre un pdf existant
    //FPDI herite de FPDF_TPL, elle meme heritant de FPDF
    require('fpdf/fpdi.php');
    require('fpdf/gif.php');
     
    //instanciation et allocation en memoire
    $pdf = new FPDI();
     
    //chargement du fichier existant
    //il s'agit du papier a en-tete
    $pagecount = $pdf->setSourceFile('test.pdf');
     
    //transformation de la source en template (FPDF_TPL)
    $tpl = $pdf->importPage(1, '/MediaBox');
     
    //ajout d'une page
    $pdf->addPage();
     
    //zoom de la page a 100%, affichage continu d'une page à l'autre
    $pdf->SetDisplayMode('real', 'continuous');
     
    //ajout du template
    $pdf->useTemplate($tpl);
     
    /** DESTINATAIRE **/
    $tabulationX = 115;
    $tabulationY = 55;
    $margeGauche = 30;
     
    $pdf->SetFont('Arial', 'B', 11);
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->Cell(0,0,'Mr Dupond',0,2);
     
    $tabulationY = $tabulationY + 5;
    $pdf->SetFont('Arial', '', 11);
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->Cell(0,0,'adresse',0,2);
     
    $tabulationY = $tabulationY + 5;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->Cell(0,0,'code postal et ville',0,2);
    /*******************/
     
    /** DATE D'ENVOI **/
    $tabulationY = $tabulationY + 20;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->Cell(0,0,'Lyon, le 01/04/2008',0,2);
    /*******************/
     
    /** N°DE POLICE **/
    $pdf->SetFont('Arial', 'U', 11);
    $tabulationY = $tabulationY + 30;
    $tabulationX = $margeGauche;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->Cell(25,0,'N° de produit :',0,0);
    $pdf->SetFont('Arial', '', 11);
    $pdf->Cell(0,0,'012345678910',0,2);
    /*******************/
     
    /** CONTENT **/
    $paragraphe1 = 'contenu paragraphe';
    $paragraphe2 = 'contenu paragraphe';
    $paragraphe3 = 'contenu paragraphe';
    $paragraphe4 = 'contenu paragraphe';
    $largeurParagraphe = 150;
     
    $tabulationY = $tabulationY + 15;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->Cell(0,0,'Bonjour,',0,2);
     
    $tabulationY = $tabulationY + 7;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->MultiCell($largeurParagraphe,4,$paragraphe1,0,'J');
     
    $tabulationY = $tabulationY + 14;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->Cell(0,0,'Merci de bien vouloir :',0,2);
     
    $tabulationY = $tabulationY + 5;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->MultiCell($largeurParagraphe,4,$paragraphe2,0,'J');
     
    $tabulationY = $tabulationY + 11;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->MultiCell($largeurParagraphe,4,$paragraphe3,0,'J');
     
    $tabulationY = $tabulationY + 15;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->MultiCell($largeurParagraphe,4,$paragraphe4,0,'J');
    /*******************/
     
    /** SIGNATURE **/
    $tabulationY = $tabulationY + 25;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->Cell(0,0,'John Smith',0,2);
     
    $tabulationY = $tabulationY + 5;
    $pdf->setXY($tabulationX,$tabulationY);
    $pdf->Cell(0,0,'Président, Directeur Général',0,2);
     
    $tabulationY = $tabulationY + 5;
    $pdf->Image('signature.gif',$tabulationX,$tabulationY,46,15,'gif');
    /*****************/
     
    //affichage du pdf dans le navigateur
    $pdf->Output();
    ?>
    Ensuite j'ai entrepris de passer ce bout de code dans le fichier action.class.php de mon module, dans la methode executeIndex().

    J'ai modifié le view.yml pour ne mettre que has_layout: off et content-type : application/pdf

    Le souci est qu'il y des erreurs :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    Warning: fseek() [function.fseek]: stream does not support seeking in D:\www\symfony\apps\monsymfony\modules\editions\lib\fpdf\pdf_parser.php on line 159
     
    Warning: filesize() [function.filesize]: stat failed for http://localhost/symfony/web/templatesDocuments/pdf/tetedelettre.pdf in D:\www\symfony\apps\monsymfony\modules\editions\lib\fpdf\pdf_parser.php on line 168
     
    Warning: fseek() [function.fseek]: stream does not support seeking in D:\www\symfony\apps\monsymfony\modules\editions\lib\fpdf\pdf_parser.php on line 168
     
    Warning: fseek() [function.fseek]: stream does not support seeking in D:\www\symfony\apps\monsymfony\modules\editions\lib\fpdf\pdf_parser.php on line 191
     
    Warning: fseek() [function.fseek]: stream does not support seeking in D:\www\symfony\apps\monsymfony\modules\editions\lib\fpdf\pdf_parser.php on line 198
     
    Warning: fseek() [function.fseek]: stream does not support seeking in D:\www\symfony\apps\monsymfony\modules\editions\lib\fpdf\pdf_parser.php on line 191
     
    Warning: fseek() [function.fseek]: stream does not support seeking in D:\www\symfony\apps\monsymfony\modules\editions\lib\fpdf\pdf_parser.php on line 198
     
    Warning: fseek() [function.fseek]: stream does not support seeking in D:\www\symfony\apps\monsymfony\modules\editions\lib\fpdf\pdf_parser.php on line 191
     
    Warning: fseek() [function.fseek]: stream does not support seeking in D:\www\symfony\apps\monsymfony\modules\editions\lib\fpdf\pdf_parser.php on line 198
    FPDF error: Unable to find xref table - Maybe a Problem with 'auto_detect_line_endings'
    Comme ça ne concerne qu'un seul fichier, pdf_parser.php, voici son code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
     
    <?php
    //
    //  FPDI - Version 1.2
    //
    //    Copyright 2004-2007 Setasign - Jan Slabon
    //
    //  Licensed under the Apache License, Version 2.0 (the "License");
    //  you may not use this file except in compliance with the License.
    //  You may obtain a copy of the License at
    //
    //      http://www.apache.org/licenses/LICENSE-2.0
    //
    //  Unless required by applicable law or agreed to in writing, software
    //  distributed under the License is distributed on an "AS IS" BASIS,
    //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    //  See the License for the specific language governing permissions and
    //  limitations under the License.
    //
     
    if (!defined ('PDF_TYPE_NULL'))
        define ('PDF_TYPE_NULL', 0);
    if (!defined ('PDF_TYPE_NUMERIC'))
        define ('PDF_TYPE_NUMERIC', 1);
    if (!defined ('PDF_TYPE_TOKEN'))
        define ('PDF_TYPE_TOKEN', 2);
    if (!defined ('PDF_TYPE_HEX'))
        define ('PDF_TYPE_HEX', 3);
    if (!defined ('PDF_TYPE_STRING'))
        define ('PDF_TYPE_STRING', 4);
    if (!defined ('PDF_TYPE_DICTIONARY'))
        define ('PDF_TYPE_DICTIONARY', 5);
    if (!defined ('PDF_TYPE_ARRAY'))
        define ('PDF_TYPE_ARRAY', 6);
    if (!defined ('PDF_TYPE_OBJDEC'))
        define ('PDF_TYPE_OBJDEC', 7);
    if (!defined ('PDF_TYPE_OBJREF'))
        define ('PDF_TYPE_OBJREF', 8);
    if (!defined ('PDF_TYPE_OBJECT'))
        define ('PDF_TYPE_OBJECT', 9);
    if (!defined ('PDF_TYPE_STREAM'))
        define ('PDF_TYPE_STREAM', 10);
     
    require_once("pdf_context.php");
    require_once("wrapper_functions.php");
     
    class pdf_parser {
     
    	/**
         * Filename
         * @var string
         */
        var $filename;
     
        /**
         * File resource
         * @var resource
         */
        var $f;
     
        /**
         * PDF Context
         * @var object pdf_context-Instance
         */
        var $c;
     
        /**
         * xref-Data
         * @var array
         */
        var $xref;
     
        /**
         * root-Object
         * @var array
         */
        var $root;
     
     
        /**
         * Constructor
         *
         * @param string $filename  Source-Filename
         */
    	function pdf_parser($filename) {
            $this->filename = $filename;
     
            $this->f = @fopen($this->filename, "rb");
     
            if (!$this->f)
                $this->error(sprintf("Cannot open %s !", $filename));
     
            $this->getPDFVersion();
     
            $this->c = new pdf_context($this->f);
            // Read xref-Data
            $this->pdf_read_xref($this->xref, $this->pdf_find_xref());
     
            // Check for Encryption
            $this->getEncryption();
     
            // Read root
            $this->pdf_read_root();
        }
     
        /**
         * Close the opened file
         */
        function closeFile() {
        	if (isset($this->f)) {
        	    fclose($this->f);	
        		unset($this->f);
        	}	
        }
     
        /**
         * Print Error and die
         *
         * @param string $msg  Error-Message
         */
        function error($msg) {
        	die("<b>PDF-Parser Error:</b> ".$msg);	
        }
     
        /**
         * Check Trailer for Encryption
         */
        function getEncryption() {
            if (isset($this->xref['trailer'][1]['/Encrypt'])) {
                $this->error("File is encrypted!");
            }
        }
     
    	/**
         * Find/Return /Root
         *
         * @return array
         */
        function pdf_find_root() {
            if ($this->xref['trailer'][1]['/Root'][0] != PDF_TYPE_OBJREF) {
                $this->error("Wrong Type of Root-Element! Must be an indirect reference");
            }
            return $this->xref['trailer'][1]['/Root'];
        }
     
        /**
         * Read the /Root
         */
        function pdf_read_root() {
            // read root
            $this->root = $this->pdf_resolve_object($this->c, $this->pdf_find_root());
        }
     
        /**
         * Get PDF-Version
         *
         * And reset the PDF Version used in FPDI if needed
         */
        function getPDFVersion() {
            fseek($this->f, 0);
            preg_match("/\d\.\d/",fread($this->f,16),$m);
            $this->pdfVersion = $m[0];
        }
     
        /**
         * Find the xref-Table
         */
        function pdf_find_xref() {
           	fseek ($this->f, -min(filesize($this->filename),1500), SEEK_END);
            $data = fread($this->f, 1500);
     
            $pos = strlen($data) - strpos(strrev($data), strrev('startxref')); 
            $data = substr($data, $pos);
     
            if (!preg_match('/\s*(\d+).*$/s', $data, $matches)) {
                $this->error("Unable to find pointer to xref table");
        	}
     
        	return (int) $matches[1];
        }
     
        /**
         * Read xref-table
         *
         * @param array $result Array of xref-table
         * @param integer $offset of xref-table
         * @param integer $start start-position in xref-table
         * @param integer $end end-position in xref-table
         */
        function pdf_read_xref(&$result, $offset, $start = null, $end = null) {
            if (is_null ($start) || is_null ($end)) {
    		    fseek($this->f, $o_pos = $offset);
                $data = trim(fgets($this->f,1024));
     
                if (strlen($data) == 0) 
                    $data = trim(fgets($this->f,1024));
     
                if ($data !== 'xref') {
                	fseek($this->f, $o_pos);
                	$data = trim(_fgets($this->f, true));
                	if ($data !== 'xref') {
                	    if (preg_match('/(.*xref)(.*)/m', $data, $m)) { // xref 0 128 - in one line
                            fseek($this->f, $o_pos+strlen($m[1]));            	        
                	    } elseif (preg_match('/(x|r|e|f)+/', $data, $m)) { // correct invalid xref-pointer
                	        $tmpOffset = $offset-4+strlen($m[0]);
                	        $this->pdf_read_xref($result, $tmpOffset, $start, $end);
                	        return;
                        } else {
                            $this->error("Unable to find xref table - Maybe a Problem with 'auto_detect_line_endings'");
                	    }
                	}
        		}
     
        		$o_pos = ftell($this->f);
        	    $data = explode(' ', trim(fgets($this->f,1024)));
    			if (count($data) != 2) {
        	        fseek($this->f, $o_pos);
        	        $data = explode(' ', trim(_fgets($this->f, true)));
     
                	if (count($data) != 2) {
                	    if (count($data) > 2) { // no lineending
                	        $n_pos = $o_pos+strlen($data[0])+strlen($data[1])+2;
                	        fseek($this->f, $n_pos);
                	    } else {
                            $this->error("Unexpected header in xref table");
                	    }
                	}
                }
                $start = $data[0];
                $end = $start + $data[1];
            }
     
            if (!isset($result['xref_location'])) {
                $result['xref_location'] = $offset;
        	}
     
        	if (!isset($result['max_object']) || $end > $result['max_object']) {
        	    $result['max_object'] = $end;
        	}
     
        	for (; $start < $end; $start++) {
        		$data = ltrim(fread($this->f, 20)); // Spezifications says: 20 bytes including newlines
        		$offset = substr($data, 0, 10);
        		$generation = substr($data, 11, 5);
     
        	    if (!isset ($result['xref'][$start][(int) $generation])) {
        	    	$result['xref'][$start][(int) $generation] = (int) $offset;
        	    }
        	}
     
        	$o_pos = ftell($this->f);
            $data = fgets($this->f,1024);
    		if (strlen(trim($data)) == 0) 
    		    $data = fgets($this->f, 1024);
     
            if (preg_match("/trailer/",$data)) {
                if (preg_match("/(.*trailer[ \n\r]*)/",$data,$m)) {
                	fseek($this->f, $o_pos+strlen($m[1]));
        		}
     
    			$c = new pdf_context($this->f);
        	    $trailer = $this->pdf_read_value($c);
     
        	    if (isset($trailer[1]['/Prev'])) {
        	    	$this->pdf_read_xref($result, $trailer[1]['/Prev'][1]);
        		    $result['trailer'][1] = array_merge($result['trailer'][1], $trailer[1]);
        	    } else {
        	        $result['trailer'] = $trailer;
                }
        	} else {
        	    $data = explode(' ', trim($data));
     
        		if (count($data) != 2) {
                	fseek($this->f, $o_pos);
            		$data = explode(' ', trim (_fgets ($this->f, true)));
     
            		if (count($data) != 2) {
            		    $this->error("Unexpected data in xref table");
            		}
    		    }
     
    		    $this->pdf_read_xref($result, null, (int) $data[0], (int) $data[0] + (int) $data[1]);
        	}
        }
     
     
        /**
         * Reads an Value
         *
         * @param object $c pdf_context
         * @param string $token a Token
         * @return mixed
         */
        function pdf_read_value(&$c, $token = null) {
        	if (is_null($token)) {
        	    $token = $this->pdf_read_token($c);
        	}
     
            if ($token === false) {
        	    return false;
        	}
     
           	switch ($token) {
                case	'<':
        			// This is a hex string.
        			// Read the value, then the terminator
     
                    $pos = $c->offset;
     
        			while(1) {
     
                        $match = strpos ($c->buffer, '>', $pos);
     
        				// If you can't find it, try
        				// reading more data from the stream
     
        				if ($match === false) {
        					if (!$c->increase_length()) {
        						return false;
        					} else {
                            	continue;
                        	}
        				}
     
        				$result = substr ($c->buffer, $c->offset, $match - $c->offset);
        				$c->offset = $match+1;
     
        				return array (PDF_TYPE_HEX, $result);
                    }
     
                    break;
        		case	'<<':
        			// This is a dictionary.
     
        			$result = array();
     
        			// Recurse into this function until we reach
        			// the end of the dictionary.
        			while (($key = $this->pdf_read_token($c)) !== '>>') {
        				if ($key === false) {
        					return false;
        				}
     
        				if (($value =   $this->pdf_read_value($c)) === false) {
        					return false;
        				}
                        $result[$key] = $value;
        			}
     
        			return array (PDF_TYPE_DICTIONARY, $result);
     
        		case	'[':
        			// This is an array.
     
        			$result = array();
     
        			// Recurse into this function until we reach
        			// the end of the array.
        			while (($token = $this->pdf_read_token($c)) !== ']') {
                        if ($token === false) {
        					return false;
        				}
     
        				if (($value = $this->pdf_read_value($c, $token)) === false) {
                            return false;
        				}
     
        				$result[] = $value;
        			}
     
                    return array (PDF_TYPE_ARRAY, $result);
     
        		case	'('		:
                    // This is a string
     
        			$pos = $c->offset;
     
        			while(1) {
     
                        // Start by finding the next closed
        				// parenthesis
     
        				$match = strpos ($c->buffer, ')', $pos);
     
        				// If you can't find it, try
        				// reading more data from the stream
     
        				if ($match === false) {
        					if (!$c->increase_length()) {
                                return false;
        					} else {
                                continue;
                            }
        				}
     
        				// Make sure that there is no backslash
        				// before the parenthesis. If there is,
        				// move on. Otherwise, return the string.
                        $esc = preg_match('/([\\\\]+)$/', $tmpresult = substr($c->buffer, $c->offset, $match - $c->offset), $m);
     
                        if ($esc === 0 || strlen($m[1]) % 2 == 0) {
        				    $result = $tmpresult;
                            $c->offset = $match + 1;
                            return array (PDF_TYPE_STRING, $result);
        				} else {
        					$pos = $match + 1;
     
        					if ($pos > $c->offset + $c->length) {
        						$c->increase_length();
        					}
        				}    				
                    }
     
                case "stream":
                	$o_pos = ftell($c->file)-strlen($c->buffer);
    		        $o_offset = $c->offset;
     
    		        $c->reset($startpos = $o_pos + $o_offset);
     
    		        $e = 0; // ensure line breaks in front of the stream
    		        if ($c->buffer[0] == chr(10) || $c->buffer[0] == chr(13))
    		        	$e++;
    		        if ($c->buffer[1] == chr(10) && $c->buffer[0] != chr(10))
    		        	$e++;
     
    		        if ($this->actual_obj[1][1]['/Length'][0] == PDF_TYPE_OBJREF) {
    		        	$tmp_c = new pdf_context($this->f);
    		        	$tmp_length = $this->pdf_resolve_object($tmp_c,$this->actual_obj[1][1]['/Length']);
    		        	$length = $tmp_length[1][1];
    		        } else {
    		        	$length = $this->actual_obj[1][1]['/Length'][1];	
    		        }
     
    		        if ($length > 0) {
        		        $c->reset($startpos+$e,$length);
        		        $v = $c->buffer;
    		        } else {
    		            $v = '';   
    		        }
    		        $c->reset($startpos+$e+$length+9); // 9 = strlen("endstream")
     
    		        return array(PDF_TYPE_STREAM, $v);
     
        		default	:
                	if (is_numeric ($token)) {
                        // A numeric token. Make sure that
        				// it is not part of something else.
        				if (($tok2 = $this->pdf_read_token ($c)) !== false) {
                            if (is_numeric ($tok2)) {
     
        						// Two numeric tokens in a row.
        						// In this case, we're probably in
        						// front of either an object reference
        						// or an object specification.
        						// Determine the case and return the data
        						if (($tok3 = $this->pdf_read_token ($c)) !== false) {
                                    switch ($tok3) {
        								case	'obj'	:
                                            return array (PDF_TYPE_OBJDEC, (int) $token, (int) $tok2);
        								case	'R'		:
        									return array (PDF_TYPE_OBJREF, (int) $token, (int) $tok2);
        							}
        							// If we get to this point, that numeric value up
        							// there was just a numeric value. Push the extra
        							// tokens back into the stack and return the value.
        							array_push ($c->stack, $tok3);
        						}
        					}
     
        					array_push ($c->stack, $tok2);
        				}
     
        				return array (PDF_TYPE_NUMERIC, $token);
        			} else {
     
                        // Just a token. Return it.
        				return array (PDF_TYPE_TOKEN, $token);
        			}
     
             }
        }
     
        /**
         * Resolve an object
         *
         * @param object $c pdf_context
         * @param array $obj_spec The object-data
         * @param boolean $encapsulate Must set to true, cause the parsing and fpdi use this method only without this para
         */
        function pdf_resolve_object(&$c, $obj_spec, $encapsulate = true) {
            // Exit if we get invalid data
        	if (!is_array($obj_spec)) {
                return false;
        	}
     
        	if ($obj_spec[0] == PDF_TYPE_OBJREF) {
     
        		// This is a reference, resolve it
        		if (isset($this->xref['xref'][$obj_spec[1]][$obj_spec[2]])) {
     
        			// Save current file position
        			// This is needed if you want to resolve
        			// references while you're reading another object
        			// (e.g.: if you need to determine the length
        			// of a stream)
     
        			$old_pos = ftell($c->file);
     
        			// Reposition the file pointer and
        			// load the object header.
     
        			$c->reset($this->xref['xref'][$obj_spec[1]][$obj_spec[2]]);
     
        			$header = $this->pdf_read_value($c,null,true);
     
        			if ($header[0] != PDF_TYPE_OBJDEC || $header[1] != $obj_spec[1] || $header[2] != $obj_spec[2]) {
        				$this->error("Unable to find object ({$obj_spec[1]}, {$obj_spec[2]}) at expected location");
        			}
     
        			// If we're being asked to store all the information
        			// about the object, we add the object ID and generation
        			// number for later use
    				$this->actual_obj =& $result;
        			if ($encapsulate) {
        				$result = array (
        					PDF_TYPE_OBJECT,
        					'obj' => $obj_spec[1],
        					'gen' => $obj_spec[2]
        				);
        			} else {
        				$result = array();
        			}
     
        			// Now simply read the object data until
        			// we encounter an end-of-object marker
        			while(1) {
                        $value = $this->pdf_read_value($c);
    					if ($value === false || count($result) > 4) {
    						// in this case the parser coudn't find an endobj so we break here
    						break;
        				}
     
        				if ($value[0] == PDF_TYPE_TOKEN && $value[1] === 'endobj') {
        					break;
        				}
     
                        $result[] = $value;
        			}
     
        			$c->reset($old_pos);
     
                    if (isset($result[2][0]) && $result[2][0] == PDF_TYPE_STREAM) {
                        $result[0] = PDF_TYPE_STREAM;
                    }
     
        			return $result;
        		}
        	} else {
        		return $obj_spec;
        	}
        }
     
     
     
        /**
         * Reads a token from the file
         *
         * @param object $c pdf_context
         * @return mixed
         */
        function pdf_read_token(&$c)
        {
        	// If there is a token available
        	// on the stack, pop it out and
        	// return it.
     
        	if (count($c->stack)) {
        		return array_pop($c->stack);
        	}
     
        	// Strip away any whitespace
     
        	do {
        		if (!$c->ensure_content()) {
        			return false;
        		}
        		$c->offset += _strspn($c->buffer, " \n\r\t", $c->offset);
        	} while ($c->offset >= $c->length - 1);
     
        	// Get the first character in the stream
     
        	$char = $c->buffer[$c->offset++];
     
        	switch ($char) {
     
        		case '['	:
        		case ']'	:
        		case '('	:
        		case ')'	:
     
        			// This is either an array or literal string
        			// delimiter, Return it
     
        			return $char;
     
        		case '<'	:
        		case '>'	:
     
        			// This could either be a hex string or
        			// dictionary delimiter. Determine the
        			// appropriate case and return the token
     
        			if ($c->buffer[$c->offset] == $char) {
        				if (!$c->ensure_content()) {
        				    return false;
        				}
        				$c->offset++;
        				return $char . $char;
        			} else {
        				return $char;
        			}
     
        		default		:
     
        			// This is "another" type of token (probably
        			// a dictionary entry or a numeric value)
        			// Find the end and return it.
     
        			if (!$c->ensure_content()) {
        				return false;
        			}
     
        			while(1) {
     
        				// Determine the length of the token
     
        				$pos = _strcspn($c->buffer, " []<>()\r\n\t/", $c->offset);
        				if ($c->offset + $pos <= $c->length - 1) {
        					break;
        				} else {
        					// If the script reaches this point,
        					// the token may span beyond the end
        					// of the current buffer. Therefore,
        					// we increase the size of the buffer
        					// and try again--just to be safe.
     
        					$c->increase_length();
        				}
        			}
     
        			$result = substr($c->buffer, $c->offset - 1, $pos + 1);
     
        			$c->offset += $pos;
        			return $result;
        	}
        }
     
     
    }
     
    ?>
    Voila, je n'en sais pas plus. Je tiens a souligner que je suis un novice avec ce framework...peut être qu'il n'aime pas tout ce qui touche au parsage d'un pdf ?

    J'utilise les dernieres versions stables de Apache et PHP.

    Merci d'avance pour vos réponses.

  2. #2
    Membre averti
    Homme Profil pro
    Inscrit en
    Février 2007
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 46
    Par défaut
    j'ai réussi a régler le problème...apparemment c une histoire d'url mal définie.

    Maintenant c'est un probleme d'encodage... FPDF ne gère pas l'utf8. et je ne peut pas utiliser UFPDF (une classe dérivée qui le gère), parce que je fais un 'new FPDI()'. J'ai essayé d'inclure UFPDF dans l'arborescence classe mere-fille, mais ça bug.

    Le souci, c'est que ça fait pareil que tout à l'heure : hors symfony, pas de souci, par contre avec symfony : probleme. J'ai des û©¨.

    Est ce qu'il s'agit d'un double encodage ?

  3. #3
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 505
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 505
    Par défaut
    bonjour,

    As-tu essayé utf8_decode et utf8_encode ?

Discussions similaires

  1. [fpdf][FPDI] Fichier protégé
    Par guigui69 dans le forum Bibliothèques et frameworks
    Réponses: 0
    Dernier message: 17/06/2013, 14h50
  2. [1.x] problème avec FPDF et symfony: failed to open stream
    Par flora806 dans le forum Symfony
    Réponses: 7
    Dernier message: 12/05/2011, 12h56
  3. [FPDF][FPDI] Problème concatenation
    Par yoyo33fc dans le forum Bibliothèques et frameworks
    Réponses: 0
    Dernier message: 17/12/2010, 10h15
  4. [FPDI] Fonctionne en local/pas en ligne: "FPDF error: Unexpected data in xref table"
    Par gobi13 dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 26/10/2007, 12h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo