首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NodeJS html-pdf右侧切割

NodeJS html-pdf右侧切割
EN

Stack Overflow用户
提问于 2021-02-05 17:10:05
回答 1查看 519关注 0票数 2

我正在使用html-pdf将HTML转换成pdf;然而,它正在削减内容的右侧。我从数据库中获取HTML,并使用express向浏览器发送pdf响应。

代码语言:javascript
复制
let htmlData = await getData(); // it returns the HTML below

pdf.create(htmlData ).toBuffer(function(err, buffer){
    res.writeHead(200, {
        'Content-Type': 'application/pdf',
        'Content-Length': buffer.length
    });
    return res.end(buffer);
});

HTML内容(我不能更改它,但如果需要可以添加css样式)

代码语言:javascript
复制
<!DOCTYPE html>
<html>
   <head>
      </style>
      <link href=\"https://fonts.googleapis.com/css?family=Aguafina+Script|Alex+Brush|Bilbo|Condiment|Great+Vibes|Herr+Von+Muellerhoff|Kristi|Meddon|Monsieur+La+Doulaise|Norican|Nothing+You+Could+Do|Parisienne|Permanent+Marker|Sacramento|Yellowtail\" rel=\"stylesheet\">
   </head>
   <body>
      <p>&nbsp;</p>
      \n<p style=\"text-align: center;\"><span style=\"font-size: 12pt;\"><strong>My Doc TEST</strong></span></p>\n<p style=\"text-align: center;\"><span style=\"font-size: 8pt;\"><strong>dksfdksfndskfndsklfndskl dfkdsfnldks dsfkljdsklfdsmlkf.</strong></span></p>\n<p style=\"text-align: left;\"><span style=\"font-size: 8pt;\">Date: <strong>08/19/2020</strong></span></p>\n<table style=\"height: 30px;\" width=\"993\">\n
      <tbody>
         \n<tr style=\"height: 5847px;\">\n<td style=\"width: 488.5px; height: 5847px;\">\n
         <p><span style=\"background-color: #ff0000; color: #ffffff; font-size: 8pt;\">Moving In &mdash; General Information</span></p>
         \n
         <ol>
         \n
         <li dir=\"ltr\"><span style=\"background-color: #ffffff; color: #000000; font-size: 8pt;\">Parties. This Lease Contract (&ldquo;Lease&rdquo;) is between you, the resident(s) (list all people signing the Lease): ________<strong>NAME</strong> <strong>NAME</strong> ____<strong>NAME NAME </strong>_____________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ and us, the owner:&nbsp;<strong>COMPANY ABCABCABC</strong> You are renting Apartment No<strong> 53, </strong>at<strong> 123 MAIN </strong>in<strong> MY CITY</strong>, <strong>AA</strong> <strong>00000</strong> for use as a private residence only. The terms &ldquo;you&rdquo; and &ldquo;your&rdquo; refer to all residents listed above or, in the event of a sole resident&rsquo;s death, to someone authorized to act for the estate. The terms &ldquo;we,&rdquo; &ldquo;us,&rdquo; and &ldquo;our&rdquo; refer to the owner listed above and not to property managers or anyone else. Neither we nor any of our representatives have made any oral promises, representations, or agreements. This Lease is the entire agreement between you and us.</span></li>
         \n
         <li dir=\"ltr\"><span style=\"background-color: #ffffff; color: #000000; font-size: 8pt;\">Occupants. The apartment will be occupied only by you and (list all other occupants not signing the Lease): _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________&nbsp;&nbsp;&nbsp; and no one else. Anyone not listed here cannot stay in the apartment for more than ___7____ consecutive days without our prior written consent, and no more than twice that many days in any one month. If the previous space isn&rsquo;t filled in, 2 days total per month will be the limit.
   </body>
</html>

PDF显示:

如果我更改为只返回HTML内容,它将显示所有内容:

EN

回答 1

Stack Overflow用户

发布于 2022-01-20 19:58:53

您可以使用以下CSS属性解决此问题:

代码语言:javascript
复制
break-inside: auto

“内部中断”CSS属性设置页面、列或区域中断在生成框中的行为方式。如果没有生成框,则忽略该属性。Auto允许但不强制在主框中插入任何断点(页、列或区域)。

如果从其正常状态更改了以下属性,则需要将其更改回:

代码语言:javascript
复制
white-space: normal

正常:空白区序列被折叠。源中的换行符处理方式与其他空白相同。如有必要,线会被打破,以填充线框。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66067594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档