2

嗨,我正在尝试使用 ' turnjs' 和 ' pdf.js' 构建一本翻书。我能够通过本地 pdf 文件以及在线 pdf url 构建翻书,当我尝试使用 pdf blob url 时,它显示如下错误

Error: Access to 'blob:http://localhost:8080/41029659-ad46-4f1d-ba0a-6c874271cc38' from script denied

但是当我尝试使用window.open我能够在新窗口中查看 pdf 打开这个 url 时。

这是我的代码

       //file = '1.pdf'; // it works
     file="blob:http://localhost:8080/41029659-ad46-4f1d-ba0a-6c874271cc38" // here im getting the error

 // window.open(file);  // it will shows the pdf in new window for blob url

     PDFJS.getDocument(file).then(function (doc) {
                pdfDoc = doc;
                np = (doc.numPages);

                scale = 3;
                $(".flip-book").html('')
                for (var i = 1; i <= np; i++) {
                    $(".flip-book").html($(".flip-book").html() + '<div><canvas id="canvs' + i + '" style="border: 1px solid black; width: 99.4%; height: 99.5%;"></canvas></div>');
                }

                for (var i = 1; i <= np; i++) {

                    hoja = document.getElementById('canvs' + i)
                    pdfDoc.getPage(i).then(function (page) {

                        var viewport = page.getViewport(scale);
                        hoja.height = viewport.height;
                        hoja.width = viewport.width;
                        var renderContext = {
                            canvasContext: hoja.getContext('2d'),
                            viewport: viewport
                        };
                        page.render(renderContext);
                    });


                }
                $('.flip-book').turn({
                    // Width

                    width: 922,

                    // Height

                    height: 600,

                    // Elevation

                    elevation: 50,

                    // Enable gradients

                    gradients: true,

                    // Auto center this flipbook

                    autoCenter: true

                });
            }); 
4

0 回答 0