TCPDF没有从. php文件创建PDF文件


TCPDF is not creating PDF file from .PHP file

我有一个PHP文件,我想创建的PDF文件,但问题是,它不是创建PDF文件。

如果我给$content = 'ABC BCNNCNCN';工作,但对于我的。php文件谁只包含html内容,它不是一直工作。

我也粘贴我的代码在这里:

require_once('../styles/uploads/files/extract/'.$bookName.'/'.$bookName.'_coverFinal.php'); 
$content = ob_get_clean();
require_once('html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(25, 20, 25, 20));
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
html2pdf->Output("../styles/uploads/files/pdf_files/htmltopdf.pdf", 'F');
下面是我的HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title></title>
<style type="text/css">
.main-container {
    margin-left: auto;
    margin-right: auto;
    width: auto;
    font-family: Myriad Pro;
}
.page-title {
    font-family: Myriad Pro;
    font-size:25px;
    text-align: center;
}
.stepone {
    padding: 10px;
}
.steptwo {
    padding: 10px;
}
.codeis {
    font-size: 25px;
    text-align: center;
}
.code {
    font-size: 50px;
    padding: 8px;
}
.stepthree {
    padding: 10px;
}
.bookgift {
    font-weight: bold;
    text-align: center;
}
.registration {
    padding: 10px;
}
.given {
    font-size: 20px;
    font-weight: bold;
    padding: 10px;
}
.too {
    font-size: 20px;
    font-weight: bold;
    padding: 10px;
}
</style>
</head>
<body>
<div class="main-container">
  <div class="page-title">Giftcardbooks.org</div>
  <div class="stepone"> Step1. Register this book at <a href="www.giftcardbooks.org/register">www.giftcardbooks.org/register</a></div>
  <div class="steptwo"> Step 2. Enjoy the book and write down the code as you go through the book. Look for the sentences stating. Congratulations, you have just unlocked a letter in your code. The first letter is P.</div>
  <div class="codeis"> Your Code is:</div>
  <div class="code"> P _ _ _ _ _ _</div>
  <div class="stepthree"> Step 3. After finishing the book put your code in the website (<a href="www.giftcardbooks.org/giftscards">www.giftcardbooks.org/giftscards</a>) and enjoy your gift card. Thanks</div>
  <div class="bookgift">j ghjhg jghj ukrtert</div>
  <div class="registration"> Book Registration Number:&nbsp;68217543</div>
  <div class="given"> This book was given by <font style="text-decoration:underline">_mohsin_</font></div>
  <div class="too"> This book was given to <font style="text-decoration:underline">_yousaf_</font></div>
</div>
<style type="text/css">
pre{display:none !important;}
</style>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- $Id: header.txt 236 2009-12-07 18:57:00Z vlsimpson $ -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <title>The Project Gutenberg eBook of The Secret Battle, by A. P. Herbert.</title>
    <style type="text/css">
body {
    margin-left: 10%;
    margin-right: 10%;
}
h1, h2, h3, h4, h5, h6 {
    text-align: center; /* all headings centered */
    clear: both;
}
p {
    margin-top: .75em;
    text-align: justify;
    margin-bottom: .75em;
}
hr {
    width: 33%;
    margin-top: 2em;
    margin-bottom: 2em;
    margin-left: auto;
    margin-right: auto;
    clear: both;
}
table {
    margin-left: auto;
    margin-right: auto;
}
.pagenum { /* uncomment the next line for invisible page numbers */
    /*  visibility: hidden;  */
    position: absolute;
    left: 92%;
    font-size: smaller;
    text-align: right;
} /* page numbers */
.linenum {
    position: absolute;
    top: auto;
    left: 4%;
} /* poetry number */
.blockquot {
    margin-left: 5%;
    margin-right: 10%;
}
.sidenote {
    width: 20%;
    padding-bottom: .5em;
    padding-top: .5em;
    padding-left: .5em;
    padding-right: .5em;
    margin-left: 1em;
    float: right;
    clear: right;
    margin-top: 1em;
    font-size: smaller;
    color: black;
    background: #eeeeee;
    border: dashed 1px;
}
.bb {
    border-bottom: solid 2px;
}
.bl {
    border-left: solid 2px;
}
.bt {
    border-top: solid 2px;
}
.br {
    border-right: solid 2px;
}
.bbox {
    border: solid 2px;
}
.center {
    text-align: center;
}
.smcap {
    font-variant: small-caps;
}
.u {
    text-decoration: underline;
}
.caption {
    font-weight: bold;
}
/* Images */
.figcenter {
    margin: auto;
    text-align: center;
}
.figleft {
    float: left;
    clear: left;
    margin-left: 0;
    margin-bottom: 1em;
    margin-top: 1em;
    margin-right: 1em;
    padding: 0;
    text-align: center;
}
.figright {
    float: right;
    clear: right;
    margin-left: 1em;
    margin-bottom:
 1em;
    margin-top: 1em;
    margin-right: 0;
    padding: 0;
    text-align: center;
}
/* Footnotes */
.footnotes {
    border: dashed 1px;
}
.footnote {
    margin-left: 10%;
    margin-right: 10%;
    font-size: 0.9em;
}
.footnote .label {
    position: absolute;
    right: 84%;
    text-align: right;
}
.fnanchor {
    vertical-align: super;
    font-size: .8em;
    text-decoration:
 none;
}
/* Poetry */
.poem {
    margin-left:10%;
    margin-right:10%;
    text-align: left;
}
.poem br {
    display: none;
}
.poem .stanza {
    margin: 1em 0em 1em 0em;
}
.poem span.i0 {
    display: block;
    margin-left: 0em;
    padding-left: 3em;
    text-indent: -3em;
}
.poem span.i2 {
    display: block;
    margin-left: 2em;
    padding-left: 3em;
    text-indent: -3em;
}
.poem span.i4 {
    display: block;
    margin-left: 4em;
    padding-left: 3em;
    text-indent: -3em;
}
</style>
    </head>
    <body>
<div class="figcenter"> <img src="images/cover.jpg" alt=""/> </div>
<hr style="width: 65%;" />
<h1>THE SECRET BATTLE</h1>
<h2>BY A. P. HERBERT</h2>
<h3>AUTHOR OF 'THE BOMBER GYPSY'</h3>
<h3>METHUEN &amp; CO. LTD.<br />
      36 ESSEX STREET W.C.<br />
      LONDON</h3>
<h3><i>First Published in 1919</i></h3>
<hr style="width: 65%;" />
<h2>CONTENTS</h2>
<hr style="width: 65%;" />
<h2>THE SECRET BATTLE</h2>
<hr style="width: 65%;" />
<h2><a name="I" id="I"></a>I</h2>
<p>I am going to write down some of the history of Harry Penrose, because I
      do not think full justice has been done to him, and because there must
      be many other young men of his kind who flung themselves into this war
      at the beginning of it, and have gone out of it after many sufferings
      with the unjust and ignorant condemnation of their fellows. At times, it
      may be, I shall seem to digress into the dreary commonplaces of all
      war-chronicles, but you will never understand the ruthless progression
      of Penrose's tragedy without some acquaintance with each chapter of his
      life in the army.</p>
<hr style="width: 45%;" />
<p>He joined the battalion only a few days before we left Plymouth for
      Gallipoli, a shy, intelligent-looking person, with smooth, freckled skin
      and quick, nervous movements; and although he was at once posted to my
      company we had not become at all intimate when we steamed at last into
      Mudros Bay. But he had interested me from the first, and at intervals in
      the busy routine of a troopship passing without escort through submarine
      waters, I had been watching him and delighting in his keenness and happy
      disposition.</p>
<p>It was not my first voyage through the Mediterranean, though it was the
      first I had made in a transport, and I liked to see my own earlier
      enthusiasm vividly reproduced in him. Cape Spartel and the first glimpse
      of Africa; Tangiers and Tarifa and all that magical hour's steaming
      through the narrow waters with the pink and white houses hiding under
      the hills; Gibraltar Town shimmering and asleep in the noonday sun;
      Malta and the bumboat women, carozzes swaying through the narrow,
      chattering streets; cool drinks at cafés in a babel of strange tongues;
      all these were to Penrose part of the authentic glamour of the East; and
      he said so. I might have told him, with the fatuous pomp of wider
      experience, that they were in truth but a very distant reflection of the
      genuine East; but I did not. For it was refreshing to see any one so
      frankly confessing to the sensations of adventure and romance. To other
      members of the officers' mess the spectacle of Gibraltar from the sea
      may have been more stimulating than the spectacle of Southend (though
      this is doubtful); but it is certain that few of them would have
      admitted the grave impeachment.</p>
<p>That was the end of it. They were kind enough, those grey men; they did
      not like the job, and they wanted only to do their duty. But they
      conceived that their duty was 'laid down in The Book,' to look at the
      'hard facts,' and no further. And the 'hard facts' were very hard....</p>
<p>The Court was closed while they considered their verdict; it was closed
      for forty minutes, and when it reopened they asked for evidence of
      character. And that meant that the verdict was 'Guilty.' On the only
      facts they had succeeded in discovering it could hardly have been
      anything else.</p>
<p>The Adjutant put in formal evidence of Harry's service, age, record, and
      so on; and I was allowed to give evidence of character.</p>
<p>I told them simply the sort of fighting record he had, about Gallipoli,
      and the scouting, and the job he had refused in England.</p>
<p>I am glad to believe that I did him a little good; for that evening it
      got about somehow that he was recommended to mercy.</p>
<p>And perhaps they remembered that he was twenty-three.</p>
<hr style="width: 65%;" />
<h2><a name="XIII" id="XIII"></a>XIII</h2>
<p>That evening I sat in C Company mess for an hour and talked with them
      about the trial. They were very sad and upset at this thing happening in
      the regiment, but they were reasonable and generous, not like those D
      Company pups, Wallace and the other. For they were older men, and had
      nearly all been out a long time. Only one of them annoyed me, a fellow
      in the thirties, making a good income in the City, who had only joined
      up just before he had to under the Derby scheme, and had been out a
      month. This fellow was very strong on 'the honour of the regiment'; and
      seemed to think it desirable for that 'honour' that Harry should be
      shot. Though how the honour of the regiment would be thereby advanced,
      or what right he had to speak for it, I could not discover.</p>
<hr style="width: 45%;" />
<div class="footnote">
      <p><a name="Footnote_1_1" id="Footnote_1_1"></a><a href="#FNanchor_1_1"><span class="label">[1]</span></a> It is only fair to say that, long after the supposed date
    of this conversation, a system of sending 'war-weary' soldiers home for
    six months at a time was instituted, though I doubt if Foster would have
    been satisfied with that.</p>
    </div>
</body>
</html>

如果您包含的PHP文件只是HTML,请尝试使用file_get_contents获取其内容,而不是混淆输出缓冲:

$content = file_get_contents('../styles/uploads/files/extract/'.$bookName.'/'.$bookName.'_coverFinal.php');
require_once('html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(25, 20, 25, 20));
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$html2pdf->Output("../styles/uploads/files/pdf_files/htmltopdf.pdf", 'F');

编辑:失踪美元在最后一行