我正在使用此代码生成pdf:
let fileUri = process.env.PWD + '/storage/orders-pdf/' + fileName;
// Commence Webshot
webshot(html_string, fileUri, options, function(error) {
  fs.readFile(fileUri, function (err, data) {
    if (err) {
        return console.log(err);
    }
    fs.unlinkSync(fileUri);
    fut.return(data);
  });
});
let pdfData = fut.wait();
但它会引发以下错误:
{ [Error: ENOENT, open '/opt/holi/storage/orders-pdf/Attributes.pdf']
   errno: 34,
   code: 'ENOENT',
   path: '/opt/holi/storage/orders-pdf/Attributes.pdf' }
尝试使用npm包https://github.com/brenden/node-webshot 然后代码在localhost上完美运行,但在服务器上失败并抛出此错误:
编辑:
即使在没有运行webshot的情况下:
fs.readFile(fileUri, function (err, data) {
  if (err) {
    return console.log(err);
  }
  fs.unlinkSync(fileUri);
  fut.return(data);
});
该文件未创建..
EDIT 2:
Webshot抛出一个错误: [Error: PhantomJS exited with return value 2] 
编辑3:实际问题: …
这是一个示例代码:http://jsfiddle.net/gppjvjjs/1/
正如您所看到的,有可编辑的DIV内容,即句子.一句话<=>一个SPAN
问题是DIV块开始时的换行符.如何删除它,保留剩余内容的格式?
DIV内容是使用文本文件中的文本以编程方式生成的,但不包含在jsfiddle中,但这里是函数:
/* Reads sentences from loaded text. */
readSentences = function(text) {
  var lines = [],
    i = 0;
  $.each(text.split("\n"), function(key, value) {
    i++;
    var wrapper  = $('<div/>'),
      span  = $('<span/>').attr('num', i),
      sentencesMatch = value.match(/([\sa-zA-Z\d]){1}.+?[\.!\?]{1}([\s]+|$)/g);
// console.log(sentencesMatch);
    if (sentencesMatch !== null && sentencesMatch.length) {
      var sentences = '';
      $.each(sentencesMatch, function(k, v) {
        var trimmedValue = $.trim(v);
        if (trimmedValue != "") {
          if (k > 0) {
            i++;
            span.attr('num', i);
          }
          span.text(trimmedValue);
          sentences += wrapper.append(span).html() …我创建了一个带边框的语音气泡剪辑路径(非常重要)。现在我正在尝试使内容背景透明。
这是我目前的解决方案:
.background {
  background: url(https://thumbs.dreamstime.com/b/birch-forest-sunny-day-green-woods-summer-spring-landscape-43067305.jpg) no-repeat;
  background-size: cover;
  text-align: center;
}
.clip-svg {
  width: 0;
  height: 0;
}
.clip-wrap {
  display: inline-block;
  vertical-align: top;
  padding: 3px;
  background-color: #639;
  background-color: rebeccaPurple;
  clip-path: url("#speechebubble-clip");
}
.clip {
  width: 180px;
  height: 180px;
  position: relative;
  background: #fff;
}
.clip {
  clip-path: url("#speechebubble-clip");
}<div class="background">
  <div class="clip-wrap">
    <div class="clip">
      test
    </div>
  </div>
</div>
<svg class="clip-svg">
 <defs>
  <clipPath id="speechebubble-clip" clipPathUnits="objectBoundingBox">
  <path width="100%" height="100%" transform="scale(0.0045, 0.00385)" id="clip-mask" d="M34.1983772,243.81581 C35.2123618,243.81581 36.0373744,244.643759 36.0373744,245.661353 L36.0373744,260 L63.450348,244.064408 C63.7301493,243.901754 64.0488773,243.81581 …css ×2
html ×2
clip-path ×1
javascript ×1
jquery ×1
meteor ×1
node.js ×1
svg ×1
ubuntu-14.04 ×1