我有使用FPDF库生成pdf文件的项目,但是我得到了这样的错误。
致命错误:带有消息'FPDF错误的未捕获异常'异常': 有些数据已经输出,无法发送PDF文件(输出已启动 在C:\ xampp \ htdocs \ SIPP-Litbang \ admin.php:113)'in C:\ xampp \ htdocs \ SIPP-Litbang \ FPDF \ fpdf.php:271堆栈跟踪:#0 C:\ xampp \ htdocs \ SIPP-Litbang \ FPDF \ fpdf.php(1052):FPDF->错误('有些 数据有...')#1 C:\ xampp \ htdocs \ SIPP-Litbang \ FPDF \ fpdf.php(999): FPDF-> _checkoutput()#2 C:\ XAMPP \ htdocs中\ SIPP-Litbang \ tampilan管理员\ lembar_pengesahan.php(11): FPDF->输出()#3 C:\ XAMPP \ htdocs中\ SIPP-Litbang \ tampilan管理员\ permintaanproposal.php(7): include('C:\ xampp \ htdocs ...')#4 C:\ XAMPP \ htdocs中\ SIPP-Litbang \ admin.php的(145): include('C:\ xampp \ htdocs ...')#5 {main}引入 第271行的C:\ xampp \ htdocs \ SIPP-Litbang \ FPDF \ fpdf.php
以下是代码:
<?php
ob_start();
require __DIR__ . '/../FPDF/fpdf.php';
$pdf = new FPDF('P', 'mm', 'A4');
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Write('20', 'Hello World!');
$pdf->Ln();
$pdf->Write('0', 'Project Pertama Menggunakan FPDF');
ob_end_clean();
$pdf->Output();
?>
和admin.php代码顶部如下:
<?php
session_start();
require_once "class.admin.php";
$admin = new ADMIN();
$id_admin = $_SESSION['adminSession'];
$level = $_SESSION['levelSession'];
$query = $admin->runQuery("SELECT * FROM admin WHERE id_admin = :id_admin AND level = :level");
$query->bindParam(":id_admin", $id_admin);
$query->bindParam(":level", $level);
$query->execute();
$row = $query->fetch(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<body>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SIPP-Litbang</title>
<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'>
<link href="tampilan-admin/css/bootstrap.min.css" rel="stylesheet">
<link href="tampilan-admin/css/font-awesome.min.css" rel="stylesheet">
<link href="tampilan-admin/css/datepicker3.css" rel="stylesheet">
<link type="text/css" href="tampilan-admin/css/styles.css" rel="stylesheet">
<link href="tampilan-admin/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
<!--Custom Font-->
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
<!--[if lt IE 9]>
<script src="tampilan-admin/js/html5shiv.js"></script>
<script src="tampilan-admin/js/respond.min.js"></script>
<![endif]-->
</head>
在admin.php开始的输出是第113行
<div class="profile-usertitle-name"><?php echo $row['nama_admin']?></div>
我的代码出了什么问题?
答案 0 :(得分:1)
目前您正在尝试在HTML页面中输出PDF。
您需要将其分为两部分: