Tuesday, 15 May 2012

pdf.js and django -



pdf.js and django -

pdf.js uses web workers:

<script type="text/javascript"> // specify main script used create new pdf.js web worker. // in production, alter point combined `pdf.js` file. pdfjs.workersrc = '../../src/worker_loader.js'; </script>

but understand web workers can't access outside of url javascript file came from:

can load web worker script absolute url?

i'm hosting site on aws ec2, serving static files aws s3.

i hence error when trying run equivalent of line: pdfjs.workersrc = '../../src/worker_loader.js'; .js cannot loaded.

have understood problem correctly, , if so, options have around this?

there appear 2 possible methods. either turn off workers:

from pdf.js example:

// disable workers avoid yet cross-origin issue (workers // need url of // script loaded, , not allow // cross-origin scripts) // pdfjs.disableworker = true;

or suggested async5 relatively easy serve pdf.js on same apache virtualhost django, files served urls static media, , others using mod_wsgi interface django. documentation here relatively easy follow apache deployment. local development next snippet added urls.py easy adapt serve pdf.js:

from django.conf import settings # ... rest of urlconf goes here ... if settings.debug: urlpatterns += patterns('', url(r'^media/(?p<path>.*)$', 'django.views.static.serve', { 'document_root': settings.media_root, }), )

with media_url , media_root set appropriately in settings.py

both have performance implications.

django pdf.js

No comments:

Post a Comment