Pdf.js: 为单页查看器撰写示例

创建于 2017-09-24  ·  8评论  ·  资料来源: mozilla/pdf.js

在提取请求#8724中,已实现了单个页面查看器。 最好在examples文件夹中有一个组件示例,以演示如何使用此查看器。

1-other 5-good-beginner-bug

最有用的评论

在components文件夹中,pageviewer.js是一个使用pdf_page_view.js正常显示pdf文件的示例。 我需要创建一个使用pdf_single_page_viewer.js的示例singlepageviewer.js。

考虑到PDFSinglePageViewer实现与PDFViewer相同的接口,基于https://github.com/mozilla/pdf.js/blob/master/examples/components/simpleviewer.js的新示例将是一个更合适的起点。

所有8条评论

嗨! 我想解决这个问题。 这是我第一次在Github上解决问题,所以如果您能帮助我弄清楚如何入门,我非常乐意。
我已经在gulp服务器上运行了本地副本。

https://github.com/mozilla/pdf.js/tree/master/examples/components文件夹中有组件示例。 此修补程序的目的是添加一个使用PDFSinglePageViewer的示例。 像那里的其他示例一样,它可以仅加载默认的Tracemonkey PDF文件。

谢谢! 我将尝试解决这个问题。

所以,我在这里有些困惑。 这是我的理解:
在components文件夹中,pageviewer.js是一个使用pdf_page_view.js正常显示pdf文件的示例。 我需要创建一个使用pdf_single_page_viewer.js的示例singlepageviewer.js。

到目前为止,我是否沿着正确的道路前进?

因此,基本上这就是我需要从pageviewer.js文件进行编辑的内容,以便它可以使用单个页面查看器吗?

return pdfDocument.getPage(PAGE_TO_VIEW).then(function (pdfPage) {
    // Creating the page view with default parameters.
    var pdfPageView = new PDFJS.PDFPageView({
      container: container,
      id: PAGE_TO_VIEW,
      scale: SCALE,
      defaultViewport: pdfPage.getViewport(SCALE),
      // We can enable text/annotations layers, if needed
      textLayerFactory: new PDFJS.DefaultTextLayerFactory(),
      annotationLayerFactory: new PDFJS.DefaultAnnotationLayerFactory()
    });
    // Associates the actual page with the view, and drawing it
    pdfPageView.setPdfPage(pdfPage);
    return pdfPageView.draw();
  });

这是singlepageviewer.js作为编辑部分包含的内容:

return pdfDocument.getPage(PAGE_TO_VIEW).then(function (pdfPage) {
    // Creating the page view with default parameters.
    var pdfSinglePageView = new PDFJS.PDFSinglePageViewer({
      container: container,
      id: PAGE_TO_VIEW,
      scale: SCALE,
      defaultViewport: pdfPage.getViewport(SCALE),
      // We can enable text/annotations layers, if needed
      textLayerFactory: new PDFJS.DefaultTextLayerFactory(),
      annotationLayerFactory: new PDFJS.DefaultAnnotationLayerFactory()
    });
    // Associates the actual page with the view, and drawing it
    pdfSinglePageView.setPdfPage(pdfPage);
    return pdfSinglePageView.draw();
  });

到目前为止,我的方法有意义吗?

非常感谢您的宝贵时间!

重新发布格式正确的评论。

在components文件夹中,pageviewer.js是一个使用pdf_page_view.js正常显示pdf文件的示例。 我需要创建一个使用pdf_single_page_viewer.js的示例singlepageviewer.js。

考虑到PDFSinglePageViewer实现与PDFViewer相同的接口,基于https://github.com/mozilla/pdf.js/blob/master/examples/components/simpleviewer.js的新示例将是一个更合适的起点。

感谢您的建议!
我已经提交了拉取请求https://github.com/mozilla/pdf.js/pull/8989。 请对其进行检查,并让我知道是否要进行任何更改。

编辑:
我不知道我是否在这里缺少任何内容,但是没有任何组件示例在http://localhost:8888/examples/components/{anyfile}.html的浏览器中显示任何内容。 控制台显示以下错误:

singlepageviewer.html:38 GET http://localhost:8888/node_modules/pdfjs-dist/web/pdf_viewer.css net::ERR_ABORTED
singlepageviewer.html:40 GET http://localhost:8888/node_modules/pdfjs-dist/build/pdf.js net::ERR_ABORTED
singlepageviewer.html:41 GET http://localhost:8888/node_modules/pdfjs-dist/web/pdf_single_page_viewer.js net::ERR_ABORTED
singlepageviewer.js:18 Uncaught ReferenceError: PDFJS is not defined
    at singlepageviewer.js:18

我不知道我是否在这里缺少任何内容,但是没有任何组件示例在浏览器中的http:// localhost :8888 / examples / components / {anyfile} .html上显示任何内容。 控制台显示以下错误:

如示例的*.js文件中所述,请参见例如此处,您是否运行gulp dist-install

知道了谢谢!
这是拉取请求,其中包括您所有已审核的更改以及根据Contributing and Squashing Commits Wiki: https :
非常感谢您的宝贵时间!

此页面是否有帮助?
0 / 5 - 0 等级