首页 > 解决方案 > 如何在浏览器中从我的数据库中显示 PDF 文件?

问题描述

我想使用 HTML 的嵌入标签在浏览器中显示来自数据库的 PDF 文件。我怎样才能做到这一点?这是我的 PHP 代码:

$content_query="select * from time_table where semester_no=$current_semester";
$apply_query=sqlsrv_query($conn,$content_query);
$result_content = sqlsrv_fetch_array($apply_query);

$file_directory=$result_content['file_path'];
$exists=file_exists($result_content['file_path']);
$ext=$result_content['name']; 

echo $direc="../admin/pages/".$file_directory; exit;
$path=$direc.$file_directory;

标签: php

解决方案


您可以简单地将其添加到您的 html 代码中(假设您的 pdf 存储在可公开访问的路径中)

<embed src="{{url_to_pdf}}" width="1920" height="1080"/>

或者您也可以选择使用它,

<embed src="https://drive.google.com/viewerng/viewer?embedded=true&url={{url_to_pdf}}" width="1920" height="1080">

推荐阅读