Giter Club home page Giter Club logo

relaxed's Introduction

ReLaXed

Build Status

ReLaXed creates PDF documents interactively using HTML or Pug (a shorthand for HTML). It allows complex layouts to be defined with CSS and JavaScript, while writing the content in a friendly, minimal syntax close to Markdown or LaTeX.

Here it is in action in the Atom editor:

And here are a few output examples:

Book - source / PDF Letter - Source / PDF Resume - Source / PDF Visit card - Source / PDF
Slides - Source / PDF Report - Source / PDF Paper - Source / PDF Poster - Source / PDF

ReLaXed has support for Markdown, LaTeX-style mathematical equations (via MathJax), CSV conversion to HTML tables, plot generation (via Vega-Lite or Chart.js), and diagram generation (via mermaid). Many more features can be added simply by importing an existing JavaScript or CSS framework.

Installing ReLaXed

Install ReLaXed via NPM with this command (do not use sudo):

npm i -g relaxedjs

This will provide your system with the relaxed command. If the installation fails, refer to the troubleshooting page. You can also use ReLaXed via Docker (see this repository)

Getting started

To start a project, create a new document my_document.pug with the following Pug content:

h1 My document's title
p A paragraph in my document

Then start ReLaXed from a terminal:

relaxed my_document.pug

ReLaXed will generate my_document.pdf from my_document.pug, then watch its directory and subdirectories so that every time a file changes, my_document.pdf will be re-generated.

It is also possible to generate the PDF file just once, with no sub-sequent file-watching, with this command:

relaxed my_document.pug --build-once

To go further:

Why yet another PDF document creator?

Many of us prefer markup languages (Markdown, LaTeX, etc.) to GUI document-editors like MS Office or Google Docs. This is because markup languages make it easier to quickly write documents in a consistent style.

However, Markdown is limited to the title/sections/paragraphs structure, and LaTeX has obscure syntax and errors that also make it difficult to stray from the beaten track.

On the other hand, web technologies have never looked so good.

  • Beautiful CSS frameworks make sure your documents look clean and modern.
  • There are JavaScript libraries for pretty much anything: plotting, highlight code, rendering equations...
  • Millions of people (and growing) know how to use these.
  • Shorthand languages like Pug and SCSS are finally making it fun to write HTML and CSS.
  • (Headless) web browsers can easily turn web documents into PDF, on any platform.

ReLaXed is an attempt at finding the most comfortable way to leverage this for desktop PDF creation.

How ReLaXed works

ReLaXed consists of a few lines of code binding together other software. It uses Chokidar to watch the file system. When a file is changed, several JavaScript libraries are used to compile SCSS, Pug, Markdown, and diagram files (mermaid, flowchart.js, Chart.js) into an HTML page which is then printed to a PDF file by a headless instance of Chromium (via Puppeteer).

Using it as a Node Module

MasterToPDF.js is exposed by default as main package, which can be used directly.

An Example:

const { masterToPDF } = require('relaxedjs');
const puppeteer = require('puppeteer');
const plugins = require('relaxedjs/src/plugins');
const path = require('path');

class HTML2PDF {
  constructor() {
    this.puppeteerConfig = {
      headless: true,
      args: [
        '--no-sandbox',
        '--disable-translate',
        '--disable-extensions',
        '--disable-sync',
      ],
    };

    this.relaxedGlobals = {
      busy: false,
      config: {},
      configPlugins: [],
    };

    this._initializedPlugins = false;
  }

  async _initializePlugins() {
    if (this._initializedPlugins) return; // Do not initialize plugins twice
    for (const [i, plugin] of plugins.builtinDefaultPlugins.entries()) {
      plugins.builtinDefaultPlugins[i] = await plugin.constructor();
    }
    await plugins.updateRegisteredPlugins(this.relaxedGlobals, '/');

    const chrome = await puppeteer.launch(this.puppeteerConfig);
    this.relaxedGlobals.puppeteerPage = await chrome.newPage();
    this._initializedPlugins = true;
  }

  async pdf(templatePath, json_data, tempHtmlPath, outputPdfPath) {
    await this._initializePlugins();
    if (this._initializedPlugins) {
      // Paths must be absolute
      const defaultTempHtmlPath = tempHtmlPath || path.resolve('temp.html');
      const defaultOutputPdfPath =
        outputPdfPath || path.resolve('output.pdf');

      await masterToPDF(
        templatePath,
        this.relaxedGlobals,
        defaultTempHtmlPath,
        defaultOutputPdfPath,
        json_data
      );
    }
  }
}

