TCPDF未通过jQuery捕获PHP变量
我通过jQuery将用户数据发送到TCPDF,但它不会在PDF文件中显示从jQuery接收到的任何值 我甚至尝试在会话变量中捕获该值,但它仍然没有显示。我哪里做错了 HTML: TCPDF.php:TCPDF未通过jQuery捕获PHP变量,php,jquery,variables,pdf,tcpdf,Php,Jquery,Variables,Pdf,Tcpdf,我通过jQuery将用户数据发送到TCPDF,但它不会在PDF文件中显示从jQuery接收到的任何值 我甚至尝试在会话变量中捕获该值,但它仍然没有显示。我哪里做错了 HTML: TCPDF.php: <?php session_start(); //============================================================+ // Author: Nicola Asuni // // (c) Copyright: //
<?php
session_start();
//============================================================+
// Author: Nicola Asuni
//
// (c) Copyright:
// Nicola Asuni
// Tecnick.com s.r.l.
// Via Della Pace, 11
// 09044 Quartucciu (CA)
// ITALY
// www.tecnick.com
// info@tecnick.com
//============================================================+
/**
* @author Nicola Asuni
* @since 2009-03-20
*/
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'B', 8);
$this->SetTextColor(247, 147, 29);
$this->Cell(0, 10, 'ABC', 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('ABC');
$pdf->SetTitle('ABC');
$pdf->SetSubject('ABC');
$pdf->SetKeywords('ABC');
// set default header data
$pdf->SetHeaderData(false);
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, 5, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// add a page
$pdf->AddPage();
$pdf->SetFont('helvetica', '', 8);
// -----------------------------------------------------------------------------
//request parameters
$nop = strip_tags($_POST['nop']);
$_SESSION['nop'] = $nop;
$nop = $_SESSION['nop'];
$as = strip_tags($_POST['as']);
$las = strip_tags($_POST['las']);
$bo = strip_tags($_POST['bo']);
$lbo = strip_tags($_POST['lbo']);
$mca = strip_tags($_POST['mca']);
$lmca = strip_tags($_POST['lmca']);
$tbl = <<<EOF
<div>
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td>FOO</td>
<td>$nop</td>
</tr>
</tbody>
</table>
</div>
<hr>
<div>
<table border="0" cellpadding="5" cellspacing="2">
<thead>
<tr>
<th><h3>ABC</h3></th>
<th><h3>PQR</h3></th>
<th><h3>XYS</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td>Staff</td>
<td>$as</td>
<td>$las</td>
</tr>
<tr>
<td>Office</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Administrative</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
EOF;
$pdf->writeHTML($tbl, true, false, false, false, '');
$txt = $nop . 'This';
// print a block of text using Write()
$pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
// -----------------------------------------------------------------------------
//Close and output PDF document
$pdf->Output('ABC.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
试试看
打印(邮政美元)
然后把它放在php文件的开头,在那里构建pdf。
这有助于您了解哪些值到达了,哪些值没有您正在调用pdf.php两次,一次使用post数据,另一次不使用
$.ajax({ // call 1, with post data
type: "POST",
url: "pdf.php",
data: postData,
success: function(data){
window.open("pdf.php"); // call 2, without post data
}
});
您可以做的是删除ajax请求,并通过GET发送数据,而不是使用
var getString = "nop=" + nop "&as=" + as; // .....
window.open("pdf.php?" + getString);
我甚至尝试在会话变量中捕获该值,但它仍然没有显示。我哪里做错了
它应该会起作用。您是否错过了会话\u start()
另一种方法是在ajax请求和输出文件名中生成PDF,您可以使用window.open()
打开该文件,谢谢您的帮助。这起作用了。我只是想知道我是否可以在url字符串中隐藏参数?@input不,对不起,不能用get。取决于要隐藏的原因,但查看发送到的post值很容易
$.ajax({ // call 1, with post data
type: "POST",
url: "pdf.php",
data: postData,
success: function(data){
window.open("pdf.php"); // call 2, without post data
}
});
var getString = "nop=" + nop "&as=" + as; // .....
window.open("pdf.php?" + getString);