Redo and add more documentation to gh-pages.

This commit is contained in:
Brendan Dahl 2014-04-10 10:01:51 -07:00
parent 80fed15dd3
commit 3ce622a106
16 changed files with 530 additions and 23 deletions

22
docs/config.json Normal file
View File

@ -0,0 +1,22 @@
{
"locals": {
"url": "http://localhost:8080",
"name": "PDF.js Documentation",
"description": ""
},
"require": {
"moment": "moment",
"_": "underscore",
"typogr": "typogr"
},
"jade": {
"pretty": true
},
"markdown": {
"smartLists": true,
"smartypants": true
},
"plugins": [
"./plugins/wintersmith-makerelative.coffee"
]
}

View File

@ -0,0 +1,8 @@
---
title: API
template: layout.jade
---
# API
We're currently working on better API docs, but the API is well documented in [api.js](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js).

7
docs/contents/css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

119
docs/contents/css/main.css Normal file
View File

@ -0,0 +1,119 @@
body {
}
.starter-template {
padding: 0 15px;
}
.navbar-brand {
padding: 4px 15px;
}
.navbar-brand img {
height: 42px;
}
.navbar {
border-color: #e5e7e8;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background-color: #fff;
border: 1px solid #e5e7e8;
border-width: 0 1px;
position: relative;
top: 1px;
}
footer {
padding-top: 40px;
padding-bottom: 40px;
margin-top: 100px;
color: #777;
text-align: center;
border-top: 1px solid #E5E5E5;
}
/* code styling */
code {
font-family: 'Anonymous Pro', monospace;
font-size: 0.85em;
color: #000;
}
pre code {
display: block;
line-height: 1.1;
}
p code {
padding: 0.1em 0.3em 0.2em;
border-radius: 0.3em;
position: relative;
top: -0.15em;
background: #444;
color: #fff;
white-space: nowrap;
}
/* syntax hl stuff */
code.lang-markdown {
color: #424242;
}
code.lang-markdown .header,
code.lang-markdown .strong {
font-weight: bold;
}
code.lang-markdown .emphasis {
font-style: italic;
}
code.lang-markdown .horizontal_rule,
code.lang-markdown .link_label,
code.lang-markdown .code,
code.lang-markdown .header,
code.lang-markdown .link_url {
color: #555;
}
code.lang-markdown .blockquote,
code.lang-markdown .bullet {
color: #bbb;
}
/* Tomorrow Theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
.tomorrow-comment, pre .comment, pre .title {
color: #8e908c;
}
.tomorrow-red, pre .variable, pre .attribute, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo {
color: #c82829;
}
.tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .literal, pre .params, pre .constant {
color: #f5871f;
}
.tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute {
color: #eab700;
}
.tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata {
color: #718c00;
}
.tomorrow-aqua, pre .css .hexcolor {
color: #3e999f;
}
.tomorrow-blue, pre .function, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title {
color: #4271ae;
}
.tomorrow-purple, pre .keyword, pre .javascript .function {
color: #8959a8;
}

View File

@ -0,0 +1,65 @@
---
title: Examples
template: layout.jade
---
## Hello World Walkthrough
[Full source](https://github.com/mozilla/pdf.js/tree/master/examples/helloworld)
PDF.js heavily relies on the use of [Promises](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise). If promises are new to you, it's recommended you become familiar with them before continuing on.
### Document
The object structure of PDF.js loosely follows the structure of an actual PDF. At the top level there is a document object. From the document, more information and individual pages can be fetched. To get the document:
```js
PDFJS.getDocument('helloworld.pdf')
```
Remember though that PDF.js uses promises, so the above will return a promise that is resolved with the document object.
```js
PDFJS.getDocument('helloworld.pdf').then(function(pdf)) {
// you can now use *pdf* here
});
```
### Page
Now that we have the document, we can get a page. Again, this uses promises.
```js
pdf.getPage(1).then(function(page) {
// you can now use *page* here
});
```
### Rendering the Page
Each PDF page has its own viewport which defines the size in pixels(72DPI) and initial rotation. By default the viewport is scaled to the original size of the PDF, but this can be changed by modifying the viewport. When the viewport is created an initial transformation matrix will also be created that takes into account the desired scale, rotation, and it transforms the coordinate system (the 0,0 point in PDF documents the bottom-left whereas canvas 0,0 is top-left).
```js
var scale = 1.5;
var viewport = page.getViewport(scale);
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);
```
Alternatively, if you want the canvas to render to a certain pixel size you could do the following:
```js
var desiredWidth = 100;
var viewport = page.getViewport(1);
var scale = desiredWidth / viewport.width;
var scaledViewport = page.getViewport(scale);
```

View File

@ -0,0 +1,114 @@
---
title: Getting Started
template: layout.jade
---
# Getting Started
An introduction to PDF.js with examples.
## Introduction
Before downloading PDF.js please take a moment to understand the different layers of the PDF.js project.
<table class="table">
<thead>
<tr>
<th>Layer</th>
<th>About</th>
</tr>
</thead>
<tbody>
<tr>
<td>Core</td>
<td>The core layer is where a binary PDF is parsed and interpreted. This layer is the foundation for all subsequent layers. It is not documented here because using it directly is considered an advanced usage and the API is likely to change. For an example of using the core layer see the [PDF Object Browser](https://github.com/brendandahl/pdf.js.utils/tree/master/browser)
</td>
</tr>
<tr>
<td>Display</td>
<td>The display layer takes the core layer and exposes an easier to use API to render PDFs and get other information out of a document. This API is what the version number is based on.</td>
</tr>
<tr>
<td>Viewer</td>
<td>The viewer is built on the display layer and is the UI for PDF viewer in Firefox and the other browser extensions within the project. It can be a good starting point for building your own viewer. *However, we do ask if you plan to embed the viewer in your own site, that it not just be an unmodified version. Please re-skin it or build upon it.*</td>
</tr>
</tbody>
</table>
## Download
<div class="row">
<div class="col-md-6">
<h3>Pre-built</h3>
<p>
Includes the generic build of PDF.js and the viewer.
</p>
<span class="btn-group-vertical centered">
<a type="button" class="btn btn-primary" href="https://github.com/mozilla/pdf.js/releases/download/vSTABLE_VERSION/pdfjs-STABLE_VERSION-dist.zip">Stable (vSTABLE_VERSION)</a>
<a type="button" class="btn btn-warning" href="https://github.com/mozilla/pdf.js/releases/download/vBETA_VERSION/pdfjs-BETA_VERSION-dist.zip">Beta (vBETA_VERSION)</a>
</span>
</div>
<div class="col-md-6">
<h3>Source</h3>
To get a local copy of the current code, clone it using git:
<pre><code>$ git clone git://github.com/mozilla/pdf.js.git pdfjs
$ cd pdfjs
</code></pre>
</div>
</div>
## File Layout Overview
### Prebuilt
```
├── LICENSE
├── build/
│   ├── pdf.js - display layer
│   └── pdf.worker.js - core layer
└── web/
├── cmaps/ - character maps(required by core)
├── compatibility.js - polyfills for missing features
├── compressed.tracemonkey-pldi-09.pdf - test pdf
├── debugger.js - helpful pdf debugging features
├── images/ - images for the viewer and annotation icons
├── l10n.js - localization
├── locale/ - translation files
├── viewer.css - viewer style sheet
├── viewer.html - viewer html
└── viewer.js - viewer layer
```
### Source
```
├── AUTHORS
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build/ - output of build steps (empty)
├── docs/ - this
├── examples/ - bare bones examples
├── extensions/ - various browser extensions
├── external/ - third party code
├── l10n/ - translation files
├── make.js - build script
├── package.json
├── src/
│   ├── core/ - core layer
│   ├── display/ - display layer
│   ├── images/
│   ├── pdf.js - wrapper file that everything is bundled into
│   ├── shared/ - shared code between core and display layers
│   └── worker_loader.js - used for developer builds to load worker files
├── test/ - reference, unit, and font tests
└── web/ - viewer layer
```
## Trying the Viewer
With the prebuilt or source version open `web/viewer.html` in a browser and the test pdf should load. Note: the worker is not enabled for file:// urls, so use a server. If you're using the source build and have node, you can run `node make server`.
## More Information
For a further walkthrough of a minimal viewer see the [hello world example](/examples/). More documentation can be found in our [wiki](https://github.com/mozilla/pdf.js/wiki) too.

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns="http://www.w3.org/2000/svg"
width="64"
height="64">
<path
d="M 4.8364028,0.4891005 32.096378,4.5726641 59.163597,0.4891005 54.680408,57.805097 32.096378,63.510899 8.3116209,57.805097 z"
style="fill:#e5e7e8;fill-opacity:1;fill-rule:nonzero;stroke:#cccccc" />
<path
d="M 32.096378,10.745857 53.925414,6.8301117 51.016574,53.81906 32.096378,58.517955 z"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" />
<rect
width="34.027256"
height="19.136194"
x="3.7557135"
y="22.431904"
style="fill:#ff2600;fill-opacity:1;fill-rule:nonzero;stroke:none" />
<rect
width="23.480518"
height="19.136194"
x="36.763767"
y="22.431904"
style="fill:#ff501a;fill-opacity:1;fill-rule:nonzero;stroke:none" />
<g transform="matrix(0.42778543,0,0,0.42778543,58.617711,9.6737064)">
<path
d="m -120.53125,34.59375 0,35.1875 6.53125,0 0,-5.9375 0,-5.96875 8.875,0 4.15625,-3.71875 0,-7.71875 0,-7.71875 -4.21875,-4.125 -15.34375,0 z m 6.53125,6.8125 6.21875,0 0,10.21875 -6.21875,0 0,-10.21875 z"
style="fill:#ffffff;fill-opacity:1" />
<path
d="m -98.125,34.59375 0,35.1875 16.125,0 3.75,-3.625 0,-27.96875 -3.96875,-3.59375 -15.90625,0 z m 6.8125,6.8125 6.8125,0 0,21.5625 -6.8125,0 0,-21.5625 z" id="path3056"
style="fill:#ffffff;fill-opacity:1" />
<path
d="m -74.856072,34.602929 c 5.485697,0 10.971394,0 16.457091,0 0,2.269943 0,4.539887 0,6.80983 -3.404915,0 -6.809831,0 -10.214746,0 0,2.472069 0,4.944138 0,7.416206 2.93201,0.110496 5.864021,-0.110494 8.796031,0 l 0,3.366025 0,3.375914 c -2.93201,0.110495 -5.864021,-0.110495 -8.796031,0 l 0,7.146446 0,7.069702 c -2.080782,0 -4.161563,0 -6.242345,0 0,-11.728041 0,-23.456082 0,-35.184123 z"
style="fill:#ffffff;fill-opacity:1" />
<path
d="m -42.8813,67.942723 -2.181762,-1.844329 c 0,-1.986871 0,-3.973742 0,-5.960613 2.175363,6.7e-4 4.350725,0.0013 6.526088,0.002 0,0.94581 0,1.891619 0,2.837429 1.891619,0 3.783239,0 5.674858,0 0,-9.458098 0,-18.916195 0,-28.374293 2.175363,-1.26e-4 4.350725,-2.52e-4 6.526088,-3.78e-4 0,10.498614 0,20.997229 0,31.495843 -1.454508,1.229554 -2.909019,2.459106 -4.363529,3.688658 -3.333325,0 -6.666651,0 -9.999976,0 -0.727237,-0.614768 -1.454563,-1.229595 -2.181767,-1.844308 z"
style="fill:#ffffff;fill-opacity:1" />
<path
d="m -21.316836,67.942723 -2.109122,-1.844329 0,-5.978379 c 2.061011,0 4.392437,0.01978 6.453448,0.01978 0,0.94581 0,1.891619 0,2.837429 2.269943,0 4.539887,0 6.80983,0 0,-2.459105 0,-4.918211 0,-7.377316 -3.196954,0 -6.393909,0 -9.590863,0 l -3.745055,-3.688659 0,-6.80983 0,-6.80983 3.745055,-3.688658 c 3.863156,0 7.726313,0 11.5894692,0 l 4.2511106,3.688658 c -0.00204,1.797039 -0.00472,3.594077 -0.00737,5.391115 -2.0807816,0 -4.1615632,0 -6.2423448,0 0,-0.756648 0,-1.513295 0,-2.269943 -2.269943,0 -4.539887,0 -6.80983,0 0,2.459105 0,4.918211 0,7.377316 2.990126,0 5.980253,0 8.9703792,0 1.3605964,1.204585 4.0817956,3.613749 4.0817956,3.613749 0,4.555246 0,9.110492 0,13.665738 l -2.0892845,1.858745 -2.0892901,1.858745 -5.5180792,0 -5.51808,0 z"
style="fill:#ffffff;fill-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

14
docs/contents/index.md Normal file
View File

@ -0,0 +1,14 @@
---
title: PDF.js
template: layout.jade
---
<h1 class="text-center">PDF.js</h1>
<p class="text-center" style="font-size: 20px">A general-purpose, web standards-based platform for parsing and rendering PDFs.
</p>
<p class="text-center">
<a type="button" class="btn btn-lg btn-default" href="getting_started/#download">Download</a>
<a type="button" class="btn btn-lg btn-default" href="web/viewer.html">Demo</a>
<a type="button" class="btn btn-lg btn-default" href="https://github.com/mozilla/pdf.js">Github Project</a>
</p>

6
docs/contents/js/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

4
docs/contents/js/jquery-2.1.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,15 @@
module.exports = (env, callback) ->
count = (string, substr) ->
num = pos = 0
return 1/0 unless substr.length
num++ while pos = 1 + string.indexOf(substr, pos)
num
env.helpers.makeRelative = (source, dest) ->
return dest unless dest.indexOf("/") == 0
depth = count(source, '/') # 1 being /
ret = ""
ret += "../" while depth = depth - 1
ret + dest.substr(1)
callback()

52
docs/templates/layout.jade vendored Normal file
View File

@ -0,0 +1,52 @@
- makeRelative = env.helpers.makeRelative
doctype html
html(lang='en')
head
meta(charset='utf-8')
meta(name='viewport', content='width=device-width, initial-scale=1.0')
meta(name='description', content='')
meta(name='author', content='')
link(rel='shortcut icon', href=makeRelative(page.url, '/images/favicon.ico'))
title=page.title
// Bootstrap core CSS
link(href=makeRelative(page.url, '/css/bootstrap.min.css'), rel='stylesheet')
// Custom styles for this template
link(href=makeRelative(page.url, '/css/main.css'), rel='stylesheet')
body
header.navbar.navbar-default.navbar-static-top
.container
.navbar-header
button.navbar-toggle(type='button', data-toggle='collapse', data-target='.navbar-collapse')
span.icon-bar
span.icon-bar
span.icon-bar
a.navbar-brand(href='#')
img(src=makeRelative(page.url, '/images/logo.svg'))
.collapse.navbar-collapse
ul.nav.navbar-nav
li(class=(page.url === '/' ? 'active' : ''))
a(href=makeRelative(page.url, '/')) Home
li(class=(page.url === '/getting_started/' ? 'active' : ''))
a(href=makeRelative(page.url, '/getting_started/')) Getting Started
li(class=(page.url === '/examples/' ? 'active' : ''))
a(href=makeRelative(page.url, '/examples/')) Examples
li
a(href='https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions') FAQ
li(class=(page.url === '/api/' ? 'active' : ''))
a(href=makeRelative(page.url, '/api/')) API
.container
.starter-template
section.content!= typogr(page.html).typogrify()
.container
footer
p &copy;Mozilla and individual contributors
:markdown
PDF.js is licensed under [Apache](https://github.com/mozilla/pdf.js/blob/master/LICENSE),
documentation is licensed under [CC BY-SA 2.5](http://creativecommons.org/licenses/by-sa/2.5/)
// Bootstrap core JavaScript
script(src=makeRelative(page.url, '/js/jquery-2.1.0.min.js'))
script(src=makeRelative(page.url, '/js/bootstrap.min.js'))

74
make.js
View File

@ -23,7 +23,16 @@
require('./external/shelljs/make');
var builder = require('./external/builder/builder.js');
var crlfchecker = require('./external/crlfchecker/crlfchecker.js');
var wintersmith = require('wintersmith');
var path = require('path');
var fs = require('fs');
var CONFIG_FILE = 'pdfjs.config';
var config = JSON.parse(fs.readFileSync(CONFIG_FILE));
// Defined by buildnumber target.
var BUILD_NUMBER,
VERSION;
var ROOT_DIR = __dirname + '/', // absolute path to project's root
BUILD_DIR = 'build/',
@ -109,6 +118,7 @@ target.generic = function() {
defines: defines,
copy: [
[COMMON_WEB_FILES, GENERIC_DIR + '/web'],
['LICENSE', GENERIC_DIR],
['external/webL10n/l10n.js', GENERIC_DIR + '/web'],
['web/viewer.css', GENERIC_DIR + '/web'],
['web/compatibility.js', GENERIC_DIR + '/web'],
@ -156,19 +166,42 @@ target.web = function() {
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/');
cp(CHROME_BUILD_DIR + '/*.crx', FIREFOX_BUILD_DIR + '/*.rdf',
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chromium/');
cp('web/index.html.template', GH_PAGES_DIR + '/index.html');
cp('-R', 'test/features', GH_PAGES_DIR);
cp('-R', B2G_BUILD_DIR, GH_PAGES_DIR + EXTENSION_SRC_DIR + 'b2g/');
cd(GH_PAGES_DIR);
exec('git init');
exec('git remote add origin ' + REPO);
exec('git add -A');
exec('git commit -am "gh-pages site created via make.js script"');
exec('git branch -m gh-pages');
var env = wintersmith('docs/config.json');
env.build(GH_PAGES_DIR, function (error) {
if (error) {
throw error;
}
sed('-i', /STABLE_VERSION/g, config.stableVersion,
GH_PAGES_DIR + '/getting_started/index.html');
sed('-i', /BETA_VERSION/g, config.betaVersion,
GH_PAGES_DIR + '/getting_started/index.html');
echo('Done building with wintersmith.');
echo();
echo('Website built in ' + GH_PAGES_DIR);
cd(GH_PAGES_DIR);
exec('git init');
exec('git remote add origin ' + REPO);
exec('git add -A');
exec('git commit -am "gh-pages site created via make.js script"');
exec('git branch -m gh-pages');
echo();
echo('Website built in ' + GH_PAGES_DIR);
});
};
target.dist = function() {
target.generic();
config.stableVersion = config.betaVersion;
config.betaVersion = VERSION;
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
cd(GENERIC_DIR);
var distFilename = 'pdfjs-' + VERSION + '-dist.zip';
exec('zip -r ' + ROOT_DIR + BUILD_DIR + distFilename + ' *');
echo('Built distribution file: ' + distFilename);
cd(ROOT_DIR);
};
//
@ -285,7 +318,7 @@ target.bundle = function(args) {
}
var bundle = cat(SRC_FILES),
bundleVersion = EXTENSION_VERSION,
bundleVersion = VERSION,
bundleBuild = exec('git log --format="%h" -n 1',
{silent: true}).output.replace('\n', '');
@ -487,11 +520,6 @@ target.minified = function() {
// Extension stuff
//
var EXTENSION_BASE_VERSION = '0ac55ac879d1c0eea9c0d155d5bbd9b11560f631',
EXTENSION_VERSION_PREFIX = '0.8.',
EXTENSION_BUILD_NUMBER,
EXTENSION_VERSION;
//
// make extension
//
@ -511,13 +539,13 @@ target.buildnumber = function() {
echo('### Getting extension build number');
var lines = exec('git log --format=oneline ' +
EXTENSION_BASE_VERSION + '..', {silent: true}).output;
config.baseVersion + '..', {silent: true}).output;
// Build number is the number of commits since base version
EXTENSION_BUILD_NUMBER = lines ? lines.match(/\n/g).length : 0;
BUILD_NUMBER = lines ? lines.match(/\n/g).length : 0;
echo('Extension build number: ' + EXTENSION_BUILD_NUMBER);
echo('Extension build number: ' + BUILD_NUMBER);
EXTENSION_VERSION = EXTENSION_VERSION_PREFIX + EXTENSION_BUILD_NUMBER;
VERSION = config.versionPrefix + BUILD_NUMBER;
};
//
@ -612,9 +640,9 @@ target.firefox = function() {
});
// Update the build version number
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
FIREFOX_BUILD_DIR + '/install.rdf');
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
FIREFOX_BUILD_DIR + '/update.rdf');
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, FIREFOX_STREAM_CONVERTER_ID,
@ -745,7 +773,7 @@ target.mozcentral = function() {
cp(DEFAULT_LOCALE_FILES, MOZCENTRAL_L10N_DIR);
// Update the build version number
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
MOZCENTRAL_EXTENSION_DIR + 'README.mozilla');
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, MOZCENTRAL_STREAM_CONVERTER_ID,
@ -845,7 +873,7 @@ target.chromium = function() {
cleanupJSSource(CHROME_BUILD_CONTENT_DIR + '/web/viewer.js');
// Update the build version number
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
CHROME_BUILD_DIR + '/manifest.json');
// Allow PDF.js resources to be loaded by adding the files to

View File

@ -5,6 +5,12 @@
"jshint": "2.4.x",
"yargs": "~1.2.1"
},
"devDependencies": {
"wintersmith": "2.0.x",
"moment": "2.3.x",
"underscore": "1.4.x",
"typogr": "0.5.x"
},
"scripts": {
"test": "node make lint"
},

6
pdfjs.config Normal file
View File

@ -0,0 +1,6 @@
{
"betaVersion": "0.8.1114",
"stableVersion": "0.8.1334",
"baseVersion": "0ac55ac879d1c0eea9c0d155d5bbd9b11560f631",
"versionPrefix": "0.8."
}