Skip to content

Commit

Permalink
More rendering config
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwestendorf committed Jun 13, 2018
1 parent 7245741 commit 5680e42
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -4,6 +4,7 @@ node_js:
addons:
chrome: stable
before_install:
- export CHROME_PATH="$(pwd)/chrome-linux/chrome"
- google-chrome-stable --no-sandbox --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
- |
until nc -z -v -w30 127.0.0.1 9222
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -20,7 +20,7 @@ This is done with a `POST` request the the web server. We'll use some example HT
```sh
curl -X POST -H 'Authorization: Bearer PRIVATE_TOKEN_DEFINED_IN_SERVER_ENVIRONMENT' \
http://url-of-your-breezy-pdf-lite-server/render/html \
-d '`curl https://raw.githubusercontent.com/danielwestendorf/breezy-pdf-lite/master/sample.html`' \
-d "`curl https://raw.githubusercontent.com/danielwestendorf/breezy-pdf-light/master/sample.html`" \
-o example.pdf
```

Expand Down
26 changes: 25 additions & 1 deletion index.js
@@ -1,4 +1,28 @@
const Server = require('./lib/server')
const { spawn } = require('child_process')
const Server = require('./lib/server')

if (process.env.GOOGLE_CHROME_SHIM !== undefined) {
console.log('Starting Google Chrome')
const chrome = spawn(
process.env.GOOGLE_CHROME_SHIM,
[
'--disable-extensions',
'--disable-background-networking',
'--safebrowsing-disable-auto-update',
'--disable-sync',
'--metrics-recording-only',
'--disable-default-apps',
'--no-first-run',
'--mute-audio',
'--hide-scrollbars'
]
)

chrome.on('close', async (code) => {
console.error(`Chrome process closed with code ${code}`);
process.exit(code);
});
}

console.log('Starting web server...')

Expand Down
16 changes: 7 additions & 9 deletions lib/render.js
Expand Up @@ -7,16 +7,9 @@ const CompletionTrigger = require('./pdf/completion-trigger')
module.exports = class Render {
constructor(htmlString, options) {
this.htmlString = htmlString
this.options = options || {
host: 'localhost',
port: 9222
}

this.log = debug(this.options.log || 'breezy-pdf-lite:pdf')
this.options = options || {}

if (process.env.GOOGLE_CHROME_SHIM !== undefined) {
process.env.CHROME_PATH = process.env.GOOGLE_CHROME_SHIM
}
this.log = debug(this.options.log || 'breezy-pdf-lite:pdf')
}

toPdf() {
Expand All @@ -25,6 +18,11 @@ module.exports = class Render {
printOptions: this.printOptions()
}

if (process.env.GOOGLE_CHROME_SHIM !== undefined) {
renderOptions.host = 'localhost'
renderOptions.port = 9222
}

this.log(`Generating PDF for HTML string with options: ${JSON.stringify(renderOptions)}`)

return htmlPdf.create(this.htmlString, renderOptions)
Expand Down
2 changes: 1 addition & 1 deletion sample.html
Expand Up @@ -6,7 +6,7 @@
<meta name="breezy-pdf-variable" content="pdfRenderReady">
<meta name="breezy-pdf-displayBackground" content="true">
<meta name="breezy-pdf-marginTop" content="0.4">
<meta name="breezy-pdf-marginBottom" content="0.8">
<meta name="breezy-pdf-marginBottom" content="0.7">
<meta name="breezy-pdf-footerTemplate" content=" &lt;style type=&quot;text/css&quot;&gt;
#footer {
font-size: 12px;
Expand Down

0 comments on commit 5680e42

Please sign in to comment.