here im passing php variable instead of pdf file path as said in URL
Using a pdf from a php variable instead of a file | FAQ: Miscellaneous | Setasign[
^] but it it shows some fetal error described below
fetal error:Uncaught exception 'InvalidArgumentException' with message 'Cannot open VarStream://0 !' in C:\xampp\htdocs\VB\FPDI\pdf_parser.php:183 Stack trace: #0 C:\xampp\htdocs\VB\FPDI\fpdi_pdf_parser.php(64): pdf_parser->__construct('VarStream://0') #1 C:\xampp\htdocs\VB\FPDI\fpdi.php(135): fpdi_pdf_parser->__construct('VarStream://0') #2 C:\xampp\htdocs\VB\FPDI\fpdi.php(106): FPDI->_getPdfParser('VarStream://0') #3 C:\xampp\htdocs\VB\mlpdf.php(133): FPDI->setSourceFile('VarStream://0') #4 C:\xampp\htdocs\VB\TCPDF\tcpdf.php(3537): PDF->Header() #5 C:\xampp\htdocs\VB\TCPDF\tcpdf.php(3204): TCPDF->setHeader() #6 C:\xampp\htdocs\VB\TCPDF\tcpdf.php(3116): TCPDF->startPage('', '', false) #7 [internal function]: TCPDF->AddPage() #8 C:\xampp\htdocs\VB\FPDI\fpdf_tpl.php(360): call_user_func_array(Array, Array) #9 C:\xampp\htdocs\VB\mlpdf.php(167): FPDF_TPL->AddPage() #10 {main} thrown in C:\xampp\htdocs\VB\FPDI\pdf_parser.php on line 183
where mlpdf.php is file name
What I have tried:
<?php
require_once('tcpdf/tcpdf.php');
require_once('fpdi/fpdi.php');
$collcode=15485;
$serverName = "KUDK126";
$connectionInfo = array( "Database"=>"qp");
$objConnect = sqlsrv_connect( $serverName, $connectionInfo);
$id=10;
$strSQL = "SELECT * FROM files WHERE FilesID = $id ";
$objQuery = sqlsrv_query($objConnect,$strSQL) or die ("Error Query [".$strSQL."]");
$objResult = sqlsrv_fetch_array($objQuery);
class VarStream extends FPDI{
private $_pos;
private $_stream;
private $_cDataIdx;
static protected $_data = array();
static protected $_dataIdx = 0;
static function createReference(&$var) {
$idx = self::$_dataIdx++;
self::$_data[$idx] =& $var;
return __CLASS__.'://'.$idx;
}
static function unsetReference($path) {
$url = parse_url($path);
$cDataIdx = $url["host"];
if (!isset(self::$_data[$cDataIdx]))
return false;
unset(self::$_data[$cDataIdx]);
return true;
}
public function stream_open($path, $mode, $options, &$opened_path) {
$url = parse_url($path);
$cDataIdx = $url["host"];
if (!isset(self::$_data[$cDataIdx]))
return false;
$this->_stream = &self::$_data[$cDataIdx];
$this->_pos = 0;
if (!is_string($this->_stream)) return false;
$this->_cDataIdx = $cDataIdx;
return true;
}
public function stream_read($count) {
$ret = substr($this->_stream, $this->_pos, $count);
$this->_pos += strlen($ret);
return $ret;
}
public function stream_write($data) {
$l=strlen($data);
$this->_stream =
substr($this->_stream, 0, $this->_pos) .
$data .
substr($this->_stream, $this->_pos += $l);
return $l;
}
public function stream_tell() {
return $this->_pos;
}
public function stream_eof() {
return $this->_pos >= strlen($this->_stream);
}
public function stream_seek($offset, $whence) {
$l=strlen($this->_stream);
switch ($whence) {
case SEEK_SET: $newPos = $offset; break;
case SEEK_CUR: $newPos = $this->_pos + $offset; break;
case SEEK_END: $newPos = $l + $offset; break;
default: return false;
}
$ret = ($newPos >= 0 && $newPos <= $l);
if ($ret) $this->_pos=$newPos;
return $ret;
}
public function url_stat($path, $flags) {
$url = parse_url($path);
$dataIdx = $url["host"];
if (!isset(self::$_data[$dataIdx]))
return false;
$size = strlen(self::$_data[$dataIdx]);
return array(
7 => $size,
'size' => $size
);
}
public function stream_stat() {
$size = strlen($this->_stream);
return array(
'size' => $size,
7 => $size,
);
}
}
class PDF extends VarStream {
var $_tplIdx;
function Header() {
stream_wrapper_register('VarStream', 'VarStream') or die('Failed to register protocol VarStream://');
if (is_null($this->_tplIdx)) {
$this->numPages = $this->setSourceFile(VarStream::createReference($objResult["FilesName"]));
$this->_tplIdx = $this->importPage(1);
}
$this->useTemplate($this->_tplIdx);
}
function Footer() {}
}
$pdf = new PDF();
$pdf->setFontSubsetting(true);
$style = array(
'position' => '',
'align' => 'C',
'stretch' => false,
'fitwidth' => true,
'cellfitalign' => '',
'border' => false,
'hpadding' => 'auto',
'vpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false,
'text' => true,
'font' => 'helvetica',
'fontsize' => 8,
'stretchtext' => 4
);
$pdf->AddPage();
$pdf->write1DBarcode('15748', 'C128', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln();
$pdf->StartTransform();
$pdf->Rotate(40, 50, 110);
$pdf->SetFont("times", "B", 70);
$pdf->SetAlpha(0.3);
$pdf->Text(20,150,'Raghu');
$pdf->StopTransform();
if($pdf->numPages>1) {
for($i=2;$i<=$pdf->numPages;$i++) {
$pdf->endPage();
$pdf->_tplIdx = $pdf->importPage($i);
$pdf->AddPage();
$pdf->write1DBarcode('15748', 'C128', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln();
$pdf->StartTransform();
$pdf->Rotate(40, 50, 110);
$pdf->SetFont("times", "B", 70);
$pdf->SetAlpha(0.3);
$pdf->Text(20,150,'Raghu');
$pdf->StopTransform();
}
}
$pdf->Output();
?>