module.exports = new HTML2PDF();

Usage:

const HTML2PDF = require('./HTML2PDF.js');
(async () => {
    await HTML2PDF.pdf('./template.pug', {"a":"b", "c":"d"});
})();

Contribute!

ReLaXed is an open-source framework originally written by Zulko and released on Github under the ISC licence. Everyone is welcome to contribute!

For bugs and feature requests, open a Github issue. For support or Pug/HTML-related questions, ask on Stackoverflow or on the brand new reddit/r/relaxedjs forum, which can be used for any kind of discussion.

Projects members:

License

ISC

relaxed's People

Contributors

benperiton avatar chocolateboy avatar danielruf avatar drew-s avatar flakebi avatar glynnforrest avatar hinok avatar jwmann avatar luisdanielroviracontreras avatar mayank avatar nikhilmitrax avatar rcralph avatar superd22 avatar tht13 avatar veggiedefender avatar zulko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

relaxed's Issues

What I should know to use ReLaXed and other questions about the pug syntax.

I am a data scientist that considers writing a library for R that will offer an alternative document generation pipeline that would replace the usual path of R -> pander -> pandoc -> xelatex -> pdf. Unfortunately, in short, I have never written anything to be executed directly by the Web browser. I don't program in JavaScript and I barely know what CSS is for. (I am familiar with the idea of having nested style hierarchy; I simply never used a CSS implementation of it. )

I know LaTeX and I spent a great deal of time writing or gluing together different document rendering systems for use with the statistical output.

  1. What path should I take learn how to efficiently use ReLaXed (and pug) for scientific data reporting?

The first paragraph on the Pug's "Getting Started" page says

The general rendering process of Pug is simple. pug.compile() will compile the Pug source code into a JavaScript function that takes a data object (called “locals”) as an argument.

  1. I understand, that the pug.compile() is a JavaScript call. Do I need to learn JavaScript to use the ReLaXed? Does a pug file format actually follows a JavaScript syntax (like JSON), but then what happened to the semicolons?

  2. What is the minimal Hello World document in ReLaXed? Is it p Hello World!? If so, why you never use the syntax p <text> in the examples? (The closest I can find is p.\n<paragraph text>).

  3. The source pug files have lines that start with coma, like .main-text or .title. The dot before .main-text and a nested structure present in some pug files suggests it is a property call of some default "root-document" object, but it is only my guess. What is the name of words that are prefixed by the comma? Where can I look up the meaning of them?

  4. There are lines that are prefixed with a colon, like :markdown-it(html=true). Is it also some sort of property call, (perhaps for a static member, like in C++)?

  5. Some lines start neither with coma nor colon, like style or h1#title Beautiful PDF documents with web technologies. What is the difference between them and the lines prefixed with . and :?

  6. You seem to use # for something like the separation between a keyword and its arguments, like in h1#title Beautiful PDF documents with web technologies or td.positive #[i.icon.checkmark] Totally working. Am I right? (If not, what is the meaning of the #?)

  7. All the pug documents in the examples are nicely indented with spaces. Do spaces have a syntactic meaning, like in Python, or are they simply there for readability, like in C or JavaScript?

[Discuss] Maybe we can use react or jsx as DSL

In my opinions, there is not many people use pugjs. And maybe we can use react as second choose. We can write some logic code, like below

const mockData = [{ name: 'stephen', sex: 'male', age: 25 }, { name: 'stephen', sex: 'male', age: 25 }, { name: 'stephen', sex: 'male', age: 25 }, { name: 'stephen', sex: 'male', age: 25 }];

const Item = props => (
  <div>
    <p>name: {props.name}</p>
    <p>sex: {props.male}</p>
    <p>age: {props.age}</p>
  </div>
);

const List = props => (
  <div>
    { mockData.map((item, index) => <Item name={item.name} male={item.male} age={item.age} key={index} />) }
  </div>
);

That is more powerful than just HTML, and can provide kinds of scenes to use.

Plugin system

