I am using FPDF/FPDI to merge a PDF from database with an image as a header of the PDF. Searching for solution but no solution found yet so I post it here.
Here is my viewpdf.php code:
<?php
session_start();
require"../system/sistem.php";
dbConnect();
//take data gambar
$result13 = mysqli_query($dbconn,"SELECT * FROM gambar WHERE id_gambar=".$_SESSION['id_gambar']."" ) or error( mysqli_error() );
$show13=mysqli_fetch_assoc($result13);
$id_gambar = $show13['id_gambar'];
$tipe_gambar = $show13['tipe_gambar'];
$ukuran_gambar = $show13['ukuran_gambar'];
$gambar = base64_decode($show13['gambar']);
$nama_gambar = $show13['nama_gambar'];
use setasign\Fpdi\Fpdi;
require('rotation.php');
require_once('src/autoload.php');
class PDF extends PDF_Rotate
{
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
}
function RotatedText($x, $y, $txt, $angle)
{
//Text rotated around its origin
$this->Rotate($angle,$x,$y);
$this->Text($x,$y,$txt);
$this->Rotate(0);
}
}
//echo $gambar;
$pdf=new PDF();
$pdf = new FPDI();
$pdf->AddPage();
$pdf->SetFont('Arial','',12);
//$pdf->setSourceFile('document.pdf');
$pdf->setSourceFile('$gambar');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx);
$pdf->SetFont('Arial','I',8);
$pdf->SetTextColor(25,192,203);
$pdf->SetY(264);
$pdf->Write(10,'Approved by YONATAN R.CHRISTIAN','http://athena.wgo-nigeria.com/');
$pdf->Output();
?>
It doesn't load the PDF from the database. and can't see text watermark.
This is view error:
Warning: fopen($gambar): failed to open stream: No such file or directory in C:\xampp\htdocs\approval\blob\src\PdfParser\StreamReader.php on line 43
Fatal error: Uncaught InvalidArgumentException: No stream given. in C:\xampp\htdocs\approval\blob\src\PdfParser\StreamReader.php:105 Stack trace: #0 C:\xampp\htdocs\approval\blob\src\PdfParser\StreamReader.php(44): setasign\Fpdi\PdfParser\StreamReader->__construct(false, true) #1 C:\xampp\htdocs\approval\blob\src\FpdiTrait.php(172): setasign\Fpdi\PdfParser\StreamReader::createByFile('$gambar') #2 C:\xampp\htdocs\approval\blob\src\FpdiTrait.php(211): setasign\Fpdi\Fpdi->getPdfReaderId('$gambar') #3 C:\xampp\htdocs\approval\blob\watermark.php(50): setasign\Fpdi\Fpdi->setSourceFile('$gambar') #4 {main} thrown in C:\xampp\htdocs\approval\blob\src\PdfParser\StreamReader.php on line 105