2017-01-25 8 views
0

私は、pdfドキュメントに回答を送信するhtmlフォームを持っています。すべてうまくいっていますが、私はPDF文書に質問を載せたいと思います。FPDF挿入テキスト

現在、それはPDFファイルに次のようになります。

Jurgen 
Yes 
No 
4 
No 

私はそれがしたいと思います:

Name: Jurgen 
Do you own a vehicle? Yes 
etc 

(解決しよう)FPDFファイルの 私の現在のコード:

<?php 

class PDF extends FPDF 
{ 
// Page header 
function Header() 
{ 
    // Logo 
    $this->Image('images/logo.png', 10, 6, 30); 

    $this->SetFont('Arial', 'B', 15); 

    $this->Cell(50); 


    $this->Cell(90, 10, 'Document Title', 'C'); 
    // Line break 
    $this->Ln(20); 
} 

// Page footer 
function Footer() 
{ 

    $this->SetY(-15); 

    $this->SetFont('Arial', 'I', 8); 

    $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C'); 
} 
} 
?> 
<?php 
//set the question values 
$questions = array(
      'name' => "Name: ", 
      'date' => "Date: ", 
      'first' => "First Day of Leave: ", 
      'last' => "Last Day of Leave: ", 
      'days' => "Number of Days Taken: ", 
      'email' => "Managers Email: ", 
      'sig' => "Signed: ", 

     ); 
//set the question answers 
$date = $_POST['date']; 
$first = $_POST['first']; 
$last = $_POST['last']; 
$days = $_POST['days']; 
$email = $_POST['email']; 
$sig = $_POST['sig']; 
$name = $_POST['name']; 
//set the question names 
$questionName = $questions['name']; 
$questionDate = $questions['date']; 
$questionFirst = $questions['first']; 
$questionLast = $questions['last']; 
$questionDays = $questions['days']; 
$questionEmail = $questions['email']; 
$questionSig = $questions['sig']; 
//Create the PDF 

require('fpdf.php'); 

$pdf = new FPDF(); 
$pdf->AddPage(); 

$pdf->SetFont('Arial','B',16); 
//insert questions and answers 
$pdf->MultiCell(150,10,sprintf("%s %s", $questionDate, $date)); 
$pdf->Ln(); 
$pdf->MultiCell(150,10,sprintf("%s %s", $questionName, $name)); 
$pdf->Ln(); 
$pdf->MultiCell(150,10,sprintf("%s %s", $questionFirst, $first)); 
$pdf->Ln(); 
$pdf->MultiCell(150,10,sprintf("%s %s", $questionLast, $last)); 
$pdf->Ln(); 
$pdf->MultiCell(150,10,sprintf("%s %s", $questionDays, $days)); 
$pdf->Ln(); 
$pdf->MultiCell(150,10,sprintf("%s %s", $questionEmail, $email)); 
$pdf->Ln(); 
$pdf->MultiCell(50,10,sprintf("%s %s", $questionSig, $sig)); 
//display pdf 
$pdf->Output(); 

私はまだFPDFについて学んでいますが、そのドキュメントは最善ではないためです。私が間違いを犯した場合は、私に知らせてください。ありがとう

+0

があなたの投稿になります方法です私はyを与えることができるように完全なHTMLフォーム私はfpdfをたくさん使ってきました。 –

+0

@MasivuyeCokile私はこの問題をAnthonyBに分類しました。ありがとうございますが、私はページヘッダーの設定に問題があります。もし私にそれのための例を与えることができますか? – RedZ

+0

あなたはあなたのpdfファイルのヘッダーを意味しますか? –

答えて

0

これを行うには、キーがname属性と一致するような連想配列をHTML形式で使用します。

your_post.php

<form action="your_post.php" method="POST"> 
    <!-- Your first question about age --> 
    <label> 
     What's your name? 
     <input name="name" type="text" /> 
    </label> 
    <!-- Your second question --> 
    <label> 
     How old are you ? 
     <input name="yo" type="text" /> 
    </label> 
    <input type="submit" /> 
</form> 

form.html

私は、明示的な質問のお手伝いをすることはできませんが、私はまた、作成され、数日前にスクリプトを記述する必要がありました
<?php 
$questions = array(
       'name' => "What's your name?", 
       'yo' => 'How old are you?' 
      ); 
//Get you question and answer about name 
$name = $_POST['name']; 
$questionName = $questions['name']; 
//You can of course use a foreach through $_POST to get every question 

