よくわかりません。
MPDFで html ページをエクスポートしてみます。私は例を見て、それを使用する方法は次のようになります:
<?php
$html = '
<h1><a name="top"></a>mPDF</h1>
<p>P: Nulla felis erat, imperdiet eu, ullamcorper non, nonummy quis, elit. Suspendisse potenti. Ut a eros at ligula vehicula pretium. Maecenas feugiat pede vel risus. Nulla et lectus. </p>';
include("../mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>
したがって、html コードを変数に入れる必要があり、mpdf クラスが pdf ファイルを生成します。
私はこのような問題を抱えています:
ユーザーからフォームが送信された後、php で動的に生成されたページを印刷したいと考えています。レポートページです。ユーザーが希望する特定の期間を選択すると、ページにレポートが表示されます。
したがって、ユーザーがフォームを送信した後、生成された html コードを取得する必要があります。私はob_get_contents()
これを行ってから、上記のmpdfスクリプトを持つphpページ、たとえばpdf.phpにフォームを送信するために使用しています。
ここにpdf.phpの私のコード:
<?php
include("../mpdf.php");
$mpdf=new mPDF();
$htmlx = "$_POST[htmlx]";
$mpdf->WriteHTML($htmlx);
$mpdf->Output();
exit;
?>
PDFが作成されましたが、本来のように正しく表示されません(作成されたPDFはHTMLページを正しく表示しません)。
生成された html コードが間違っていて、mpdf が html コードを理解していない可能性があると思います。だから私はこのように試します:
生成された html コードをコピーして、上記の例のように php ページを作成しようとしました。生成された pdf はページを正しく表示します。
なぜこれが起こるのか理解できません。たぶん、php のフォームから html コードを送信できませんか?
私の悪い英語で申し訳ありません。あなたが私の問題を理解し、解決できることを願っています。ありがとうございました。
編集:
ここにHTMLコードを送信するための私のフォーム:
<?php
$html = ob_get_contents();
$html = str_replace('"','\"',$html);
?>
<form action="pdf.php" method="POST" enctype="multipart/form-data">
<input type="submit" value="Print to PDF">
<textarea name="htmlx" style="display:; width: 100%; height:300px;" readonly><?= $html ?></textarea>
</form>
編集
これは私の生成されたhtmlの例です:
<style>
*{
font-family: arial;
}
body{
background: #fff;
}
table#myTable{
border:solid 7px #eee;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
-khtml-border-radius: 7px;
border-radius: 7px;
behavior: url(/files/border-radius.htc);
}
#myTable th{
font: normal 11pt 'century gothic';
cursor:pointer;
background: #ccc;
padding: 8px 15px 8px 15px;
color:#000
}
#myTable th.header {
padding: 8px 15px 8px 15px;
background: #eee;
cursor: pointer;
font-weight: bold;
background-repeat: no-repeat;
background-position: center right;
padding-right: 20px;
margin-left: -1px;
color:#fff
}
#myTable th.headerSortUp {
background-image: url(/template/default/images/asc.gif);
background-color: #eee;
color:#fff
}
#myTable th.headerSortDown {
background-image: url(/template/default/images/desc.gif);
background-color: #eee;
color:#fff
}
#myTable tr {
border:solid 1px #3e6189;
}
#myTable td {
background:#f9f9f9;
padding: 8px 15px 8px 15px;
border:solid 1px #f0f0f0;
font-size: 9pt
}
@media print
{
.blabla{
display:none;
}
}
</style>
</head>
<body>
<script>
function printPage() { print(); }
</script>
<table cellpadding="3" cellspacing="1" border="0" width="100%" id="myTable">
<tr class="bgTransUng25">
<th width="5">No</th>
<th width="70">Pembelian</th>
<th width="100">Oleh</th>
<th width="70">Tanggal</th>
<th width="">Detail Pembelian</th>
<th width="70">Paket Pengiriman</th>
</tr>
<tr class="bgTransWht71" align="center">
<td align="right">1.</td>
<td>00122</td>
<td>Iko Uwais</td>
<td align="right">2 Jul 2012</td>
<td>
<table cellpadding="3" cellspacing="1" border="0" width="100%">
<tr class="bgTransWht25" align="center">
<td align="left">Kaos BW 9500 003</td>
<td align="right" width="70">3 pcs</td>
<td width="100"><div style="text-align:left">Rp.<div style="float:right; text-align:right">285.000</div></div></td>
</tr>
<tr class="bgTransWht25" align="center">
<td align="left">Kaos BW 9500 003</td>
<td align="right" width="70">7 pcs</td>
<td width="100"><div style="text-align:left">Rp.<div style="float:right; text-align:right">665.000</div></div></td>
</tr>
<tr class="bgTransWht25" align="center">
//and so on...