Просмотр полной версии : Как передать данные в FPDF (PDF)
Вообщем скачал библиотеку которая создает 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 но не как..
FireFenix
16.07.2009, 21:44
$pdf->Cell(40,10, $text); //Без кавычек
Ура Ура Ура.
А ты не посдкажеш как сделать что бы было Сохронить как а не просто открывался документ PDF ?
FireFenix
16.07.2009, 22:25
Ну блин, ты хоть до конца документацию дочитай, а?
$pdf->Output('file.pdf','I');
//"I"-параметр выведет результат в браузер.
$pdf->Output('file.pdf','D');
//"D" - В этом случае браузер предложит сохранить данный файл.
Нк рапотает..
Вот сам 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>
Во туплю.. )) убрал 1 оутпут все работает !!!! Спасибо !!!!!!!!!!!!!!!!!!!!!!!!!!!! Огромноеее
Непонял это как ?
Вы должны добавить репутацию кому-то еще, прежде чем сможете снова добавить ее FireFenix.
Почему так ?
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 заполненных полей тогда ?
FireFenix
16.07.2009, 23:49
ээх.... чтоли сюда скопировать весь мануал?
Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])
Description
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.
Parameters
w
Cell width. If 0, the cell extends up to the right margin.
h
Cell height. Default value: 0.
txt
String to print. Default value: empty string.
border
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.
ln
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.
align
Allows to center or align the text. Possible values are:
L or empty string: left align (default value)
C: center
R: right align
fill
Indicates if the cell background must be painted (true) or transparent (false). Default value: false.
link
URL or identifier returned by AddLink().
© http://www.fpdf.org/en/doc/index.php
В твоём коде получается что ты задаёшь параметр границы через запятую
$pdf->Cell(40,10,$bobo,$name);
Если ты хочешь вывести текст как продолжение существующего, то тебе нужно вместо запятой - использовать точку (конкатенация строк)
$pdf->Cell(40, 10, $bobo . $name);
Если тебе нужна отдельная строка - задавай ещё одну строку через Cell
$pdf->SetXY(50, 50);
$pdf->Cell(40, 10, $bobo);
$pdf->SetXY(50, 70);
$pdf->Cell(40, 10, $name);
И почитай на русском http://habrahabr.ru/blogs/php/31438/
Спасибо.
Только не как не пойму как выстроить все в значение Вот так.
Telefon : 3333333333
Name : Broken
Lastname : Wolf
т.е саму расстановку я такую сделал только они у меня все криво вылетают в документе
Вот
<?php
require('fpdf.php');
//22222222222222222222222222222222222222222222222222 222222222222
$names="Nome : ";
$address="Indirizzo : ";
$phone="Telefono : ";
$mail="Email : ";
//22222222222222222222222222222222222222222222222222 222222222222
$name=$_POST['name'];
$indirizzo=$_POST['indirizzo'];
$tel=$_POST['tel'];
$email=$_POST['email'];
//22222222222222222222222222222222222222222222222222 222222222222
$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 нормально .
Не могу понять с этими SetXY пытюсь настроить строку где телефон но она все равно в права улетает.. незнаю что я не так делаю..
FireFenix
17.07.2009, 12:20
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.
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.
Да я мануал и на русском нашол только все равно не пойму как выстроить Строчку телефон в лево как и все остальные..
Улетает она у меня в право кудато...
Щас муду мучаться обратно тыкать XY и меня координаты как вчера но я так и не смог поставить ее в лево.. может сам код неправильно написан ?
Все решено ! Спасибо FireFenix
vBulletin® v3.8.14, Copyright ©2000-2026, vBulletin Solutions, Inc. Перевод: zCarot