Giter Club home page Giter Club logo

django-pdf-flipbook's Introduction

django-pdf-flipbook

A Django app that displays a pdf library in a grid and lets you read them as flipbooks.

Installation

  • Copy the flipbook folder to the root of your django project.

Install the following requirements:

  • Install Imagemagick for thumbnail generation
  • pip install Wand
  • pip install python-magic
  • pip install Pillow

For installation on Max OS X:

  • Install Ghostscript: $ brew install ghostscript
  • When running into an 'ImportError: MagickWand shared library not found.' on Mac OS X, try this solution

In settings.py add:

  • 'flipbook', to INSTALLED_APPS
DATA_DIR = os.path.dirname(os.path.dirname(__file__))
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
TEMP_ROOT = os.path.join(DATA_DIR, 'media/tmp')

In urls.py add:

  • from django.urls import include, path
  • path('flipbook/', include('flipbook.urls')), to urlpatterns

When running locally using runserver also add to urls.py:

from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.static import serve
if settings.DEBUG:
    urlpatterns = [
        url(r'^media/(?P<path>.*)$', serve,
            {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
        ] + staticfiles_urlpatterns() + urlpatterns

Then run:

  • $ python manage.py makemigrations flipbook
  • $ python manage.py migrate flipbook
  • $ python manage.py runserver

Add the Flipbook app to a page (or browse to http://127.0.0.1:8000/flipbook/) and upload the pdfs via the admin interface.

Flipbook plugins

I have implemented pdfjs-flipbook by default, which is a bit buggy but free. However, I recommend using dFlip PDF FlipBook jQuery Plugin. Simply change the template in views.py from index.html to index-dflip.html, and populate flipbook/static/flipbook/dflip/ with the js, sound, images, fonts and css folders from the dFlip PDF FlipBook jQuery Plugin.

Change the dependency urls in dflip.js as follows and you're good to go:

    pdfjsSrc: url + "js/libs/pdf.min.js",
    pdfjsCompatibilitySrc: url + "js/libs/compatibility.js",
    pdfjsWorkerSrc: url + "js/libs/pdf.worker.min.js",
    threejsSrc: url + "js/libs/three.min.js",
    mockupjsSrc: url + "js/libs/mockup.min.js",
    soundFile: url + "sound/turn2.mp3",
    imagesLocation: url + "images",
    imageResourcesPath: url + "images/pdfjs/",
    cMapUrl: url + "cmaps/", 

'not authorized' policy error

If you get a 'not authorized' policy error when uploading a pdf, this has to do with recent changes to ImageMagick. A workaround can be found here. Restart apache afterwards.

django-pdf-flipbook's People

Contributors

rjadr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-pdf-flipbook's Issues

Issues encountered while setting up.

Thanks for your wonderful work on creating this awesome app I truly appreciate. But encountered some hurdles that I managed to get through whilst setting up. This may help (especially the novice django developers) with debugging.

  1. I noticed that you didn't have migrations for the app. So I had to a $ ./manage.py makemigrations. Which brought up the issue below (issue 2).

  2. I had issues installing Imagemagick on Mac OS X 10.10.5 (worked fine on Ubuntu 16.04). Got the following error when trying to ./manage.py makemigrations yet I had Imagemagick installed

ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
    Try to install: brew install freetype imagemagick

This SO answer fixed it: https://stackoverflow.com/a/41772062

  1. After fixing the above, trying to ./manage.py makemigrations I got the following error:
    valueError: Cannot serialize: <flipbook.models.FileValidator object at 0x112603908> There are some values Django cannot serialize into migration files. For more, see https://docs.djangoproject.com/en/1.11/topics/migrations/#migration-serializing

For this, I imported from django.utils.deconstruct import deconstructible and added a @deconstructor decorator to the FileValidator class.

  1. Add url for flipbook to project root url
    For that I did a
from flipbook import urls as flipbook_urls

urlpatterns = [
# other urls
 url(r'^flipbook/', include(flipbook_urls)),
]
  1. When trying to upload a test document it failed since I didn't have ghostscript installed.
    You can also add to the requirements for Mac OS X 10.10.5 (already had gs on Ubuntu 16.04)
    For this I did a
$ brew install ghostscript
  1. Change the template in view.py to use the index-dflip.html if you using dFlip PDF FlipBook jQuery Plugin.

  2. CMS_TEMPLATE = base.html. You could mention this. Took sometime to wrap my mind around.

Hope this will be helpful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.