Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created October 12, 2011 07:33
Show Gist options
  • Save deanhume/1280538 to your computer and use it in GitHub Desktop.
Save deanhume/1280538 to your computer and use it in GitHub Desktop.
PDF.js Hello World
<script type="text/javascript">
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
//
// See README for overview
//
'use strict';
getPdf('your-file-name.pdf', function getPdfHelloWorld(data) {
//
// Instantiate PDFDoc with PDF data
//
var pdf = new PDFDoc(data);
var page = pdf.getPage(1);
var scale = 1.5;
//
// Prepare canvas using PDF page dimensions
//
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = page.height * scale;
canvas.width = page.width * scale;
//
// Render PDF page into canvas context
//
page.startRendering(context);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment