2013-02-13 60 views
0

pdf.js使用网络工作者:pdf.js和Django的

<script type="text/javascript"> 
    // Specify the main script used to create a new PDF.JS web worker. 
    // In production, change this to point to the combined `pdf.js` file. 
    PDFJS.workerSrc = '../../src/worker_loader.js'; 
</script> 

,但据我了解网络工作者不能说的JavaScript文件来自的URL外部访问任何内容:

Can I load a web worker script from an absolute URL?

我在AWS EC2上托管我的网站,但是从AWS S3提供静态文件。

因此,当我试图运行这行代码时,我得到一个错误:PDFJS.workerSrc ='../../src/worker_loader.js'; .js无法加载。

我是否正确地理解了这个问题,如果有的话,我有什么方法可以解决这个问题?

+1

什么阻止您在同一网站上托管pdf.js文件? – async5 2013-02-14 01:07:46

+0

我想为aws s3提供大部分静态文件 - 是否可以只使用与主django应用程序相同的服务器的pdf.js文件,并将剩余的s3文件保留在其中? – 2013-02-14 08:39:27

回答

1

似乎有两种可能的方法。无论是关闭的工人:

从pdf.js example

// Disable workers to avoid yet another cross-origin issue (workers 
// need the URL of // the script to be loaded, and currently do not allow 
// cross-origin scripts) 
// PDFJS.disableWorker = true; 

或由async5相对容易供职于同一个Apache虚拟主机作为Django的pdf.js,有一些文件提供建议通过URLs作为静态媒体,以及其他使用mod_wsgi接口的Django。文档here相对容易遵循apache部署。对于地方发展snippet加入的urls.py以下是容易适应服务了pdf.js:

from django.conf import settings 

# ... the rest of your URLconf goes here ... 

if settings.DEBUG: 
    urlpatterns += patterns('', 
     url(r'^media/(?P<path>.*)$', 'django.views.static.serve', { 
      'document_root': settings.MEDIA_ROOT, 
     }), 
    ) 

与MEDIA_URL和MEDIA_ROOT适当设定settings.py

双方将有性能问题。