如何知道PDF.JS是否已完成渲染? [英] How to know if PDF.JS has finished rendering?

查看:1612
本文介绍了如何知道PDF.JS是否已完成渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PDF.JS将pdf页面转换为不同的画布元素。我的要求是捕获画布的输出并将其显示为图像。是否有一些事件知道如果在canvas中的pdf页面的渲染已经完成。因为当我试图捕获画布的输出是空白。但pdf页面正确呈现。 看起来我的捕获事件在pdf.js完成渲染过程之前被调用。

I am using PDF.JS to render pdf pages into different canvas elements. my requirement is to capture the output of the canvas and to display it as an image. Is there some event to know if the rendering of the pdf page in canvas has been finished or not. because when I try to capture the output of canvas it is blank. but the pdf page is rendered properly. it looks like my capture event is being called before the pdf.js finishes the rendering process.

这里是我的代码:

page.render(renderContext);
var myImage = new Image();
myImage.src = document.getElementById('my-canvas-id').toDataURL();
$('body').append(myImage);

如果我在FireFox的控制台中执行相同的代码,所以没有什么是错误的这个代码。

If I execute the same code in my FireFox's console this works fine. so nothing is wrong with this code.

只是为了让大家知道我已经尝试过document.ready和window.load事件。

Just to let you people know that I already have tried document.ready and window.load events.

推荐答案

我也在努力解决这个问题..我使用的解决方案是:

I was also struggling with this problem.. the solution that i used is:

//Step 1: store a refer to the renderer
var pageRendering = page.render(renderContext);
//Step : hook into the pdf render complete event
var completeCallback = pageRendering.internalRenderTask.callback;
pageRendering.internalRenderTask.callback = function (error) {
  //Step 2: what you want to do before calling the complete method                  
  completeCallback.call(this, error);
  //Step 3: do some more stuff
};

这篇关于如何知道PDF.JS是否已完成渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