I want to display .pdf file content in my php website. I already tried with a simple code like this:
#[Route('/pdf', name: 'app_pdf')]
public function pdfAction()
{
$path = $this->getParameter('kernel.project_dir').'\public\build\images\tracemonkey.pdf';
$response = new BinaryFileResponse($path);
$response->headers->set('Content-Type', 'application/pdf');
$response->setContentDisposition(
ResponseHeaderBag::DISPOSITION_INLINE,
'tracemonkey.pdf'
);
return $response;
}
Its working fine but it showing me the pdf in browser so my question is: It is possible to know how to display a pdf not in the browser but in an html tag? (Here in my p.pdf)
How to read pdf file in my p.pdf ?
.container-news {
width: 100%;
background-color: white;
}
.container-news .news-header {
width: 100%;
margin: 15px auto;
text-align: left;
border-bottom: 1px solid red;
}
.container-news .news-header h1 {
font-size: 1.5rem;
margin: 0;
}
.container-news .news-body {
width: 100%;
display: flex;
justify-content: space-between;
}
.container-news .news-body .news-card {
width: 25%;
background-color: #f7f7f7;
margin: 5px 0;
padding: 5px;
}
.container-news .news-body .news-card .news-title h2 {
text-align: center;
font-size: 1.3rem;
margin: 0;
min-height: 40px;
line-height: 3rem;
}
.container-news .news-body .news-content h3 {
font-size: 0.8rem;
margin: 0;
}
.container-news .news-body .news-content a {
float: right;
}
.pdf {
min-height: 150px;
border: 1px solid red;
}
<div class="container-news">
<div class="news-header">
<h1>Dernière actualités</h1>
</div>
<div class="news-body">
<div class="news-card rounded">
<div class="news-title">
<h2>Cours SQL (lesson)</h2>
</div>
<div class="news-content">
<h3>Catégorie: <span class="alert-success">Informatique/Programmation</span></h3>
<p class="text-muted mt-4">SQL, pour Structured Query Language, est un langage qui permet d'interroger une base de données relationnelle afin de pouvoir modifier...</p>
<p class="pdf">SHOW PDF FILES HERE</p>
<a href="#">En voir plus</a>
</div>
</div>
<div class="news-card">
<div class="news-title">
<h2>Cours SQL (lesson)</h2>
</div>
<div class="news-content">
<h3>Catégorie: <span class="alert-success">Informatique/Programmation</span></h3>
<p class="text-muted mt-4">SQL, pour Structured Query Language, est un langage qui permet d'interroger une base de données relationnelle afin de pouvoir modifier...</p>
<p class="pdf">SHOW PDF FILES HERE</p>
<a href="#" class="">En voir plus</a>
</div>
</div>
<div class="news-card">
<div class="news-title">
<h2>Cours SQL (lesson)</h2>
</div>
<div class="news-content">
<h3>Catégorie: <span class="alert-success">Informatique/Programmation</span></h3>
<p class="text-muted mt-4">SQL, pour Structured Query Language, est un langage qui permet d'interroger une base de données relationnelle afin de pouvoir modifier...</p>
<p class="pdf">SHOW PDF FILES HERE</p>
<a href="#">En voir plus</a>
</div>
</div>
</div>
</div>
My Answer:
To display the content of a PDF file within an HTML tag, you can use a library like PDF.js. PDF.js is a JavaScript library that allows you to render PDF files using HTML5 and JavaScript.
Here's how you can use PDF.js to display a PDF file within a `
` tag in your HTML:
1. First, include the PDF.js library in your HTML file. You can either download the library and include it locally or use a CDN link. Here's an example using a CDN link:
2. Next, create a `
1. First, include the PDF.js library in your HTML file. You can either download the library and include it locally or use a CDN link. Here's an example using a CDN link:
html
2. Next, create a `