require('fpdf.php'); 

$pdf = new FPDF(); 
$pdf->AddPage(); 

$pdf->SetFont('Arial','B',16); 
//Here concatenate $questionName and $name 
$pdf->MultiCell(40,10,sprintf("%s %s", $questionName, $name)); 
$pdf->Output(); 
+0

私はこれを私のHTMLフォームでコード化しますか?現在のところ、Name: RedZ

+0

ありがとうございます。すべて^^ – RedZ

0

pdf 私はfpdfの代わりに使うことにしました。それは直接HTMLコードをpdfに変換します。 (あなたもそれにCSSをリンクすることができます)おそらくこれはあなたのためにも面白いことができます。 https://github.com/spipu/html2pdf

+0

本当にhtml2pdfはHTMLビューをPDFに直接変換するのに最適なツールです。それは簡単な方法です。しかしここでは彼自身がPDFを作成しようとしていますが、問題の問題は同じです。 – AnthonyB

0

これはヘッダを追加

<?php 
$pdf = new PDF(); 

$pdf->Cell(20, 10, 'Name : ' . $name . ''); 
$pdf->Ln(); 
$pdf->cell(20, 10, 'Do you own a vehicle? : ' . $question1); 
$pdf->Ln(); 
$pdf->Output(); 
?> 

を行う必要があり、あなたが

今すぐアップデートを

<?php 

class PDF extends FPDF 
{ 
    // Page header 
    function Header() 
    { 
     // Logo 
     $this->Image('images/logo.png', 10, 6, 30); 

     $this->SetFont('Arial', 'B', 15); 

     $this->Cell(50); 


     $this->Cell(90, 10, 'Document Title', 'C'); 
     // Line break 
     $this->Ln(20); 
    } 

    // Page footer 
    function Footer() 
    { 

     $this->SetY(-15); 

     $this->SetFont('Arial', 'I', 8); 

     $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C'); 
    } 
} 
?> 
が直面している問題は、これはあなたの最終的なコードが

<?php 
//set the question values 
$questions  = array(
    'name' => "Name: ", 
    'date' => "Date: ", 
    'first' => "First Day of Leave: ", 
    'last' => "Last Day of Leave: ", 
    'days' => "Number of Days Taken: ", 
    'email' => "Managers Email: ", 
    'sig' => "Signed: " 

); 
//set the question answers 
$date   = $_POST['date']; 
$first   = $_POST['first']; 
$last   = $_POST['last']; 
$days   = $_POST['days']; 
$email   = $_POST['email']; 
$sig   = $_POST['sig']; 
$name   = $_POST['name']; 
//set the question names 
$questionName = $questions['name']; 
$questionDate = $questions['date']; 
$questionFirst = $questions['first']; 
$questionLast = $questions['last']; 
$questionDays = $questions['days']; 
$questionEmail = $questions['email']; 
$questionSig = $questions['sig']; 
//Create the PDF 

require('fpdf.php'); 

class PDF extends FPDF 
{ 
    // Page header 
    function Header() 
    { 
     // Logo 
     $this->Image('images/logo.png', 10, 6, 30); 

     $this->SetFont('Arial', 'B', 15); 

     $this->Cell(50); 


     $this->Cell(90, 10, 'Document Title', 'C'); 
     // Line break 
     $this->Ln(20); 
    } 

    // Page footer 
    function Footer() 
    { 

     $this->SetY(-15); 

     $this->SetFont('Arial', 'I', 8); 

     $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C'); 
    } 
} 


$pdf = new FPDF(); 
$pdf->AddPage(); 

$pdf->SetFont('Arial', 'B', 16); 
//insert questions and answers 
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionDate, $date)); 
$pdf->Ln(); 
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionName, $name)); 
$pdf->Ln(); 
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionFirst, $first)); 
$pdf->Ln(); 
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionLast, $last)); 
$pdf->Ln(); 
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionDays, $days)); 
$pdf->Ln(); 
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionEmail, $email)); 
$pdf->Ln(); 
$pdf->MultiCell(50, 10, sprintf("%s %s", $questionSig, $sig)); 
//display pdf 
$pdf->Output(); 
+0

これを現在のコードの上に追加するだけですか?現在のコードの上に – RedZ

+0

があります。 –

+0

私にエラーがあります。 – RedZ

関連する問題