Node.js 无法使用Print Js打印PDF文件

Node.js 无法使用Print Js打印PDF文件,node.js,pdf,printjs,cross-origin-resource-policy,Node.js,Pdf,Printjs,Cross Origin Resource Policy,下面是我试图打印pdf文件的代码 <!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript" src="print.min.js"></script> <link rel="stylesheet" type="text/css&quo

下面是我试图打印pdf文件的代码

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script type="text/javascript" src="print.min.js"></script>
  <link rel="stylesheet" type="text/css" href="print.min.css">
</head>
<body>
  <script type="text/javascript">
    function sample(){
      printJS({
        printable: "test.pdf",
        type: "pdf",
      });
    }
  </script>
  <button onclick="sample()">Click Me</button>
</body>
</html>

函数示例(){
printJS({
可打印:“test.pdf”,
键入:“pdf”,
});
}
点击我
但它不工作,在chrome控制台上的错误下潜水

在'file:///test.pdf“来自源”的“null”已被CORS策略阻止:跨源请求仅支持协议方案:http、数据、chrome、chrome扩展、chrome不受信任、https。

我遵守Print js文档中的所有规则。我的{.pdf}文件和{.html}文件在同一个文件夹中。它可以很好地处理{.jpg}文件。 请帮帮我

我正在分享我的头标签中包含的脚本链接 JS:-
CSS:-

这是关于“跨来源请求”的问题。要解决这个问题,您需要启动本地服务器。在我的例子中,我启动了Xampp,并将我的文件移动到htdocs文件夹中,然后它就开始工作了。。我仍然不知道为什么它适用于图像而不适用于PDF

下面是帮助我解决堆栈溢出问题的答案。