Cara membuat pdf dengan html dan php

Bismillah, Ada yg tau ga cara membuat html dan php saya menjadi pdf ini code nya

<?php
	require_once "core/koneksi.php";
	require_once 'core/paramx.php';
?>
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style>
	*{
		font-family: sans-serif;
		background-color: white;
	}
	.company{
		font-size: 15px;
		margin-left: 17px;
		margin-top: 25px;
		margin-bottom: 25px;
		font-weight: bold;
	}
	.name{
		text-align: center;
		margin-bottom:25px;
		font-size: 18px;
		font-weight: bold;
	}

	.period{
		margin-left: 17px;
	}

	.table-all{
		border: 1px;
		margin: 20px auto;
		border-collapse: collapse;
		margin-top: 50px;
	}

	.no{
		font-size: 12px;
    height:20px;
		width: 40px;
		border: 1px solid #3c3c3c;
		padding: 1px 8px;
	}
	.tablehead{
		font-size: 12px;
		height:20px;
		width: 120px;
		border: 1px solid #3c3c3c;
		padding: 1px 8px;
	}
	.total{
		font-size: 14px;
		font-weight: bold;
	  border: 0px;
	}
	table td{
		font-size: 13px;
		height:30px;
		border: 0px solid #3c3c3c;
		padding: 2px 8px;

	}
	a{
		background: blue;
		color: #fff;
		padding: 8px 10px;
		text-decoration: none;
		border-radius: 2px;
	}
	caption{
		font-size: 15px;
		font-weight: bold;
		text-align: left;
		margin-bottom: 17px;
	}
	</style>

</head>
<body>

<div class="company">
  	CV ABRINDO SEJAHTERA
</div>
		<div class="name">
				LAPORAN BUKU BESAR
		</div>
<div class="period">
	Periode : <?=$date_from?> s/d <?=$date_end?>
</div>

<?php
$no=1;
$temp = '';
$credittot = 0;
$tempOld = '1';
$saldoCount = 0;
$debittot  = $lihat['fcdebit'];
unset($_SESSION['temp']);
?>
<?php while($lihat = mysqli_fetch_assoc($result)){ ?>
<?php
		//Mengubah Stok Awal Menjadi 0
	 if ($lihat['ftDescription']  == 'Saldo Awal') {
	      $lihat['fcsaldo'] = 0;
	  }

	 $saldoCount = $saldoCount + $lihat['fcdebit'] - $lihat['fccredit'];
	 $debittot   = $debittot + $lihat['fcdebit'];
	 $temp = $lihat['ftcoa_code'];

?>
	<?php
	    if ($tempOld != $temp) {
	    if ($_SESSION['temp'] == 'true') {
	?>
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td class="total">TOTAL :</td>
		<td class="total"><?=rupiah($debittot)?></td>
		<td class="total"><?=rupiah($credittot)?></td>
		<td></td>
	</tr>
	<?php
		}
	}
	?>
	<?php if($temp != $tempOld) {
		$no=1;
		$saldoCount = $lihat['fcsaldo'];
		$debittot   = $lihat['fcdebit'];
		$credittot =  $lihat['fccredit'];
		$credittot  = $credittot - $credittot;
	?>
	<table class="table-all">
		<caption><?=$lihat['ftcoa_code']."-".$lihat['ftcoa_name']?></caption>
		<tr>
			<th class="no">No</th>
			<th class="tablehead">Tanggal</th>
			<th class="tablehead">No.Transaksi</th>
			<th class="tablehead">Keterangan</th>
			<th class="tablehead">Jumlah (Non IDR)</th>
			<th class="tablehead">Debit (IDR) </th>
			<th class="tablehead">Kredit (IDR)</th>
			<th class="tablehead">Saldo (IDR)</th>
		</tr>
	<?php
   }
 $tempOld = $temp;
 $_SESSION['temp'] = 'true';
 if ($lihat['ftDescription']  != 'Saldo Awal') {
	?>
			<tr>
			<td><?=$no?></td>
			<td><?=$lihat['fdtrans_date']?></td>
			<td><?=$lihat['ftdocument_no']?></td>
			<td><?=$lihat['ftDescription']?></td>
      <td></td>
      <td><?=rupiah($lihat['fcdebit'])?></td>
      <td><?=rupiah($lihat['fccredit'])?></td>
      <td><?=rupiah($saldoCount)?></td>
		</tr>
<?
  $credittot  = $credittot + $lihat['fccredit'];
  }
$no++;
?>
<?php } ?>
	</table>
</body>
</html>

avatar abubakar
@abubakar

72 Kontribusi 19 Poin

Diperbarui 4 tahun yang lalu

1 Jawaban:

<a href=' https://github.com/dompdf/dompdf '>DomPDF</a>

avatar driyan
@driyan

193 Kontribusi 109 Poin

Dipost 4 tahun yang lalu

Tanggapan

codenya error, karna sy bercampur format php sy sudah coba

dipisah gan, terus make loadHTMLFile

boleh minta contoh nya ga contoh kodenya supaya saya faham

Looping tabel nya di masukin dalam loadHTML gan, jadi agan buat satu fungsi untuk convert HTML ke PDF, looping tabel nya agan buatkan variabel, misalnya $output. Variabel ini diinput dalam $dompdf->loadHtml($output);

Login untuk ikut Jawaban