节点Wkhtmltopdf生成的页面不超过一页

时间:2019-03-01 16:00:59

标签: node.js pdf wkhtmltopdf html-to-pdf

我正在传递一个html页面,它将创建多个页面。
当生成的pdf为一页时,WKHTML似乎没有问题。但是,当超出此范围时,该应用程序将挂起。

这是我的生成代码

generate: (html, destination, tempName) => {
    return new Promise((resolve, reject) => {
      const file = `${destination}/${tempName}`;
      const readStream = fs.createReadStream(html);
      wkhtmltopdf(readStream, (err, stream) => {
        if (err) {
          console.log(`Pdf generation: Failed, something went wrong
            reading the template ${html}, further details here -> ${err}`);
          reject(err);
        } else {
          // on finish ensures that fs is finished writing the file
          stream.pipe(fs.createWriteStream(file)).on('finish',
            () => resolve(file));
          console.log('pdf generated at', file);
        }
      });
    });
  }

这是html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>NRM for {{name}}</title>
  <!-- TODO: pass in this through locals -->
  <link href="http://localhost:8081/public/css/pdf.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <main id="content" role="main" class="evw container">
    <div class="container">
      <div class="row">
        <div class="col-sm-6">
          <h1 class="pad-bottom-40"><span class="organisation-logo organisation-logo-stacked-ho organisation-logo-stacked-ho-large"></span></h1>
        </div>
        <div class="col-sm-6">
          <h2 class="text-right pad-top-10">NRM Report</h2>
          <h3 class="text-right font-small">Date submitted: 18/02/19 12:15</h3>
        </div>
      </div>
    </div>
    <hr/>

    <div class= "row">
      <h2>Section 1 - Your details</h2>
    </div>
    <hr/>

    <div class="row bgrey">
      <h3 class="bold">Your details</h3>
      <div class="col-sm-6">
        Mo Ali
      </div>
      <div class="col-sm-6">
        <span class="bold">Phone:</span> 0208488 9898
      </div>
    </div>

    <div class="row bgrey">
      <div class="col-sm-6 pad-left-10">
        mo@gmail.com
      </div>
    </div>


    <div class= "row bgrey">
      <h3 class="bold">Who do you work for</h3>
      <div class="col-sm-6">
        <span class="bold">Organisation</span> 
        Westiminister City Council
      </div>
      <div class="col-sm-6">
        <span class="bold">Role:</span> Senior Practitioner
      </div>
    </div>

    <div class= "row bgrey">
      <h3 class="bold">Who should we contact in your absence</h3>
      <div class="col-sm-6">
        team-email@digital.homeoffice.com
      </div>
    </div>

    <div class= "row bgrey">
      <h3 class="bold">Where are you making this report?</h3>
      <div class="col-sm-6">
        England
      </div>
    </div>

    <hr/>
    <div class= "row">
      <h2>Section 2 - Exploitation</h2>
    </div>
    <hr/>

    <div class= "row bgrey">
      <h3>Age confirmation</h2>
      <div class="col-sm-6">
        <span class="bold">Is the PV under 18?</span> 
        No
      </div>
      <div class="col-sm-6">
        <span class="bold">Under 18 (during exploitation)?</span> 
        No
      </div>
    </div>

    <div class= "row bgrey">
      <h3>Victim's account</h2>
      <div class="col-sm-12">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
      </div>
    </div>

    <div class= "row bgrey">
      <h3 class="bold">Exploitation location</h3>
      <div class="col-sm-2 bold">
        Region
      </div>
      <div class="col-sm-10">
        UK<br>
        Greater London<br>
        Wandsworth<br>
      </div>
    </div>

    <div class="row bgrey">
      <div class="col-sm-2 bold pad-left-10">
        Details
      </div>
      <div class="col-sm-10">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
      </div>
    </div>

    <div class="row bgrey new-page">
      <div class="col-sm-2 bold pad-left-10">
        Overseas
      </div>
      <div class="col-sm-10">
        Romania
      </div>
    </div>

    <div class="row bgrey">
      <div class="col-sm-2 bold pad-left-10">
        Overseas
      </div>
      <div class="col-sm-10">
        Romania
      </div>
    </div>

    <div class="row bgrey">
      <div class="col-sm-2 bold pad-left-10">
        Overseas
      </div>
      <div class="col-sm-10">
        Romania
      </div>
    </div>

    <div class="row bgrey">
      <div class="col-sm-2 bold pad-left-10">
        Overseas
      </div>
      <div class="col-sm-10">
        Romania
      </div>
    </div>

    <div class="row bgrey">
      <div class="col-sm-2 bold pad-left-10">
        Overseas
      </div>
      <div class="col-sm-10">
        Romania
      </div>
    </div>

    <div class= "row bgrey">
      <h3 class="bold">Where are they now?</h3>
      <div class="col-sm-12">
        Greater London - Lambeth
      </div>
    </div>

    <div class= "row bgrey">
      <h3 class="bold">How were they exploited?</h3>
      <div class="col-sm-4">
        <span class="bold pad-left-80">Labour & financial</span><br>
        <ul class="pad-left-0">
          <li> Forced to work for nothing or almost nothing</li>
          <li> Wages taken by force or coercion, such as through control of a bank account
          Forced to commit fraud, such as using their identity to claim benefits</li>
        </ul>
      </div>
      <div class="col-sm-4">
        <span class="bold">Sexual exploitation</span><br>
        <ul class="pad-left-0">
          <li> Forced to do something</li>
          <li> Something else</li>
          <li> More stuff</li>
        </ul>
      </div>
      <div class="col-sm-4">
        <span class="bold">Criminal exploitation</span><br>
        <ul class="pad-left-0">
          <li> Forced to commit a crime, such as growing cannabis, drug dealing or begging</li>
          <li> Organs, such as kidneys, removed against their will</li>
        </ul>
      </div>
      </div>
    </div>
    <div class="row bgrey">
      <div class="col-sm-4">
        <span class="bold pad-left-80">Domestic</span><br>
        <ul class="pad-left-0">
          <li> Forced to do unpaid household work by relatives or strangers</li>
        </ul>
      </div>
      <div class="col-sm-4">
        <span class="bold">Other</span><br>
        <ul class="pad-left-0">
          <li> Something else</li>
        </ul>
      </div>
    <hr/>
    <div class= "row">
      <h2>Section 3 - Potential victim details</h2>
    </div>
    <hr/>

    <hr/>
    <div class= "row">
      <h2>Section 4 - NRM Consent</h2>
    </div>
    <hr/>

  </main>
</body>
</html>

这里是代码的link

这是我要通过的html的link

这是我正在研究的branch

谢谢您的帮助,在此先感谢

0 个答案:

没有答案
相关问题