|
|
|
|
|
|
|
|
npm i -g relaxedjs
h1 My document's title p A paragraph in my document
relaxed my_document.pug
relaxed my_document.pug --build-once
-
Read more about usage and options of the relaxed command. -
Learn more about the capabilities of the Pug language -
Learn how to use or write ReLaXed plugins -
Browse the examples -
Read about our recommended setup to use ReLaXed -
read about special file rendering in ReLaxed -
Read these comparisons between ReLaXed and other document-editing systems
-
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.
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 ( ) ;
const HTML2PDF = require ( './ HTML2PDF.js' ) ;
( async ( ) => {
await HTML2PDF . pdf ( './ template.pug' , { "a" : "b" , "c" : "d" } ) ;
} ) ( ) ;
-
@Zulko (Owner) -
@Drew-S (architecture, plugins) -
@DanielRuf -
@benperiton