I created a plugin system: plugin. I have not done a pull request yet, as the plugin directory location is arbitrary, it is inside the relaxed src directory. I want to set a user configuration directory for things like plugins (~/.relaxed/plugins), global templates, global configurations, etc. But before I do that I would like for some feedback on the plugin system. Plugins are loaded from src/plugins/<plugin>/index.js and are formatted gist. This system was made for my bibliography system so that it does not run during the puppeteer runtime, as per @Zulko's issue with my current system #59. This also provides a system for other plugins in the future. It consists of three parts, pre-pug processing: where the raw pug string is given (main file only), post-pug processing: where the raw compiled html is given (before saving), and mixin: where any plugin mixins are added along with the default mixins.

Global install on Ubuntu errors with "permission denied"

Hello,

Not sure whats up here. Updated npm then installed like so. Getting errors I know not how to debug.

user5@system5:~$ sudo npm i -g relaxedjs

/usr/bin/relaxed -> /usr/lib/node_modules/relaxedjs/src/index.js

> [email protected] install /usr/lib/node_modules/relaxedjs/node_modules/node-sass
> node scripts/install.js

Unable to save binary /usr/lib/node_modules/relaxedjs/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/relaxedjs/node_modules/node-sass/vendor'
    at Object.fs.mkdirSync (fs.js:885:18)
    at sync (/usr/lib/node_modules/relaxedjs/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/usr/lib/node_modules/relaxedjs/node_modules/mkdirp/index.js:77:24)
    at checkAndDownloadBinary (/usr/lib/node_modules/relaxedjs/node_modules/node-sass/scripts/install.js:114:11)
    at Object.<anonymous> (/usr/lib/node_modules/relaxedjs/node_modules/node-sass/scripts/install.js:157:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/usr/lib/node_modules/relaxedjs/node_modules/node-sass/vendor' }

> [email protected] install /usr/lib/node_modules/relaxedjs/node_modules/puppeteer
> node install.js

ERROR: Failed to download Chromium r555668! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/relaxedjs/node_modules/puppeteer/.local-chromium'
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/usr/lib/node_modules/relaxedjs/node_modules/puppeteer/.local-chromium' }
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/relaxedjs/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user5/.npm/_logs/2018-05-12T22_56_21_818Z-debug.log

How to inspect the generated html code?

When I launch the ReLaXed, I get the pdf. As .pug files gets first translated to the HTML, it would be cool to be able to inspect the HTML for debugging purposes. Is there a way to do that?

Broken colors.

Since we integrated citation-js the colors package appears to have been broken by citation-js. Not sure why, but instead of a bold output in the terminal like it should, I am getting [Function] bold. Everything else by colors still works though.

I would like to recommend a switch to signale instead of colors. Personally, I prefer the way it looks, plus citation-js does not interfere.

image

The [set] Unknown property: P407 is an issue with citation-js and wikidata entries. Currently citation-js does not have (or know) how to parse that property, so that will show up every time someone uses a wikidata entry, which my example does use. And, I am unaware of a way to suppress citation-js from logging that information.

Repeating UL header across page breaks

Given the following page structure

 ul 
     li   item 1
     li   item 2
<!--  start of next page -->
     li   item 3

Is there a way to automatically insert a custom header a start of the next page... but only if the list breaks?

The use case is that I'm adapting the resume example. The "experience" section (which is just a list) flows into the second page, and I'd like a way to automatically inject a second header "experience (cont)"... but only if the list expands into the next page

Expose the require definition to pug renderer

Is it possible to import javascript (or json) files into .pug documents to use as content?

Something like:

// content.js
module.exports = 'some content'

// doc.pug
- var someVal = require('./content.js')
h1 hello world #{someVal}

I believe that pug supports it (pugjs/pug#2604 (comment)) if you define require when passing in variables to pug.

How can i make pdf by dynamic html content?

I have seen approach you use .

If i give html it convert html to pdf and applied all css in it automatically .

Let say i want the pdf on fly.

I have a variable in node.js.

var htmlContent = "somemorehtml</html";

and i want to generate pdf by this does , it is possible or Relaxedjs need the static content only.

Thanks. LET ME KNOW IF ANY INFO NEEDED

Table of Contents

Is it possible to generate page numbers to toc, and having toc rows clickable? Also clickable references section is required.

That was so hard that I myself resorted to LaTeX instead of Chrome few months ago (didn't know about ReLaXed back then though).

Basically to support those one needs to do rendering in multiple passes, which is the reason LaTeX is so damn slow sometimes. It renders the page, get's the page numbers, make changes by inserting page numbers, re-renders the page and ensures the page numbers didn't change by the insertion etc.

relaxed reports incorrect version

Fixed in #49

Since the version is harcoded to 0.0.1 in 'src/index.js', it was tough for me to figure out if I had the latest changes that were pushed to master since I installed.

I would recommend reading the version from package.json and using that in commander.

Install does not work

Running the installed ReLaXed binary gives an error message (with node 6 as well as node 10):

/Users/yannick/sources/ReLaXed/src/index.js:31
async function main () {
      ^^^^^^^^

SyntaxError: Unexpected token function
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)

Citation/bibliography support

Are you considering to add citation feature, like LaTeX? #8 refers to a ToC support, if it’s gonna be implemented, also adding a bibliography support could be easy as pie.

Failed to npm i with ERR_STREAM_WRITE_AFTER_END

⋊> ~ sudo npm install relaxedjs -g                                                              06:50:27
[sudo] password for suzumiya: 
npm ERR! code ERR_STREAM_WRITE_AFTER_END
npm ERR! write after end

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-05-19T05_51_29_278Z-debug.log
⋊> ~ node --version                                                                             06:51:33
v10.1.0
⋊> ~ npm --version                                                                              06:52:24
6.0.1
                 

Linux 4.16.8-1-MANJARO

Issue in installing packages

I successfully cloned ReLaXed repo into my local system. After I tried to install packages those specified in package.json. But I got an error like this:

ERROR: Failed to download Chromium r549031! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: EACCES: permission denied, mkdir '/ReLaXed/node_modules/puppeteer/.local-chromium'
errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/ReLaXed/node_modules/puppeteer/.local-chromium' }
npm WARN [email protected] No repository field..

Can anyone help me to solve this?

getting-started Demo Fail ❌

https://github.com/RelaxedJS/ReLaXed#getting-started

I follow the steps


macOS high Sierra 10.13..4

Default term with zsh

❯ relaxed dd.pug
Watching dd.pug and its directory tree.

Processing detected change in /dd.pug...
File load error: file:///***/n/lib/node_modules/relaxedjs/node_modules/mathjax/unpacked/jax/output/SVG/jax.js
File load error: file:///***/n/lib/node_modules/relaxedjs/node_modules/mathjax/unpacked/jax/output/SVG/fonts/TeX/fontdata.js
File load error: file:///***/n/lib/node_modules/relaxedjs/node_modules/mathjax/unpacked/jax/input/AsciiMath/jax.js

ReLaXed Examples

I try the https://github.com/RelaxedJS/ReLaXed-examples

It Work!!! , but I cannot create a new PDF with My own *.pug

Error Installing

OS: macOS 10.13.3
NODE: v7.9.0
NPM: v4.2.0
Relaxed version: 0.1.2 (according to NPM)

Error occurs when installing npm install -g relaxedjs

➜ npm install -g relaxedjs
npm ERR! Darwin 17.4.0
npm ERR! argv "/usr/local/Cellar/node/7.9.0/bin/node" "/usr/local/bin/npm" "install" "-g" "relaxedjs"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0

npm ERR! Cannot read property 'path' of null
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/carson/.npm/_logs/2018-05-07T14_50_08_755Z-debug.log

Any ideas?

How to make ReLaXed faster ?

This issue is intended as general discussion research on how to improve user experience by making rendering faster while avoid partially-rendered PDF documents.

Open questions:

  • How to make sure the page is fully rendered before generating a PDF ? Right now this done by
    • Allowing figures and diagrams to be generated separately and included in the page as images/svgs, so that there is no rendering lag.
    • Waiting until "networkidle2" (this line) i.e. until no network exchanges, before rendering. I am wondering if this is too conservative, some pages dont need that and in my experience it really adds a lot of overhead. Would domContentLoaded work better in most cases ? If that's the case, we can always let users a choice.

I am wondering if other solutions would make ReLaXed faster:

  • Would puppeteer's page.reload() be faster ?
  • would a "hot reload" of the page where only a "diff" of the DOM is changed make the rendering faster ?
  • Are there options Chromium startup options that would make it faster ?

Any other suggestions ?

Error on Windwos npm installation

Hey, great project first of all. But installing on a Windows system with Node.js v 8.11.2 I get an error when I want to compile relaxed document.

`relaxed my_document.pug
Launching ReLaXed...

Now waiting for changes in my_document.pug and its directory
events.js:183
throw er; // Unhandled 'error' event
^

Error: watch C:\Users\kwoxer\Anwendungsdaten EPERM
at _errnoException (util.js:992:11)
at FSWatcher.start (fs.js:1382:19)
at Object.fs.watch (fs.js:1408:11)
at createFsWatchInstance (C:\Users\kwoxer\AppData\Roaming\npm\node_modules\relaxedjs\node_modules\chokidar\lib\nodefs-handler.js:37:15)
at setFsWatchListener (C:\Users\kwoxer\AppData\Roaming\npm\node_modules\relaxedjs\node_modules\chokidar\lib\nodefs-handler.js:80:15)
at FSWatcher.NodeFsHandler._watchWithNodeFs (C:\Users\kwoxer\AppData\Roaming\npm\node_modules\relaxedjs\node_modules\chokidar\lib\nodefs-handler.js:229:14)
at FSWatcher.NodeFsHandler._handleDir (C:\Users\kwoxer\AppData\Roaming\npm\node_modules\relaxedjs\node_modules\chokidar\lib\nodefs-handler.js:408:19)
at FSWatcher. (C:\Users\kwoxer\AppData\Roaming\npm\node_modules\relaxedjs\node_modules\chokidar\lib\nodefs-handler.js:456:19)
at FSWatcher. (C:\Users\kwoxer\AppData\Roaming\npm\node_modules\relaxedjs\node_modules\chokidar\lib\nodefs-handler.js:461:16)
at FSReqWrap.oncomplete (fs.js:153:5)`

How can I fix it? Is it because of the old Node.js Version?

Programmatically generate PDF

I'd like to use this in an AWS Lambda function; however, I need to invoke the PDF generation once, not watch a directory for changes. I wasn't able to find anything in the docs. Is this possible?

Failed to use on mint Linux :(

When I use the ReLaXed on mint linux 18.3 after all npm dependencies have been installed,it throws an error

Watching 11.pug and its directory tree.
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: ENOSPC: no space left on device, watch '/home/yue/pdf2web/ReLaXed/node_modules/ajv/lib/dotjs/README.md'
    at FSWatcher.start (fs.js:1389:26)
    at Object.fs.watch (fs.js:1426:11)
    at createFsWatchInstance (/usr/lib/node_modules/relaxedjs/node_modules/chokidar/lib/nodefs-handler.js:37:15)
    at setFsWatchListener (/usr/lib/node_modules/relaxedjs/node_modules/chokidar/lib/nodefs-handler.js:80:15)
    at FSWatcher.NodeFsHandler._watchWithNodeFs (/usr/lib/node_modules/relaxedjs/node_modules/chokidar/lib/nodefs-handler.js:229:14)
    at FSWatcher.NodeFsHandler._handleFile (/usr/lib/node_modules/relaxedjs/node_modules/chokidar/lib/nodefs-handler.js:256:21)
    at FSWatcher.<anonymous> (/usr/lib/node_modules/relaxedjs/node_modules/chokidar/lib/nodefs-handler.js:474:21)
    at FSReqWrap.oncomplete (fs.js:166:5)
Emitted 'error' event at:
    at FSWatcher._handleError (/usr/lib/node_modules/relaxedjs/node_modules/chokidar/index.js:260:10)
    at createFsWatchInstance (/usr/lib/node_modules/relaxedjs/node_modules/chokidar/lib/nodefs-handler.js:39:5)
    at setFsWatchListener (/usr/lib/node_modules/relaxedjs/node_modules/chokidar/lib/nodefs-handler.js:80:15)
    [... lines matching original stack trace ...]
    at FSReqWrap.oncomplete (fs.js:166:5)

But when I use the command df -h,I found that my system still has a lot of space。

Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G   18M  1.6G   2% /run
/dev/sdb4       189G   17G  163G  10% /
tmpfs           7.8G   37M  7.8G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1        99M   48M   52M  48% /boot/efi
/dev/sdb5       115G   16G   94G  15% /home
cgmfs           100K     0  100K   0% /run/cgmanager/fs
tmpfs           1.6G   40K  1.6G   1% /run/user/1000

After that,I updatemax_user_watchesto solve the same problem from https://stackoverflow.com/questions/22475849/node-js-error-enospc.However,It did not solve the problem.And the ReLaXed Into an endless wait, did not return success or error。

➜  pdf2web relaxed 11.pug 
Watching 11.pug and its directory tree.

I also try to run ReLaXed with root privileges,but it still no change in the above situation.On the other hand,I has ensured the correct chromium version has been downloaded and configured correctly in index.js.
:( I don't have any ideas so I hope to turn to you

EPub

If ReLaXed can export EPub, that would be truly wonderful. EPub is basically XHTML + assets + some metadata in a Zip file

Feature to generate pdf on first call

Hi,
The tool works great with the recommended atom setup. I was wondering if there was a way to make it generate the pdf given an html file without having to go in and save the file atleast once?

Error Running

OS: macOS 10.13.5
NPM: 4.6.1
Relaxed version: 0.1.2 (according to NPM)

Error occurs when trying to run the "relaxed {filename}" command

Error: Cannot find module 'perf_hooks'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/relaxedjs/src/index.js:6:25)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)

Is relaxed.js is completely asynchronous ?

When i see examples you provided https://github.com/RelaxedJS/ReLaXed-examples
all are pug . why not you have given any example for html to pdf ?

Is there is any limitation?

why it always give me mobile view pdf when i use html ? is there are any label to provide to make the pdf as desktop view.

According to your docs the relexed.js check for html or pug will changes , if the file changes it generate pdf with respect to it .

Why not we are using relexed.js for creating pdf when i want?

Is there is any example of it where it not check regularly ? and create pdf when we want ?

Windows: Error: Error: Page crashed

Installation worked fine, but it does not seem to work.

I have isolated the problem to PDF creation:

  await page.pdf(options)

Is causing issue on my system somehow.

I cloned the book example and modified a file:

PS C:\Source\JavaScript\ReLaXed-toc-tests> relaxed book.pug
Watching book.pug and its directory tree.

Processing detected change in \book.pug...
Error: Page crashed!
    at Page._onTargetCrashed (C:\Copies\ReLaXedJs\node_modules\puppeteer\lib\Page.js:118:24)
    at CDPSession.Page.client.on.event (C:\Copies\ReLaXedJs\node_modules\puppeteer\lib\Page.js:104:56)
    at CDPSession.emit (events.js:180:13)
    at CDPSession._onMessage (C:\Copies\ReLaXedJs\node_modules\puppeteer\lib\Connection.js:219:12)
    at Connection._onMessage (C:\Copies\ReLaXedJs\node_modules\puppeteer\lib\Connection.js:119:19)
    at WebSocket.emit (events.js:180:13)
    at Receiver._receiver.onmessage (C:\Copies\ReLaXedJs\node_modules\ws\lib\WebSocket.js:141:47)
    at Receiver.dataMessage (C:\Copies\ReLaXedJs\node_modules\ws\lib\Receiver.js:389:14)
    at Receiver.getData (C:\Copies\ReLaXedJs\node_modules\ws\lib\Receiver.js:330:12)
    at Receiver.startLoop (C:\Copies\ReLaXedJs\node_modules\ws\lib\Receiver.js:165:16)
Error: Error: Page crashed!

I hit Ctrl+C

(node:11184) UnhandledPromiseRejectionWarning: Error: Protocol error (Page.printToPDF): Target closed.
    at Promise (C:\Copies\ReLaXedJs\node_modules\puppeteer\lib\Connection.js:200:56)
    at new Promise (<anonymous>)
    at CDPSession.send (C:\Copies\ReLaXedJs\node_modules\puppeteer\lib\Connection.js:199:12)
    at Page.pdf (C:\Copies\ReLaXedJs\node_modules\puppeteer\lib\Page.js:782:39)
    at Object.exports.masterDocumentToPDF (C:\Copies\ReLaXedJs\src\converters.js:192:14)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)
(node:11184) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11184) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Installation transcript, which I think means it installed correctly:

PS C:\Copies\ReLaXedJs> git clone https://github.com/RelaxedJS/ReLaXed.git .
Cloning into '.'...
remote: Counting objects: 133, done.
remote: Compressing objects: 100% (110/110), done.
remote: Total 133 (delta 74), reused 54 (delta 21), pack-reused 0
Receiving objects: 100% (133/133), 225.90 KiB | 0 bytes/s, done.
Resolving deltas: 100% (74/74), done.
PS C:\Copies\ReLaXedJs> npm install
npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0

> [email protected] install C:\Copies\ReLaXedJs\node_modules\node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.9.0/win32-x64-59_binding.node
Download complete .] - :
Binary saved to C:\Copies\ReLaXedJs\node_modules\node-sass\vendor\win32-x64-59\binding.node
Caching binary to C:\Users\jarppa2\AppData\Roaming\npm-cache\node-sass\4.9.0\win32-x64-59_binding.node

