Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js NodeJS PDF:仅在附加调试器时才能正常工作_Node.js_Visual Studio_Debugging_Asp.net Core_Pdf Generation - Fatal编程技术网

Node.js NodeJS PDF:仅在附加调试器时才能正常工作

Node.js NodeJS PDF:仅在附加调试器时才能正常工作,node.js,visual-studio,debugging,asp.net-core,pdf-generation,Node.js,Visual Studio,Debugging,Asp.net Core,Pdf Generation,我有一个奇怪的问题发生在我的一个项目上(但不是其他项目),我看不到任何其他人有任何类似的事情。(由于这是实际的公司代码,因此我对缺乏适当的示例提前表示歉意) 我遇到的问题是在一个.NETCore2项目中,我试图使用nodejs创建PDF(就像我在第二个项目中遇到的一样)。但是,PDF仅在附加Visual Studio(2017)调试器时才能正确生成 try { var result = await nodeServices.InvokeAsync<byte[]>(pdfSet

我有一个奇怪的问题发生在我的一个项目上(但不是其他项目),我看不到任何其他人有任何类似的事情。(由于这是实际的公司代码,因此我对缺乏适当的示例提前表示歉意)

我遇到的问题是在一个.NETCore2项目中,我试图使用nodejs创建PDF(就像我在第二个项目中遇到的一样)。但是,PDF仅在附加Visual Studio(2017)调试器时才能正确生成

try
{
    var result = await nodeServices.InvokeAsync<byte[]>(pdfSettings, viewWithAbsoluteLinks);

    string invoicePath = _configuration.GetSection("AppSettings")["InvoicePath"];
    string filename = Path.Combine(invoicePath, "invoice.pdf");

    FileUtils.WriteToFile(filename, result);

    return Json(new { success = true, size = result.Count(), viewAsHtml, viewWithAbsoluteLinks, environment, pdfSettings, result });
}
catch
{
    return Json(new { success = false });
}
试试看
{
var result=await nodeServices.InvokeAsync(pdfSettings,viewWithAbsoluteLinks);
字符串invoicePath=_configuration.GetSection(“AppSettings”)[“invoicePath”];
字符串文件名=Path.Combine(invoicePath,“invoice.pdf”);
FileUtils.WriteToFile(文件名、结果);
返回Json(新的{success=true,size=result.Count(),viewAsHtml,viewWithAbsoluteLinks,environment,pdfSettings,result});
}
抓住
{
返回Json(新的{success=false});
}
我将jsrender与phantom pdf一起使用,当我在Visual Studio中附加调试器时,结果是69318。但是,当我在没有附加调试器的情况下运行时,结果=66167字节

为了进行调试,我返回了变量viewWithAbsoluteLinks,以便查看是否有任何差异,在这两种情况下,该变量是相同的

带有绝对链接的视图是:

<html>

<head>
  <style>
    .pdf-hidden {
      display: none;
    }

    .pdf-visible {
      display: block !important;
    }
  </style>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>Invoice</title>
  <link rel="stylesheet" href="http://localhost:10795/lib/bootstrap/dist/css/bootstrap.css">
  <link rel="stylesheet" href="http://localhost:10795/css/site.css">
  <link rel="stylesheet" href="http://localhost:10795/css/site.theme.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt"
    crossorigin="anonymous">
  <link rel="stylesheet" href="http://localhost:10795/lib/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
  <style>
    body {
      font-family: "DIN 2014 Light", 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
      color: #000;
    }
  </style>
</head>

<body>
  <div class="pull-right" style="border: 1px solid #0f0">
    <img src="http://localhost:10795/images/training-logo.png">
  </div>
  <div style="padding-top: 50px;">
    <table style="width: 100%; border: 1px solid #000">
      <tbody>
        <tr>
          <td style="border: 1px solid #f00"> Address </td>
          <td> Invoice </td>
        </tr>
      </tbody>
    </table>
  </div>
  <script type="text/javascript">        window.JSREPORT_READY_TO_START = true;    </script>
</body>

</html>

.pdf隐藏{
显示:无;
}
.pdf可见{
显示:块!重要;
}
发票联
身体{
字体系列:“DIN 2014 Light”、“开放式Sans”、“Helvetica Neue”、“Helvetica、Arial、Sans serif;
颜色:#000;
}
地址
发票联
window.JSREPORT_READY_TO_START=true;
附加调试器后,标记中的文本将显示在PDF中。未附加调试器时,文本不会显示。(s有不同的颜色边框-颜色显示正确)

我假设在调试改变某些东西时运行,但我不确定是什么。起初我以为CSS只是让文本变白了,但文件大小表明文本确实不存在


有人知道Visual Studio在连接调试器时会如何使其正常工作吗?

经过一段时间的努力,我可能刚刚解决了这个问题。时机

事件虽然附加了调试器(没有断点,只是附加了),但这可能会导致一个很小的延迟,时间刚好足以生成PDF

快速查看SO,我发现:


我添加了1秒的延迟,它在没有附加调试程序的情况下正确生成了包含文本的PDF。

我无法编辑我的问题:HTML示例下面的部分应为:附加调试程序时,PDF中显示的TD标记内的文本。未附加调试器时,文本不会显示。(TDs有不同的颜色边框,颜色显示正确)感谢您在此分享您的解决方案,您可以接受它作为答案。这对阅读此帖子的其他社区成员是有益的;这似乎对我有用,但我还没有做这方面的工作,所以我不能确定它是否已经修复。@Nigel Ellis,如果你能在你这边测试它会更好,这样我们就可以知道它是否能帮助你解决这个问题,并帮助其他社区成员解决同样的问题。等待着你。祝你有一个愉快的一天:)我已经回到了这个任务上-而且似乎仍然是这样,当有自定义字体时,加载字体需要延迟(大约1秒)。不过,图像不需要延迟。
try
{
    var result = await nodeServices.InvokeAsync<byte[]>(pdfSettings, viewWithAbsoluteLinks);

    string invoicePath = _configuration.GetSection("AppSettings")["InvoicePath"];
    string filename = Path.Combine(invoicePath, "invoice.pdf");

    FileUtils.WriteToFile(filename, result);

    return Json(new { success = true, size = result.Count(), viewAsHtml, viewWithAbsoluteLinks, environment, pdfSettings, result });
}
catch
{
    return Json(new { success = false });
}