@ -1,40 +1,29 @@
@@ -1,40 +1,29 @@
'use strict' ;
var DEFAULT _SCALE = 1.5 ;
// Parse query string to extract some parameters (it can fail for some input)
var query = document . location . href . replace ( /^[^?]*(\?([^#]*))?(#.*)?/ , '$2' ) ;
var queryParams = query ? JSON . parse ( '{' + query . split ( '&' ) . map ( function ( a ) {
return a . split ( '=' ) . map ( decodeURIComponent ) . map ( JSON . stringify ) . join ( ': ' ) ;
} ) . join ( ',' ) + '}' ) : { } ;
var url = queryParams . file || '../../test/pdfs/liveprogramming.pdf' ;
var scale = + queryParams . scale || 1.5 ;
var url = queryParams . file || '../../web/compressed.tracemonkey-pldi-09.pdf' ;
function renderDocument ( pdf , svgLib ) {
var numPages = pdf . numPages ;
// Using promise to fetch the page
// For testing only.
var MAX _NUM _PAGES = 50 ;
var ii = Math . min ( MAX _NUM _PAGES , numPages ) ;
var promise = Promise . resolve ( ) ;
for ( var i = 1 ; i <= ii ; i ++ ) {
var anchor = document . createElement ( 'a' ) ;
anchor . setAttribute ( 'name' , 'page=' + i ) ;
anchor . setAttribute ( 'title' , 'Page ' + i ) ;
document . body . appendChild ( anchor ) ;
for ( var i = 1 ; i <= pdf . numPages ; i ++ ) {
// Using promise to fetch and render the next page
promise = promise . then ( function ( pageNum , anchor ) {
promise = promise . then ( function ( pageNum ) {
return pdf . getPage ( pageNum ) . then ( function ( page ) {
var viewport = page . getViewport ( scale ) ;
var viewport = page . getViewport ( DEFAULT _SCALE ) ;
var container = document . createElement ( 'div' ) ;
container . id = 'pageContainer' + pageNum ;
container . className = 'pageContainer' ;
container . style . width = viewport . width + 'px' ;
container . style . height = viewport . height + 'px' ;
anchor . appendChild ( container ) ;
document . body . appendChild ( container ) ;
return page . getOperatorList ( ) . then ( function ( opList ) {
var svgGfx = new svgLib . SVGGraphics ( page . commonObjs , page . objs ) ;
@ -43,7 +32,7 @@ function renderDocument(pdf, svgLib) {
@@ -43,7 +32,7 @@ function renderDocument(pdf, svgLib) {
} ) ;
} ) ;
} ) ;
} . bind ( null , i , anchor ) ) ;
} . bind ( null , i ) ) ;
}
}