Rendering pdf like crazy in hb
Browsershot configuration on gateway
This is the browsershot configuration needed to the run headless chrome container
// browser-shot.php
<?php
return [
'PATH_CHROME' => env('PATH_CHROME'),
'PATH_NODE_MODULES' => env('PATH_NODE_MODULES'),
'HOST' => env('BROWSERSHOT_CHROMIUM_HOST', '127.0.0.1'),
'NODE' => env('NODE', '/usr/bin/node'),
'NPM' => env('NPM', '/usr/bin/npm'),
];
if (config('browser-shot.HOST')) {
$browserShot->setRemoteInstance(config('browser-
shot.HOST'), '9222')
->waitUntilNetworkIdle()
->setOption('args', ['--disable-web-security']);
}
$content = $browserShot->showBackground()
->showBrowserHeaderAndFooter()
->hideHeader()
->headerHtml(View::make($this->views['header'], $this-
>header_option?? []))
->footerHtml(View::make($this->views['footer'],
['reference' => $this->reference])->render())
->format('A4')
->margins(60, 15, 25, 15)
->pdf();
Docker container creating for headless chrome
Now than you need to make a container for the headless chrome and run it inside the docker network and pass it to gateway for to render pdf in chrome as headless mode
version: '2'
services:
nginx:
build:
context: "../images/nginx"
image: hbt/nginx
labels:
- traefik.enable=true
- traefik.docker.network=docker
- traefik.http.routers.gateway-hbt-va-http.entrypoints=http
- traefik.http.routers.gateway-hbt-va-http.rule=Host(`console.hbtdev.org`, `client.hbtdev.org`)
- traefik.http.routers.gateway-hbt-va-http.service=gateway-hbt-va-https@docker
- traefik.http.routers.gateway-hbt-va-http.middlewares=https_redirect
- traefik.http.routers.gateway-hbt-va-https.entrypoints=https
- traefik.http.routers.gateway-hbt-va-https.rule=Host(`console.hbtdev.org`, `client.hbtdev.org`)
- traefik.http.routers.gateway-hbt-va-https.tls=true
- traefik.http.routers.gateway-hbt-va-https.tls.certresolver=zerossl
- traefik.http.middlewares.https_redirect.redirectscheme.scheme=https
- traefik.http.middlewares.https_redirect.redirectscheme.permanent=true
- traefik.http.services.gateway-hbt-va-https.loadbalancer.server.port=80
depends_on:
- php-fpm
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
- ${NGINX_HOST_LOG_PATH}:/var/log/nginx
- ${NGINX_SITES_PATH}:/etc/nginx/sites-available
ports:
- "${NGINX_HOST_HTTP_PORT}:80"
networks:
- docker
- hbt-gateway
extra_hosts:
- "gateway.hbtdev.org:192.168.65.2"
- "search.hbtdev.org:192.168.65.2"
- "rates.hbtdev.org:192.168.65.2"
- "operations.hbtdev.org:192.168.65.2"
- "products.hbtdev.org:192.168.65.2"
- "travelgate.hbtdev.org:192.168.65.2"
- "foundation.hbtdev.org:192.168.65.2"
- "console.hbtdev.org:192.168.65.2"
- "client.hbtdev.org:192.168.65.2"
php-fpm:
build:
context: "../images/php-fpm-74-node-16"
dockerfile: Dockerfile
platform: linux/amd64
image: hbt/php-fpm-node:7.4-16
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
- ~/.ssh:/root/.ssh:ro
- "~/.ssh:/home/www-data/.ssh:ro"
- "tmpfiles:/tmp"
networks:
- hbt-gateway
restart: always
expose:
- 9000
extra_hosts:
- "gateway.hbtdev.org:192.168.65.2"
- "search.hbtdev.org:192.168.65.2"
- "rates.hbtdev.org:192.168.65.2"
- "operations.hbtdev.org:192.168.65.2"
- "products.hbtdev.org:192.168.65.2"
- "travelgate.hbtdev.org:192.168.65.2"
- "foundation.hbtdev.org:192.168.65.2"
- "console.hbtdev.org:192.168.65.2"
- "client.hbtdev.org:192.168.65.2"
privileged: true
environment:
- DBUS_SYSTEM_BUS_ADDRESS=${DBUS_SYSTEM_BUS_ADDRESS}
- PUPPETEER_EXECUTABLE_PATH=${PUPPETEER_EXECUTABLE_PATH}
- BROWSERSHOT_CHROMIUM_HOST=172.22.0.100
depends_on:
- chromium
node:
build:
context: "../images/node-16"
dockerfile: Dockerfile
image: hbt/node:16
networks:
- hbt-gateway
volumes:
- ${APP_CODE_PATH_HOST}:/var/www
- ~/.ssh:/root/.ssh:ro
- "~/.ssh:/home/www-data/.ssh:ro"
working_dir: /var/www
chromium:
image: zenika/alpine-chrome
command:
[
chromium-browser,
"--headless",
"--disable-gpu",
"--remote-debugging-address=0.0.0.0",
"--remote-debugging-port=9222",
]
cap_add:
- SYS_ADMIN
volumes:
- tmpfiles:/tmp
ports:
- "9222:9222"
networks:
hbt-gateway:
ipv4_address: 172.22.0.100
extra_hosts:
- "console.hbtdev.org:192.168.107.1"
- "client.hbtdev.org:192.168.107.1"
networks:
docker:
external: true
hbt-gateway:
driver: bridge
ipam:
driver: default
config:
- subnet: "172.22.0.0/24"
volumes:
tmpfiles:
driver: local
Rendering pdf style css
<link type="text/css" media="all" rel="stylesheet" href="{{
URL::asset('css/pdf.css') }}" />
<link type="text/css" media="all" rel="stylesheet" href="{{
URL::asset('css/tailwind.css') }}" />
No Comments