【问题标题】:React js pdftron not displayedReact js pdftron 不显示
【发布时间】:2021-06-18 17:29:02
【问题描述】:

我尝试按照指南查看 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;

【问题讨论】:

    标签: javascript reactjs pdf pdftron


    【解决方案1】:

    这是一个完整的 PDFTron WebViewer React 示例,您可以参考:

    https://github.com/PDFTron/webviewer-react-sample

    您可以按照 Readme.md 进行安装和设置

    【讨论】:

    • 我想我在准确分析渲染后代码的作用后理解了这个问题。使用如下路径创建 iframe:/lib/./ui/index.html#d=%2Ffiles%2FPDFTRON_about.pdf&amp;a=1&amp;filepicker=0&amp;pdfnet=0&amp;enableRedaction=0&amp;enableMeasurement=0&amp;pageHistory=1&amp;nelotesInerverLeDeNode=
    • 问题是我的代码在应用程序中使用了类似这样的东西:&lt;Switch&gt; {routeObj.map (({path, obj}, key) =&gt; ( &lt;Route exact path = {`/ $ {path}`} component = {() =&gt; obj} key = {key} /&gt; ))} &lt;Route component = {() =&gt; &lt;Error darkState = {darkState} /&gt;} /&gt; &lt;/Switch&gt; 调用 iframe 时转到错误页面。
    猜你喜欢
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    • 2022-01-14
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多