> [email protected] install C:\Copies\ReLaXedJs\node_modules\puppeteer
> node install.js

Downloading Chromium r549031 - 122.5 Mb [====================] 100% 0.0s
Chromium downloaded to C:\Copies\ReLaXedJs\node_modules\puppeteer\.local-chromium\win64-549031

> [email protected] postinstall C:\Copies\ReLaXedJs\node_modules\node-sass
> node scripts/build.js

Binary found at C:\Copies\ReLaXedJs\node_modules\node-sass\vendor\win32-x64-59\binding.node
Testing binary
Binary is fine
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 1052 packages in 87.302s
PS C:\Copies\ReLaXedJs> npm link --unsafe-perm=true
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

up to date in 8.597s
C:\Copies\Node\relaxed -> C:\Copies\Node\node_modules\relaxedjs\src\index.js
C:\Copies\Node\node_modules\relaxedjs -> C:\Copies\ReLaXedJs

PS. I modified the error to show the first stack trace.

global install

It should work. At least I do not have any issues using puppeteer for my website-stack package and using it globally.

PDFs sometimes garbled at first rendering

$ cd ReLaXed-examples/examples/book
$ /opt/npm/bin/relaxed book.pug 
Watching book.pug and its directory tree.

Processing detected change in /book.pug...
... done in 1.90s

