Merge pull request #173 from cgjones/issue-169

fix another binary-mode issue
This commit is contained in:
sayrer 2011-07-04 14:40:59 -07:00
commit 67baa86c60
3 changed files with 29 additions and 23 deletions

1
pdf.js
View File

@ -2971,6 +2971,7 @@ var Catalog = (function() {
var PDFDoc = (function() { var PDFDoc = (function() {
function constructor(stream) { function constructor(stream) {
assertWellFormed(stream.length > 0, "stream must have data");
this.stream = stream; this.stream = stream;
this.setup(); this.setup();
} }

View File

@ -99,7 +99,7 @@ class PDFTestHandler(BaseHTTPRequestHandler):
self.send_header("Content-Type", MIMEs[ext]) self.send_header("Content-Type", MIMEs[ext])
self.send_header("Content-Length", os.path.getsize(path)) self.send_header("Content-Length", os.path.getsize(path))
self.end_headers() self.end_headers()
with open(path) as f: with open(path, "rb") as f:
self.wfile.write(f.read()) self.wfile.write(f.read())
def do_GET(self): def do_GET(self):
@ -275,7 +275,7 @@ def downloadLinkedPDFs(manifestList):
sys.stdout.flush() sys.stdout.flush()
response = urllib2.urlopen(link) response = urllib2.urlopen(link)
with open(f, 'w') as out: with open(f, 'wb') as out:
out.write(response.read()) out.write(response.read())
print 'done' print 'done'

View File

@ -88,31 +88,35 @@ function nextPage() {
} }
} }
failure = ''; var ctx, fonts, gfx;
log(" loading page "+ currentTask.pageNum +"... "); if (!failure) {
log(" loading page "+ currentTask.pageNum +"... ");
var ctx = canvas.getContext("2d"); ctx = canvas.getContext("2d");
var fonts = []; fonts = [];
var gfx = null; gfx = null;
try { try {
gfx = new CanvasGraphics(ctx); gfx = new CanvasGraphics(ctx);
currentPage = pdfDoc.getPage(currentTask.pageNum); currentPage = pdfDoc.getPage(currentTask.pageNum);
currentPage.compile(gfx, fonts); currentPage.compile(gfx, fonts);
} catch(e) { } catch(e) {
failure = 'compile: '+ e.toString(); failure = 'compile: '+ e.toString();
}
} }
try { if (!failure) {
var pdfToCssUnitsCoef = 96.0 / 72.0; try {
// using mediaBox for the canvas size var pdfToCssUnitsCoef = 96.0 / 72.0;
var pageWidth = (currentPage.mediaBox[2] - currentPage.mediaBox[0]); // using mediaBox for the canvas size
var pageHeight = (currentPage.mediaBox[3] - currentPage.mediaBox[1]); var pageWidth = (currentPage.mediaBox[2] - currentPage.mediaBox[0]);
canvas.width = pageWidth * pdfToCssUnitsCoef; var pageHeight = (currentPage.mediaBox[3] - currentPage.mediaBox[1]);
canvas.height = pageHeight * pdfToCssUnitsCoef; canvas.width = pageWidth * pdfToCssUnitsCoef;
clear(ctx); canvas.height = pageHeight * pdfToCssUnitsCoef;
} catch(e) { clear(ctx);
failure = 'page setup: '+ e.toString(); } catch(e) {
failure = 'page setup: '+ e.toString();
}
} }
if (!failure) { if (!failure) {
@ -145,6 +149,7 @@ function snapshotCurrentPage(gfx) {
log("done"+ (failure ? " (failed!)" : "") +"\n"); log("done"+ (failure ? " (failed!)" : "") +"\n");
// Set up the next request // Set up the next request
failure = '';
backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0; backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0;
setTimeout(function() { setTimeout(function() {
++currentTask.pageNum, nextPage(); ++currentTask.pageNum, nextPage();