我试图找到一些关于如何将 mozilla pdf.js 包含到配置了打字稿的 create-react-app 中的文档。不幸的是,我只发现很多人都在问同样的问题,但没有可行的解决方案。
目前我使用以下方法,它似乎有效。但我不确定这是否是一个好方法。
我使用 npm 安装了依赖项,如下所示。
npm install --save @types/pdfjs-dist
npm install --save pdfjs-dist
Run Code Online (Sandbox Code Playgroud)
并以这种方式导入/配置它。
// Import pdf.js
import * as pdfjsLib from 'pdfjs-dist';
pdfjsLib.GlobalWorkerOptions.workerSrc = process.env.PUBLIC_URL + '/assets/js/pdfjs/pdf.worker.min.js';
// Load pdf
pdfjsLib.getDocument('pdf_url').promise.then((promise: pdfjsLib.PDFDocumentProxy) => {
console.log(promise.fingerprint);
});
Run Code Online (Sandbox Code Playgroud)
因此,我必须确保文件pdf.worker.js.map和pdf.worker.min.js存在于文件夹中public/assets/js/pdfjs。有没有更优雅的方式解决pdf.js的导入问题?
附上react和pdfjs-dist版本:
"pdfjs-dist": "^2.5.207",
"react": "^16.13.1",
"react-scripts": "3.4.3",
"typescript": "^3.7.5"
Run Code Online (Sandbox Code Playgroud) 我们有一些预定的脚本。他们必须访问带有点源函数的文件“Functions.ps1”。此“Functions.ps1”位于共享上。因为 ExecutionPolicy 我无法像这样加载文件:
. \\share\folder\Functions.ps1
Run Code Online (Sandbox Code Playgroud)
计划的脚本必须复制到本地 C:\ 并加载文件:
$str_ScriptPath = "$($env:LOCALAPPDATA)\$(Get-Random -Minimum 0 -Maximum 100000)_Functions.ps1"
Copy-Item -Path "$str_Share\Functions.ps1" -Destination $str_ScriptPath -Force
. $str_ScriptPath
Remove-Item -Path $str_ScriptPath
Run Code Online (Sandbox Code Playgroud)
问题是有些脚本是同时安排的。
在这种情况下会出现错误:
The process cannot access the file 'C:\Windows\system32\config\systemprofile\AppData\Local\88658_Functions.ps1' because it is being used by another process.
At line:46 char:14
+ Copy-Item <<<< -Path "$str_Share\Functions.ps1" -Destination $str_ScriptPath -Force
Run Code Online (Sandbox Code Playgroud)
我不明白错误告诉本地文件被锁定的原因。它应该是唯一的文件名并且该文件不存在。
我认为因为 Copy-Item 源($str_Share\Functions.ps1)被锁定。
我的问题:
1)有没有更好的方法来处理这个问题?
2)或者有解决方法吗?
感谢帕特里克
的帮助