After that I get 29 page pdf without any text (but the pictures are present). The rabbit is on the second page (not on the first).

Executed on Ubuntu 16.04 64 bit. npm 5.6.0.

Is it possible to run ReLaXed on demand?

I appreciate the "watch a file" thing, but is there a way to direct ReLaXed to simply execute once and exit? If I had that, I could do some automation around it.

Error: EACCES: permission denied, access \'/usr/lib/node_modules/relaxedjs\

Hello,
I ran npm i -g relaxedjs with and without sudo and I keep getting the error listed in the subject line.
I was able to run sudo npm i -g relaxedjs --unsafe-perm=true with no problem but I get an error "UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!"
How do I get it to work?

End page and/or insert empty page

It would be a great feature to have the possibility to force ReLaXed to go to the next page or insert an empty page. I believe there currently is not a way to do this.

Document pre-requisites

I was quite surprised to discover that after following the install instructions, and eventually getting to the troubleshooting page, it seems that Chromium is a requirement.

Could I suggest that this (and other pre-reqs) be documented? (Preferable in the "Installing ReLaXed" section...)

Do you support other languages?

What can I do to make it support Chinese without making error?
`` C:\Users\***\Desktop\my_document.pug:3:1

1| h1 My document's title
2| p A paragraph in my document
3| ��ã��������ˣ�
-------^

