Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loading multiple pages into one canvas

4,557 views
Skip to first unread message

Daniel Hochleitner

unread,
May 3, 2012, 10:25:21 AM5/3/12
to mozilla-d...@lists.mozilla.org
I have for example a PDF with 4 Pages, so I try to render all pages
into one canvas, but how is this possible?
The getPage() function always want the number for one page... I testen
it with an for loop:
for (var i = 1; i <= pdf.numPages; i++) but then the canvas is
complety empty, but firebug says that all pages was fetched...
Something wrong in my code?


<p><span>Page: <span id="page_num"></span> / <span id="page_count"></
span></span></p>

<canvas id="the-canvas" style="border:1px solid black"></canvas>
<script type="text/javascript" src="/m/plugins/pdfviewer/pdf.js"></
script>

<script type="text/javascript">
var url = 'http://192.168.2.17:7777/m/plugins/pdfviewer/
apex_security_doag.pdf';
var pageNum = 1;
PDFJS.disableWorker = true;
'use strict';

PDFJS.getDocument(url).then(function(pdf) {
for (var i = 1; i <= pdf.numPages; i++) {
pdf.getPage(i).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
document.getElementById('page_num').textContent = pageNum;
document.getElementById('page_count').textContent = pdf.numPages;
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
}
});
</script>

Yury Delendik

unread,
May 3, 2012, 10:57:54 AM5/3/12
to Daniel Hochleitner, mozilla-d...@lists.mozilla.org
Daniel,

The concurrent page loading was not fully tested yet and might not work
due to the font loading hack. Could you load and render one at the
particular moment? The following code might help you:


https://github.com/mozilla/pdf.js/blob/master/examples/acroforms/forms.js#L142

Also, I noticed you draw the pages in the same spot. Use additional
transform/translate to draw to the different spot on the canvas.

Thanks,
Yury
> _______________________________________________
> dev-pdf-js mailing list
> dev-p...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-pdf-js

Daniel Hochleitner

unread,
May 3, 2012, 6:00:17 PM5/3/12
to mozilla-d...@lists.mozilla.org
On 3 Mai, 16:57, Yury Delendik <ydelen...@mozilla.com> wrote:
> Daniel,
>
> The concurrent page loading was not fully tested yet and might not work
> due to the font loading hack. Could you load and render one at the
> particular moment? The following code might help you:
>
> https://github.com/mozilla/pdf.js/blob/master/examples/acroforms/form...
> > dev-pdf...@lists.mozilla.org
> >https://lists.mozilla.org/listinfo/dev-pdf-js

Hi Yury,

thanks for reply. Yes one page work when i remove the loop part. I
will have a look at the code tomorrow und test it!
What do you mean with spot? I´m not the best JS coder:)

- Daniel

lsl...@gmail.com

unread,
Mar 11, 2013, 5:30:20 PM3/11/13
to Daniel Hochleitner, mozilla-d...@lists.mozilla.org
On Thursday, May 3, 2012 9:57:54 AM UTC-5, Yury Delendik wrote:
> Daniel,
>
>
>
> The concurrent page loading was not fully tested yet and might not work
>
> due to the font loading hack. Could you load and render one at the
>
> particular moment? The following code might help you:
>
>
>
>
>
> https://github.com/mozilla/pdf.js/blob/master/examples/acroforms/forms.js#L142
>
>
>
> Also, I noticed you draw the pages in the same spot. Use additional
>
> transform/translate to draw to the different spot on the canvas.
>
>
>
> Thanks,
>
> Yury
>
>
I know this thread is old, but I was wondering if the problem with the global name space is still around? I'm trying to display multiple PDFs on the same HTML stream without iframes and my understanding was that because of the global name spacing it wasn't possible.

Thanks,
Ross.
Message has been deleted
0 new messages