javascript - React js pdftron 不显示
问题描述
我尝试按照指南查看 pdf 文件,但无法正常工作。
谁能帮我吗?
链接:https ://codesandbox.io/s/tender-hill-27ugg?file=/src/styles.css
代码:
import React, { useRef, useEffect } from "react";
import WebViewer from "@pdftron/webviewer";
import "./styles.css";
const App = () => {
const viewer = useRef(null);
// if using a class, equivalent of componentDidMount
useEffect(() => {
WebViewer(
{
path: "lib",
initialDoc:
"https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf"
},
viewer.current
).then((instance) => {
/*const { docViewer, Annotations } = instance;
const annotManager = docViewer.getAnnotationManager();
docViewer.on("documentLoaded", () => {
const rectangleAnnot = new Annotations.RectangleAnnotation();
rectangleAnnot.PageNumber = 1;
// values are in page coordinates with (0, 0) in the top left
rectangleAnnot.X = 100;
rectangleAnnot.Y = 150;
rectangleAnnot.Width = 200;
rectangleAnnot.Height = 50;
rectangleAnnot.Author = annotManager.getCurrentUser();
annotManager.addAnnotation(rectangleAnnot);
// need to draw the annotation otherwise it won't show up until the page is refreshed
annotManager.redrawAnnotation(rectangleAnnot);
});*/
});
}, []);
return (
<div className="App">
<div className="header">React sample</div>
<div className="webviewer" ref={viewer}></div>
</div>
);
};
export default App;
解决方案
这是一个完整的 PDFTron WebViewer React 示例,您可以参考:
https://github.com/PDFTron/webviewer-react-sample
您可以按照 Readme.md 进行安装和设置
推荐阅读
- kql - 如何在操作员日期时间变量之间调用
- verilog - “分配”操作中的操作优先级?
- bash - 在 RedHat 上的 bash 脚本中设置新用户的密码
- xslt - XSLT 将每第 n 个项目分组到新组中
- javascript - 在 Bootstrap v3.4 的页面加载时触发模式
- python - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 5: invalid continuation byte (On Python 3)
- visual-studio-code - 在 VSCode 中的同一编辑器组中导航回来
- python - 是否可以使用 ```OrderedDict``` 在 tensorflow 中使用 tf.saved_model API 生成模型?
- python - 尝试使用 Pandas 重新采样具有新频率的时间序列
- eclipse - 未连接到调试器时 MCU 复位