Commit 838437c9 authored by Fred Chasen's avatar Fred Chasen

Setup puppeteer

parent 85717752
The MIT License (MIT)
Copyright (c) 2018 Adam Hyde
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var index = require('./routes/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.use('/users', users);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
#!/usr/bin/env node
const Paged = require('pagedjs');
const puppeteer = require('puppeteer');
const program = require('commander');
// const temp = require("temp").track();
const path = require('path');
const fs = require('fs');
const replaceExt = require('replace-ext');
const express = require('express');
const app = express();
const PORT = 9999;
program
.version(require('../package.json').version)
.arguments('[inputPath]')
.option('-i, --inputs [inputs]', 'Inputs')
.option('-o, --output [output]', 'Output')
.option('-d, --debug', 'Debug')
.option('-l, --landscape', 'Landscape printing', false)
.option('-s, --page-size [size]', 'Print to Page Size [size]')
.option('-w, --width [size]', 'Print to Page Width [width] in MM')
.option('-h --height [size]', 'Print to Page Height [weight] in MM')
// .option('-m, --page-margin [margin]', 'Print with margin [margin]')
// .option('-n, --hyphenate [lang]', 'Hyphenate with language [language], defaults to "en-us"')
// .option('-hi, --hypher_ignore [str]', 'Ignore passed element selectors, such as ".class_to_ignore, h1"')
// .option('-ho, --hypher_only [str]', 'Only hyphenate passed elements selector, such as ".hyphenate, aside"')
// .option('-e, --encoding [type]', 'Set the encoding of the input html, defaults to "utf-8"')
.option('-t, --timeout [ms]', 'Set a max timeout of [ms]')
.parse(process.argv);
let input = program.inputs || program.args[0];
let dir = process.cwd();
let relativePath = path.resolve(dir, input);
let output;
let tmpFile, tmpPath;
// var hyphenator;
// var hyphenateOptions;
if (!input) {
console.error("You must include an input path");
return process.exit(1);
}
if (['.html', '.xhtml'].indexOf(path.extname(relativePath)) === -1) {
console.error("Must pass a html or xhtml file as input");
return process.exit(1);
}
try {
fs.accessSync(relativePath, fs.F_OK);
} catch (e) {
console.error("Input cannot be found", e);
return process.exit(1);
}
if (typeof(program.output) === "string") {
output = path.resolve(dir, program.output);
} else if (typeof(program.output) !== "undefined") {
output = './' + replaceExt(path.basename(input), '.pdf');
} else {
output = "output.pdf";
}
console.log("output", output, program.output);
/*
if (program.hyphenate) {
hyphenateOptions = {
ignore: program.hypher_ignore || undefined,
only: program.hypher_only || undefined,
encoding: program.encoding || undefined
}
tmpPath = replaceExt(relativePath, ".hyphenated.html");
// tmpFile = temp.openSync({suffix: '.html'});
// tmpPath = tmpFile.path;
// Create a new Hyphenator, with passed language
hyphenator = new Hyphenator(program.hyphenate);
hyphenator.process(relativePath, tmpPath, hyphenateOptions);
console.log("Hyphenated for", typeof(program.hyphenate) === "string" ? program.hyphenate : "en-us");
if (program.debug && tmpPath) {
console.log("Hyphenated file at:", tmpPath);
}
}
*/
(async () => {
const browser = await puppeteer.launch({
// headless: false,
// args: ['--no-sandbox', '--allow-file-access-from-files', '--enable-local-file-accesses']
});
const page = await browser.newPage();
let relativePath = path.resolve(dir, input);
let dirname = path.dirname(relativePath);
let basename = path.basename(relativePath);
app.use("/print", express.static(dirname))
let scriptPath = path.resolve(dir, "./node_modules/pagedjs/dist/");
app.use("/polyfill", express.static(scriptPath))
let server = app.listen(PORT);
await page.goto(`http://localhost:${PORT}/print/${basename}`);
await page.addScriptTag({
url: `http://localhost:${PORT}/polyfill/paged.polyfill.js`
});
await page.exposeFunction('onPagesRendered', async (msg, width, height, orientation) => {
console.log(msg);
console.log("Saved to", output);
let pdf = await page.pdf({
path: output,
printBackground: true,
displayHeaderFooter: false,
width: width,
height: height,
orientation: orientation,
margin: {
top: 0,
right: 0,
bottom: 0,
left: 0,
},
// format: 'A4'
}).catch((e) => {
console.error(e);
})
server.close();
await browser.close();
});
})();
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('demo:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
This diff is collapsed.
{
"name": "demo",
"version": "0.0.0",
"private": true,
"name": "pagedjs-cli",
"version": "0.0.1",
"author": "Fred Chasen",
"license": "MIT",
"homepage": "https://pagedmedia.org",
"repository": {
"type": "git",
"url": "https://gitlab.pagedmedia.org/polyfills/pagedjs-cli.git"
},
"scripts": {
"start": "node ./bin/www"
"start": "./bin/paged"
},
"dependencies": {
"body-parser": "~1.17.1",
"cookie-parser": "~1.4.3",
"debug": "~2.6.3",
"express": "~4.15.2",
"jade": "~1.11.0",
"morgan": "~1.8.1",
"serve-favicon": "~2.4.2"
"commander": "^2.15.1",
"express": "^4.16.3",
"pagedjs": "0.0.1",
"puppeteer": "^1.2.0",
"replace-ext": "^1.0.0"
}
}
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
module.exports = router;
# Aurorae
Test of different generating PDF tools using HTML and CSS.
* PDF reactor : [http://www.pdfreactor.com/](http://www.pdfreactor.com/)
* Prince XML : [https://www.princexml.com/](https://www.princexml.com/)
## Book
The book "Auroræ : their characters and spectra" by J. Rand Capron is used for comparaison.
The original (x)HTML file is part of the[Gutenberg project](http://www.gutenberg.org/), it has been transformed for the needs.
[I'm an inline-style link](http://www.gutenberg.org/ebooks/56159?msg=welcome_stranger)
Licence : Project Gutenberg License
Title: Auroræ: Their Characters and Spectra
Release Date: December 10, 2017 [EBook #56159]
Language: English
Character set encoding: UTF-8
## Files
`index.html` : the Auroræ book
Before using, you must change the path of the CSS and javascript files according to the tool tested.
`book.css` : commun CSS for all tools (styling + footnotes + page breaks)
`fonts` and `images` folders contain the resources used in all tools
Each tools have a specific file with :
* `layout-*.html` : CSS contain features for layout
* `script.html` : most tools accept javascript with proprietary access to layout information
* `aurorae-*.pdf` : the PDF generated
## TODO
* add other test-tools
* Vivliostyle
* Antennahouse
* add table comparaison
* add images, plates and figures + list of figures
* add index
* add cross references
* Styling tables
* all table in chapters
* add border-bottom when table is break
* #table-appa-01 > 2 column
* add mathematical support + Styling
* balancing text in titles
* clean HTML
* add span Greek
* transform sidenotes into span
* remove all !important in CSS
This diff is collapsed.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
SIL Open Font License v1.1
====================================================
Preamble
----------
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
Definitions
-------------
`"Font Software"` refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
`"Reserved Font Name"` refers to any names specified as such after the
copyright statement(s).
`"Original Version"` refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
`"Modified Version"` refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
`"Author"` refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
Permission & Conditions
------------------------
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1. Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2. Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3. No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4. The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5. The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
Termination
-----------
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
# Daubenton
![specimen1](https://github.com/velvetyne/daubenton/blob/master/documentation/images/daubenton.jpg)
![specimen2](https://github.com/velvetyne/daubenton/blob/master/documentation/images/histoirenaturelle.jpg)
Daubenton is a serif font designed by Olivier Dolbeau. Daubenton is a revival of the engraved letters of the façade of the Great Evolution Gallery of the Natural History Museum in Paris. Daubenton was the name of the first director of the Museum.
Contribute or download it on [Velvetyne Type Foundry](http://velvetyne.fr/fonts/daubenton/).
## License
Daubenton is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at
http://scripts.sil.org/OFL
## Repository Layout
This font repository follows the Unified Font Repository v2.0,
a standard way to organize font project source files. Learn more at
https://github.com/raphaelbastide/Unified-Font-Repository
This diff is collapsed.
This diff is collapsed.
@font-face {
font-family: 'daubenton';
src: url('daubentonwebfont.woff') format('woff'),
url('daubentonwebfont.ttf') format('truetype'),
url('daubentonwebfont.svg') format('svg');
font-weight: normal;
font-style: normal;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# Font Squirrel Font-face Generator Configuration File
# Upload this file to the generator to recreate the settings
# you used to create these fonts.
{"mode":"optimal","formats":["woff","woff2"],"tt_instructor":"default","fix_gasp":"xy","fix_vertical_metrics":"Y","metrics_ascent":"","metrics_descent":"","metrics_linegap":"","add_spaces":"Y","add_hyphens":"Y","fallback":"none","fallback_custom":"100","options_subset":"basic","subset_custom":"","subset_custom_range":"","subset_ot_features_list":"","css_stylesheet":"stylesheet.css","filename_suffix":"-webfont","emsquare":"2048","spacing_adjustment":"0"}
\ No newline at end of file
/*Notes about grid:
Columns: 12
Grid Width: 825px
Column Width: 55px
Gutter Width: 15px
-------------------------------*/
.section {margin-bottom: 18px;
}