From: Artur Adib Date: Thu, 15 Sep 2011 16:28:58 +0000 (-0700) Subject: Moved helloworld/ to examples/helloworld/ X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=3476364886a922180006b1b2ac5abf7d4afa3d00;p=pdf.js.git Moved helloworld/ to examples/helloworld/ --- diff --git a/examples/helloworld/README.md b/examples/helloworld/README.md new file mode 100644 index 0000000..70d5e76 --- /dev/null +++ b/examples/helloworld/README.md @@ -0,0 +1,13 @@ +## "Hello World" overview + +This example is a minimalistic application of the pdf.js project. The file `helloworld.pdf` is from the GNUpdf project (see [Introduction to PDF at GNUpdf](http://gnupdf.org/Introduction_to_PDF), and contains a simple and human-readable PDF. + + +## Getting started + +Point your browser to `index.html`. Voila. Take a peek at `hello.js` to see how to make basic calls to `pdf.js`. + + +## Additional resources + ++ [GNUpdf - Introduction to PDF](http://gnupdf.org/Introduction_to_PDF) diff --git a/examples/helloworld/hello.js b/examples/helloworld/hello.js new file mode 100644 index 0000000..0bf4631 --- /dev/null +++ b/examples/helloworld/hello.js @@ -0,0 +1,49 @@ +// +// See README for overview +// + + +// +// Ajax GET request for binary files +// (like jQuery's $.get(), but supports the binary type ArrayBuffer) +// +var binaryGet = function(url, callback){ + var xhr = new XMLHttpRequest(); + xhr.open('GET', url); + xhr.mozResponseType = xhr.responseType = 'arraybuffer'; + xhr.expected = (document.URL.indexOf('file:') === 0) ? 0 : 200; + xhr.onreadystatechange = function() { + if (xhr.readyState === 4 && xhr.status === xhr.expected) { + var data = (xhr.mozResponseArrayBuffer || xhr.mozResponse || + xhr.responseArrayBuffer || xhr.response); + + callback(data); + } + }; + xhr.send(null); +} + +// +// This is where the fun happens +// +binaryGet('helloworld.pdf', function(data){ + // + // Instantiate PDFDoc with PDF data + // + var pdf = new PDFDoc(new Stream(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); +}); diff --git a/examples/helloworld/helloworld.pdf b/examples/helloworld/helloworld.pdf new file mode 100644 index 0000000..d98b4e1 --- /dev/null +++ b/examples/helloworld/helloworld.pdf @@ -0,0 +1,68 @@ +%PDF-1.7 + +1 0 obj % entry point +<< + /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< + /Type /Pages + /MediaBox [ 0 0 200 200 ] + /Count 1 + /Kids [ 3 0 R ] +>> +endobj + +3 0 obj +<< + /Type /Page + /Parent 2 0 R + /Resources << + /Font << + /F1 4 0 R + >> + >> + /Contents 5 0 R +>> +endobj + +4 0 obj +<< + /Type /Font + /Subtype /Type1 + /BaseFont /Times-Roman +>> +endobj + +5 0 obj % page content +<< + /Length 44 +>> +stream +BT +70 50 TD +/F1 12 Tf +(Hello, world!) Tj +ET +endstream +endobj + +xref +0 6 +0000000000 65535 f +0000000010 00000 n +0000000079 00000 n +0000000173 00000 n +0000000301 00000 n +0000000380 00000 n +trailer +<< + /Size 6 + /Root 1 0 R +>> +startxref +492 +%%EOF \ No newline at end of file diff --git a/examples/helloworld/index.html b/examples/helloworld/index.html new file mode 100644 index 0000000..c353b6a --- /dev/null +++ b/examples/helloworld/index.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/helloworld/README.md b/helloworld/README.md deleted file mode 100644 index 70d5e76..0000000 --- a/helloworld/README.md +++ /dev/null @@ -1,13 +0,0 @@ -## "Hello World" overview - -This example is a minimalistic application of the pdf.js project. The file `helloworld.pdf` is from the GNUpdf project (see [Introduction to PDF at GNUpdf](http://gnupdf.org/Introduction_to_PDF), and contains a simple and human-readable PDF. - - -## Getting started - -Point your browser to `index.html`. Voila. Take a peek at `hello.js` to see how to make basic calls to `pdf.js`. - - -## Additional resources - -+ [GNUpdf - Introduction to PDF](http://gnupdf.org/Introduction_to_PDF) diff --git a/helloworld/hello.js b/helloworld/hello.js deleted file mode 100644 index 0bf4631..0000000 --- a/helloworld/hello.js +++ /dev/null @@ -1,49 +0,0 @@ -// -// See README for overview -// - - -// -// Ajax GET request for binary files -// (like jQuery's $.get(), but supports the binary type ArrayBuffer) -// -var binaryGet = function(url, callback){ - var xhr = new XMLHttpRequest(); - xhr.open('GET', url); - xhr.mozResponseType = xhr.responseType = 'arraybuffer'; - xhr.expected = (document.URL.indexOf('file:') === 0) ? 0 : 200; - xhr.onreadystatechange = function() { - if (xhr.readyState === 4 && xhr.status === xhr.expected) { - var data = (xhr.mozResponseArrayBuffer || xhr.mozResponse || - xhr.responseArrayBuffer || xhr.response); - - callback(data); - } - }; - xhr.send(null); -} - -// -// This is where the fun happens -// -binaryGet('helloworld.pdf', function(data){ - // - // Instantiate PDFDoc with PDF data - // - var pdf = new PDFDoc(new Stream(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); -}); diff --git a/helloworld/helloworld.pdf b/helloworld/helloworld.pdf deleted file mode 100644 index d98b4e1..0000000 --- a/helloworld/helloworld.pdf +++ /dev/null @@ -1,68 +0,0 @@ -%PDF-1.7 - -1 0 obj % entry point -<< - /Type /Catalog - /Pages 2 0 R ->> -endobj - -2 0 obj -<< - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj - -3 0 obj -<< - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - >> - >> - /Contents 5 0 R ->> -endobj - -4 0 obj -<< - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj - -5 0 obj % page content -<< - /Length 44 ->> -stream -BT -70 50 TD -/F1 12 Tf -(Hello, world!) Tj -ET -endstream -endobj - -xref -0 6 -0000000000 65535 f -0000000010 00000 n -0000000079 00000 n -0000000173 00000 n -0000000301 00000 n -0000000380 00000 n -trailer -<< - /Size 6 - /Root 1 0 R ->> -startxref -492 -%%EOF \ No newline at end of file diff --git a/helloworld/index.html b/helloworld/index.html deleted file mode 100644 index 68a465f..0000000 --- a/helloworld/index.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - -