gpt4 book ai didi

reactjs - 使用外部应用程序打开 Electron 中打包的 PDF

转载 作者:行者123 更新时间:2023-12-03 12:26:08 25 4
gpt4 key购买 nike

我们想在我们的应用程序中分发一组 PDF 文件。最初我们使用 React PDF 查看器打开这些文件,但是用户确实需要能够将这些文件保存到他们的计算机上,以便他们可以在自己的时间阅读/注释/打印这些文件等。

我们在 Electron 中使用 Create React App - 你有什么建议吗?

谢谢!

使用以下方法设法使其工作:

PDFLink= (e)=> { // Open PDF with `shell` method
console.log("Clicked PDF: ");
var attrs=e.currentTarget.attributes;
const shell = window.require('electron').shell;
const remote = window.require('electron').remote;
const appPath = remote.app.getAppPath();
console.log('appPath: ', appPath);

for (var a=0;a<attrs.length;a++)
{
console.log(attrs[a].name+"="+attrs[a].value);
switch (attrs[a].name)
{
case 'data-pdf':
//console.log(app.getAppPath());
shell.openItem(appPath+'\\public\\pages\\test1.pdf');

break;

default:
break;
}
}

}

最佳答案

如果您的应用程序随附 PDF,您可以使用 shell打开它们的模块:shell.openItem(fullPath) .

shell

Manage files and URLs using their default applications.



shell.openItem(fullPath)

Returns Boolean - Whether the item was successfully opened

Open the given file in the desktop's default manner.

关于reactjs - 使用外部应用程序打开 Electron 中打包的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55569279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com