Как передать данные в FPDF (PDF)

Discussion in 'PHP' started by Adio, 16 Jul 2009.

  1. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Вообщем скачал библиотеку которая создает PDF с помощью PHP.

    Вот Минимальный код Hello Word

    <?php
    require('fpdf.php');

    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();
    ?>


    Я создаю отдельную страничку к примеру form.html

    пишу форму.

    в место Hello Word пишу $text но почемуто создаеться PDF не с текстом который я отправил а так $text...
    т.е он переменную не читает..

    Как быть ? я хочу передать из форму текст в PDF но не как..
     
  2. FireFenix

    FireFenix Elder - Старейшина

    Joined:
    3 Jun 2009
    Messages:
    390
    Likes Received:
    115
    Reputations:
    23
    PHP:
    $pdf->Cell(40,10$text); //Без кавычек
     
  3. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Ура Ура Ура.

    А ты не посдкажеш как сделать что бы было Сохронить как а не просто открывался документ PDF ?
     
  4. FireFenix

    FireFenix Elder - Старейшина

    Joined:
    3 Jun 2009
    Messages:
    390
    Likes Received:
    115
    Reputations:
    23
    Ну блин, ты хоть до конца документацию дочитай, а?
    PHP:
    $pdf->Output('file.pdf','I');
    //"I"-параметр выведет результат в браузер.

    $pdf->Output('file.pdf','D');
    //"D" - В этом случае браузер предложит сохранить данный файл.
     
  5. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Нк рапотает..


    Вот сам PHP


    <?php
    require('fpdf.php');
    $text=$_POST['text'];
    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10, $text);
    $pdf->Output();





    $pdf->Output('file.pdf','D');
    //"D" - В этом случае браузер предложит сохранить данный файл.
    ?>



    А вот send html


    <form action="hello.php" method="post">
    <input type="text" name="text">
    <input type="submit" value="Send">
    </form>
     
  6. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Во туплю.. )) убрал 1 оутпут все работает !!!! Спасибо !!!!!!!!!!!!!!!!!!!!!!!!!!!! Огромноеее
     
  7. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Непонял это как ?


    Вы должны добавить репутацию кому-то еще, прежде чем сможете снова добавить ее FireFenix.
     
  8. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Почему так ?

    send.html

    <form action="hello.php" method="post">
    Nome / Cognome :<input type="text" name="name"><br>
    Indirizzo :<input type="text" name="bobo"><br>
    <input type="submit" value="Send"><br>
    </form>


    hello.php


    <?php
    require('fpdf.php');
    $bobo=$_POST['bobo'];
    $name=$_POST['nome'];
    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,$bobo,$name);
    $pdf->Output('file.pdf','D');
    //"D" - В этом случае браузер предложит сохранить данный файл.
    ?>

    Почему мне только записывает переменную $bobo ? т.е может записать только 1 переменную в файл ? то как мне записать 20 заполненных полей тогда ?
     
  9. FireFenix

    FireFenix Elder - Старейшина

    Joined:
    3 Jun 2009
    Messages:
    390
    Likes Received:
    115
    Reputations:
    23
    ээх.... чтоли сюда скопировать весь мануал?
    Code:
    Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]]) 
    [B]Description[/B]
    Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text. 
    If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting. 
    [B]Parameters[/B]
    [B]w[/B]
    Cell width. If 0, the cell extends up to the right margin. 
    [B]h[/B]
    Cell height. Default value: 0. 
    [B]txt[/B]
    String to print. Default value: empty string. 
    [B]border[/B]
    Indicates if borders must be drawn around the cell. The value can be either a number: 
    0: no border
    1: frame
    or a string containing some or all of the following characters (in any order): 
    L: left
    T: top
    R: right
    B: bottom
    Default value: 0. 
    [B]ln[/B]
    Indicates where the current position should go after the call. Possible values are: 
    0: to the right
    1: to the beginning of the next line
    2: below
    Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0. 
    [B]align[/B]
    Allows to center or align the text. Possible values are: 
    L or empty string: left align (default value)
    C: center
    R: right align
    [B]fill[/B]
    Indicates if the cell background must be painted (true) or transparent (false). Default value: false. 
    [B]link[/B]
    URL or identifier returned by AddLink().
    
    © http://www.fpdf.org/en/doc/index.php

    В твоём коде получается что ты задаёшь параметр границы через запятую
    Code:
    $pdf->Cell(40,10,$bobo,$name);
    
    Если ты хочешь вывести текст как продолжение существующего, то тебе нужно вместо запятой - использовать точку (конкатенация строк)
    Code:
    $pdf->Cell(40, 10, $bobo . $name);
    
    Если тебе нужна отдельная строка - задавай ещё одну строку через Cell
    Code:
    $pdf->SetXY(50, 50);
    $pdf->Cell(40, 10, $bobo);
    $pdf->SetXY(50, 70);
    $pdf->Cell(40, 10, $name);
    
    И почитай на русском http://habrahabr.ru/blogs/php/31438/
     
    #9 FireFenix, 16 Jul 2009
    Last edited: 16 Jul 2009
  10. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Спасибо.
    Только не как не пойму как выстроить все в значение Вот так.

    Telefon : 3333333333
    Name : Broken
    Lastname : Wolf


    т.е саму расстановку я такую сделал только они у меня все криво вылетают в документе

    Вот




    <?php
    require('fpdf.php');
    //22222222222222222222222222222222222222222222222222222222222222
    $names="Nome : ";
    $address="Indirizzo : ";
    $phone="Telefono : ";
    $mail="Email : ";
    //22222222222222222222222222222222222222222222222222222222222222
    $name=$_POST['name'];
    $indirizzo=$_POST['indirizzo'];
    $tel=$_POST['tel'];
    $email=$_POST['email'];
    //22222222222222222222222222222222222222222222222222222222222222
    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->SetXY(50,50);
    $pdf->Cell(40, 10, $names . $name);
    $pdf->SetXY(50,70);
    $pdf->Cell(40, 10, $address . $indirizzo);


    $pdf->Cell(10, 20, $phone . $tel);
    $pdf->SetXY(50,100);
    $pdf->Cell(10, 20, $mail . $email);
    $pdf->Output('file.pdf','D');
    //"D" - В этом случае браузер предложит сохранить данный файл.




    ?>



    Вот там где выводиться телефон его кудато в право перекосило саму строчку а Email нормально .
     
  11. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Не могу понять с этими SetXY пытюсь настроить строку где телефон но она все равно в права улетает.. незнаю что я не так делаю..
     
  12. FireFenix

    FireFenix Elder - Старейшина

    Joined:
    3 Jun 2009
    Messages:
    390
    Likes Received:
    115
    Reputations:
    23
    SetXY(float x, float y)
    Description
    Defines the abscissa and ordinate of the current position. If the passed values are negative, they are relative respectively to the right and bottom of the page.
     
  13. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Да я мануал и на русском нашол только все равно не пойму как выстроить Строчку телефон в лево как и все остальные..

    Улетает она у меня в право кудато...

    Щас муду мучаться обратно тыкать XY и меня координаты как вчера но я так и не смог поставить ее в лево.. может сам код неправильно написан ?
     
  14. Adio

    Adio Elder - Старейшина

    Joined:
    23 May 2005
    Messages:
    1,646
    Likes Received:
    147
    Reputations:
    18
    Все решено ! Спасибо FireFenix