unexpected text "���"
There was a Pug error (see above)
... done in 0.01s

Is there any way to add footnotes?

Footnotes like LaTeX is necessary to write up a formal document, but seems no simple way to put footnotes using HTML/CSS or JavaScript. It's possible to set position: absolute, bottom: 0 to the footnote container, but each page margin could not be arbitrary.

CSS Generated Content for Paged Media Module looks good, but it seems not implemented in the current version of Chromium. Not working.

Any other ideas?

Create PDF right away, even when `relaxed` command is run without `build-once` command.

If my_document.pug already exists and a user wants to edit this file, it would be more intuitive to create my_document.pdf as soon as the user runs relaxed my_document.pug, instead of watching for the file to change and then creating the pdf.

This would help the user to first take a look at the generated pdf and then start making the necessary changes.

ReLaXed does not work with Arch Linux (4.16.5-1)

Attempting to run relaxed myfile.pug on Arch Linux (4.16.5-1) yields the following message in stderr:

(node:19051) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to launch chrome!
[0504/012329.661509:FATAL:zygote_host_impl_linux.cc(124)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.
#0 0x55d558c17b0c base::debug::StackTrace::StackTrace()
#1 0x55d558c30780 logging::LogMessage::~LogMessage()
#2 0x55d557cc02b1 content::ZygoteHostImpl::Init()
#3 0x55d557932c65 content::BrowserMainLoop::EarlyInitialization()
#4 0x55d557938a69 content::BrowserMainRunnerImpl::Initialize()
#5 0x55d55ca629a8 headless::HeadlessContentMainDelegate::RunProcess()
#6 0x55d558952a00 content::RunNamedProcessTypeMain()
#7 0x55d5589532e8 content::ContentMainRunnerImpl::Run()
#8 0x55d55895cf24 service_manager::Main()
#9 0x55d558951f14 content::ContentMain()
#10 0x55d55ca619b9 headless::(anonymous namespace)::RunContentMain()
#11 0x55d55ca61a42 headless::HeadlessBrowserMain()
#12 0x55d558959f9d headless::HeadlessShellMain()
#13 0x55d556fb81ac ChromeMain
#14 0x7f9f47b359a7 __libc_start_main
#15 0x55d556fb802a _start

Received signal 6
#0 0x55d558c17b0c base::debug::StackTrace::StackTrace()
#1 0x55d558c17671 base::debug::(anonymous namespace)::StackDumpSignalHandler()
#2 0x7f9f4db0cb90 <unknown>
#3 0x7f9f47b48efb __GI_raise
#4 0x7f9f47b4a2c1 __GI_abort
#5 0x55d558c16105 base::debug::BreakDebugger()
#6 0x55d558c30bca logging::LogMessage::~LogMessage()
#7 0x55d557cc02b1 content::ZygoteHostImpl::Init()
#8 0x55d557932c65 content::BrowserMainLoop::EarlyInitialization()
#9 0x55d557938a69 content::BrowserMainRunnerImpl::Initialize()
#10 0x55d55ca629a8 headless::HeadlessContentMainDelegate::RunProcess()
#11 0x55d558952a00 content::RunNamedProcessTypeMain()
#12 0x55d5589532e8 content::ContentMainRunnerImpl::Run()
#13 0x55d55895cf24 service_manager::Main()
#14 0x55d558951f14 content::ContentMain()
#15 0x55d55ca619b9 headless::(anonymous namespace)::RunContentMain()
#16 0x55d55ca61a42 headless::HeadlessBrowserMain()
#17 0x55d558959f9d headless::HeadlessShellMain()
#18 0x55d556fb81ac ChromeMain
#19 0x7f9f47b359a7 __libc_start_main
#20 0x55d556fb802a _start
  r8: 0000000000000000  r9: 00007ffe43fadf90 r10: 0000000000000008 r11: 0000000000000246
 r12: 00007ffe43fae698 r13: 0000000000000161 r14: 00007ffe43fae6a0 r15: 00007ffe43fae239
  di: 0000000000000002  si: 00007ffe43fadf90  bp: 00007ffe43fae1e0  bx: 0000000000000006
  dx: 0000000000000000  ax: 0000000000000000  cx: 00007f9f47b48efb  sp: 00007ffe43fadf90
  ip: 00007f9f47b48efb efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.


TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md

(node:19051) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I have a solution, which I will post soon; I'm creating this issue as a reference for any future Arch Linux users.

Report Sidebar

When using the: ".report-sidebar: p [Text-Here]" I am unable to get the sidebar on the second page of the PDF. I used Git to clone the example and worked straight from there.

Any help would be appreciated, thanks!

Feat: Choose Chromium version to install

Would it be possible to set the Chromium version used with Puppeteer via this package?
It seems that although Puppeteer provide a way to set the Chromium version during install, they don't want to use ENV vars in the actual code (puppeteer/puppeteer#2491 (comment)), so it needs to be set when creating the browser.

e.g.

const browserFetcher = puppeteer.createBrowserFetcher();
const revision = browserFetcher.revisionInfo(process.env.PUPPETEER_CHROMIUM_REVISION);
const browser = await puppeteer.launch({executablePath: revisionInfo.executablePath})

This would provide a way to pin Chromium to a version that works for individual needs - #17 for instance - and could help in the future for any breaking changes in Chromium.

How to remove document margin?

I'm trying to remove document margin, so I can paint/handle it myself accordingly to the page I'm on. But it seems the only way to do it is adding negative margin to @page as margin: 0mm; doesn't works at all.

How can I fully remove the document margin?

captura de tela 2018-05-27 as 02 06 06

proposal: unit tests

We need unit tests which can be run with Travis CI on every PR and commit to catch issues early.

launch relaxed without arguments results in TypeError

Lauched relaxed on command line to see the options. I was greeted with a TypeError because input was undefined

output = input.substr(0, input.lastIndexOf('.')) + '.pdf'
                 ^

TypeError: Cannot read property 'substr' of undefined
    at Object.<anonymous> (/Users/irichter/develop/fun/OSS/ReLaXed/src/index.js:24:18)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.