[Cubicweb] Preview with ViewerJS in CW

Celso FLORES celso.flores at crealibre.com
Mon Apr 4 11:56:31 CEST 2016

Hi Stephane, Christophe, list.

Having spend a little time this weekend on ViewerJS, i found as you did
that :

1. Putting your VJS in data and running your instance, we can hopefully see
the empty document viewer at (your instance path) *data/ViewerJS/index.html*

2. To see a document in a View using VJS, I only managed to make it work on
PDFs using this code:

        testpdf = "data/ViewerJS/../test1.pdf"
        frame = (u'<iframe src = "%s" width="400" height="300" '
                 u'allowfullscreen webkitallowfullscreen></iframe>' %

2.a We can see two documents PDF open at the same view, opening one frame
for each, and using the same ViewerJS obviously.

2.b As soon as I change the pdf for a Text document, spreadsheet or
presentation using LibreOffice, then the document is downloaded, while
uploading the view.
So this code :

        testdoc = "data/ViewerJS/../text.odt"
        frame = (u'<iframe src = "%s" width="400" height="300" '
                 u'allowfullscreen webkitallowfullscreen></iframe>' %

Will download the file to your system (that happens at least on my CW's
local instance)

3. So to see a document in a viewer, a test.pdf at data or from a file in
the database, CubicWeb file, sends an automatic download, probably from
idownloadable methods at the File Cube. Any raw file that i tried to see
from the database, was always send to a download.

... Some last clues :
While accessing images at the database, for instance, user's photos or
signature, we used this :
        signature = user.signature[0].absolute_url() + u'/raw/' +

And the  images where returned to HTML like this:

        photo = (u'<img src="%(picture)s" alt="%(User)s picture" '
        u'class="img-circle profile-picture img-responsive" '

Nevertheless, this "absolute_url / raw / title" works on images but on pdfs
and viewers, always send them to download.


I guess we should have some "viewable" view for pdfs, besides the
idownlodable, raw format.

Probably there is and I just could not find it.


I will certainly continue on this later this week.
Hope this helps,

On Sun, Apr 3, 2016 at 8:34 AM, Christophe de Vienne <christophe at unlish.com>

> Le 03/04/2016 11:58, Stéphane Bugat a écrit :
> >
> >>> Christophe, this did not work neither... However the error message is
> >>> now "cette ressource est introuvable" (bad resource location). The
> >>> number of parent dirs '../' does not have any effect.
> >> Is this message displayed by ViewerJS which try to access the resource,
> >> or by the browser who cannot load ViewerJS itself ?
> >>
> >> If the former, try adding/removing '../'s, and have a look at the
> >> 'network' tab of the browser devtools so you get an idea of what URL the
> >> viewer is actually hitting.
> >>
> >> If the later, where did you extract ViewerJS sources ?
> >
> > Christophe, thanks for those tips. ViewerJS was extracted into the data/
> > directory of the cube. Viewing
> >
> http://myserver:8080/data/0a6bfcf4ea4e36b05a5bacb5e843de69/ViewerJS/index.html
> > gives no error (but displays an empty view). The network tab of the
> > devtools shows that the GET of index.html is OK.
> >
> > I've tried to copy foo.pdf into the data/ directory and view
> >
> http://myserver:8080/data/0a6bfcf4ea4e36b05a5bacb5e843de69/ViewerJS/index.html/#../../../foo.pdf
> > (so that the PDF file is no more in the database but in an accessible
> > part of the cube), but the GET method always returns an error 403
> > (forbidden). This is also independant of the number of '../'. Removing
> > 'index.html' does not change anything. Trying to view any other
> > accessible file (for instance those in wdoc/) always gives the same
> > error...
> On what exact URL do you get a 403 (look at the network tab) ? Play with
> the ../ until the URL accessed by ViewerJS is the right one (by that I
> mean the URL of the file when it is stored in the database, like
> /file/xxx/raw/file.ext).
> You can also try the replace the '(../)*' with a single '/' which should
> mean "back to the top level path" (not sure if ViewserJS likes it though).
> If you still get a 403 on a URL that you can otherwise access, check if
> the authentication cookies are correctly set on the request made by
> ViewerJS.
> --
> Christophe de Vienne
> Co-fondateur http://unli.sh
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> https://lists.cubicweb.org/mailman/listinfo/cubicweb

Knowledge Management Consultant
Mx. Celular - 55 25 07 21 60
celso.flores at crealibre.com  about.me/celsoflores
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20160404/428f2fbe/attachment-0186.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshotvjs.png
Type: image/png
Size: 54713 bytes
Desc: not available
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20160404/428f2fbe/attachment-0273.png>

More information about the Cubicweb mailing list