I have two html pages which are converted to pdf. Now I have a pdf file and I want to add it between the two converted html pages .
I have tried converting the pdf to html but the tcpdf doesn't support this conversion of css and js.
Please help me.
I have two html pages which are converted to pdf. Now I have a pdf file and I want to add it between the two converted html pages .
I have tried converting the pdf to html but the tcpdf doesn't support this conversion of css and js.
Please help me.
use setasign\Fpdi;
require_once('tcpdf_include.php');
require_once('../FPDI/src/autoload.php');
// Original file with multiple pages
$fullPathToFile = '../sample.pdf';
class Pdf extends Fpdi\TcpdfFpdi{
var $_tplIdx;
}
$pdf = new pdf('P', 'px', 'A4', true, 'UTF-8', false);
$page1='<table cellpadding="5" cellspacing="2" style="font-size:11px;font-family:Arial;">
</table>';
$pdf->writeHTMLCell($colWidth,300,$margin,$pagetopmargin,$page1);
$page2='';
$pdf->AddPage();
//$pdf->writeHTMLCell(235,232,495,10,$manageLogo);
$pdf->writeHTMLCell($colWidth,300,$margin,$pagetopmargin,$page2);
// THIS IS WHERE YOU GET THE NUMBER OF PAGES
$pdf -> setSourceFile('../sample.pdf');
$temp =$pdf->importPage(1);
$pdf->AddPage();
$pdf->useTemplate($temp);
$pdf->SetMargins(30, 60, 50, true);
$pdf -> setSourceFile('../sample.pdf');
$temp =$pdf->importPage(2);
$pdf->AddPage();
$pdf->useTemplate($temp ,-4, 30);
$page3=' <h4>Ongoing Rent Payments</h4>
<p>Our preferred payment method for rent is Rental Rewards. (Please note that there is a small convenience fee charged for the use of the system. These fees are charged by a third-party payment processor – Rental Rewards</p> <p>The fees for the convenience of the use of the services are: (must be able to set-up fee at agent level, as there is variation)</p> <ol type="a" style="margin-left: 20px;">';
$pdf->AddPage();
$pdf->writeHTMLCell($colWidth,300,$margin,$pagetopmargin-20,$page3);
ob_end_clean();
$pdf->Output('tenancy_application.pdf');
PDF needs a pdf reader program installed, so embedding in html is limited by browser/OS support. Normally you can open a pdf file in a browser tab, so opening in an iframe might also work (not tested).
<iframe src="link to pdf"></iframe>
To embed the PDF within the page you could use pdf.js from Mozilla. This would allow you to use a JavaScript snippet to pull in and render your PDF like so:
// If absolute URL from remote server is provided, configure CORS header on that server.
var url = '//cdn.mozilla.net/pdfjs/helloworld.pdf';
PDFJS.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
// Asynchronous download of PDF
var loadingTask = PDFJS.getDocument(url);
loadingTask.promise.then(function(pdf) {
// Fetch the first page
var pageNumber = 1;
pdf.getPage(pageNumber).then(function(page) {
// Set scale
var scale = 1.5;
var viewport = page.getViewport(scale);
// Prepare canvas using PDF page dimensions
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context
var renderContext = {
canvasContext: context,
viewport: viewport
};
var renderTask = page.render(renderContext);
});
}, function (reason) {
console.error(reason);
});
If you wanted to process your PDF upfront, rather than waiting until runtime you could convert it into HTML first by using a file conversion API such as Zamzar. You could use the API to programatically convert from PDF to HMTL (from PHP) and then use that inline.