pdfjs: How to create more than one canvas to show all the pages?

情到浓时终转凉″ 提交于 2019-12-11 11:09:03

问题


I am following the approach of here. The problem is that all the pages are in first canvas. This is because I have only one canvas and I am not sure how I can generate more canvas one after other?

 function handlePages(page)
        {
            var viewport = page.getViewport(canvas.width / page.getViewport(1.0).width);
            var ctx = canvas.getContext('2d');

            canvas.height = viewport.height;
            canvas.width = viewport.width;

            page.render({ canvasContext: ctx, viewport: viewport });

            //Add it to the web page
            div.appendChild( canvas);
                //Move to next page
                currPage++;
                if ( $scope.pdfDoc !== null && currPage <= numPages )
                {
                    $scope.pdfDoc.getPage( currPage ).then( handlePages );
                }



        }

回答1:


you cut out part of the code from the linked answer that you took this from. notice the document.createElement( "canvas" ). That creates a new canvas for every page.



来源:https://stackoverflow.com/questions/28314124/pdfjs-how-to-create-more-than-one-canvas-to-show-all-the-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!