Fork me on GitHub
#beginners
<
2016-06-28
>
conaw14:06:41

So, I’m trying to work with a mozilla’s PDF rendering library, PDFjs via a cljsjs package — and when following their example, I keep getting an error .getPage is not a function. I’m having a hard time figuring out how to debug this.

(-> (.getDocument js/PDFJS "/onlisp.pdf")
     (.then (fn [pdfFile] (.getPage pdfFile 1)))
     (.then (fn [page] (.getViewport page 1))))
their code
PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) {
    //
    // Fetch the first page
    //
    pdf.getPage(1).then(function getPageHelloWorld(page) {
      var scale = 1.5;
      var viewport = page.getViewport(scale);

      //
      // Prepare canvas using PDF page dimensions
      //
      var canvas = document.getElementById('the-canvas');
      var context = canvas.getContext('2d');
      canvas.height = viewport.height;
      canvas.width = viewport.width;

      //
      // Render PDF page into canvas context
      //
      var renderContext = {
        canvasContext: context,
        viewport: viewport
      };
      page.render(renderContext);
    });
  });

martinklepsch14:06:13

@conaw: are you using advanced optimizations?

martinklepsch14:06:13

@conaw: the issue might be that this function is missing from the externs for the CLJSJS package

martinklepsch14:06:27

you can easily check that by grepping for getPage in the compiled js file

conaw14:06:01

doesn’t appear to be in there

martinklepsch14:06:10

oh well, ignore what I said

martinklepsch14:06:33

if the error is .getPage is not a function. that shouldn't apply

martinklepsch14:06:16

if the error would be .xys is not a function that could mean that your call to getPage has been optimized-away

conaw14:06:35

the thing that is confusing me is, there seem to be a bunch of ways that I could be getting this error — it’s calling .getPage on a promise and not the returned object was my first fear, or the library itself doesn’t have an error message for when I request a pdf that doesn’t exist

conaw14:06:47

or there is some CORS thing I’m not doing that it needs

conaw14:06:24

but I really don’t know how I should debug this

conaw14:06:03

.getDocument works

conaw14:06:17

at least in that it returns a promise

rauh14:06:59

@conaw: (set! js/XY pdfFile) in your hander and then inspect XY in your console

conaw14:06:27

by console.log’ing it?

conaw14:06:44

it says XY undefined

conaw14:06:53

does this mean its never reaching the .then?

rauh14:06:42

@conaw Add a reject handler.

rauh14:06:47

As the second argument to .then

conaw14:06:52

brilliant

conaw15:06:31

so, in the examples, the pdfjs folks have you set some workers up in a file in resources, I checked that file’s location, and it looked like it was the place this error is coming from

conaw15:06:48

@rauh does this make any sense to you?

conaw15:06:16

@martinklepsch: is it possible this is a problem with the cljsjs packagage?

conaw15:06:54

@rauh appreciate the help in helping me find a better error

conaw15:06:31

ok actually I may have spoken too soon

conaw15:06:46

still not getting any response

conaw15:06:54

looks like that error was from elsewhere

leo.ribeiro17:06:20

also, as I’m beginning in the lisp/clojure world, if you have any tips to improve my code, please let me know 🙂

Tim18:06:26

@leo.ribeiro: what db are you using?

leo.ribeiro18:06:47

@tmtwd: oh sorry.. I missed the most important information haha… it’s mysql

Tim18:06:27

no, I’m just wondering, I’m not really a mysql or even jdbc expert

danlebrero18:06:21

@leo.ribeiro: can you try changing line 75 map to mapv?

hrathod18:06:46

@leo.ribeiro: You might also want to look at this function to make a transaction roll back: https://clojure.github.io/java.jdbc/#clojure.java.jdbc/db-set-rollback-only!

leo.ribeiro20:06:08

@danlebrero: sorry… I had leave to lunch

leo.ribeiro20:06:43

@hrathod: thank you, I will give it a shot

leo.ribeiro20:06:13

@danlebrero: what’s the difference here between mapv rather than map?

leo.ribeiro20:06:36

@danlebrero: LOL it worked… I got it… it’s something to do in laziness and db contexts right? by the way thank you very much

danlebrero21:06:50

@leo.ribeiro: that is correct :) laziness is sometimes a curse

hrathod21:06:36

useful for forcing side effects

leo.ribeiro21:06:59

@hrathod: if I use doall it realize all the possible lazy objects inside that, including nesting maps?

hrathod21:06:53

@leo.ribeiro: For that, I am not sure. Sorry.

danlebrero22:06:45

@leo.ribeiro: doall just realizes the lazy seq passed as param.

danlebrero22:06:47

@leo.ribeiro: if the elements of the lazy seq are themselves lazy seqs, they will not be realized.