Sample publication using wkhtml2pdf
In this example, we use Docker Compose to install Simplicité + Postgres + wkhtml2pdf
Installing
sudo yum update -y && sudo yum clean all
sudo reboot
sudo yum install -y docker && sudo yum clean all
sudo systemctl enable docker
sudo systemctl start docker
sudo docker login
# copy content in docker-compose.yml shown below
vi docker-compose.yml
sudo docker-compose up -d
docker-compose.yml
version: "3"
services:
db:
image: postgres:latest
restart: always
container_name: myinstance-postgres-database
environment:
POSTGRES_USER: "simplicite"
POSTGRES_PASSWORD: "simplicite"
POSTGRES_DB: "simplicite"
ports:
- 127.0.0.1:5432:5432
volumes:
- myinstance-postgres-db:/var/lib/postgresql/data
wkhtml2pdf:
image: openlabs/docker-wkhtmltopdf-aas:latest
restart: always
web:
image: simplicite/platform:latest
restart: always
container_name: myinstance-postgres-webapp
environment:
DB_SETUP: "true"
DB_VENDOR: "postgresql"
DB_HOST: db
DB_USER: "simplicite"
DB_PASSWORD: "simplicite"
DB_NAME: "simplicite"
DB_WAIT: 10
ports:
- 80:8080
volumes:
- myinstance-postgres-git:/usr/local/tomcat/webapps/ROOT/WEB-INF/git
depends_on:
- db
volumes:
myinstance-postgres-db:
myinstance-postgres-git:
Configuration
MyObject
- Publication
- MyPublication
- Usage: ...
- Grantable: no
- MIME Type: PDF
- Type: Method
- Method: pubPdf
Code example
For more information on generating the HTML, see HTML publication using resources
package com.simplicite.objects.Demo;
import java.util.*;
import com.simplicite.util.*;
import com.simplicite.util.tools.*;
import org.json.JSONObject;
/**
* Business object DemoSupplier
*/
public class DemoSupplier extends ObjectDB {
private static final long serialVersionUID = 1L;
public byte[] pubPdf(){
String url = "http://wkhtml2pdf/";
String user = null;
String password = null;
JSONObject postData = new JSONObject();
postData.put("contents", Tool.toBase64("<html><head><meta charset=\"utf-8\"></head><h1>Simplicité / Docker Compose / wkhtml2pdf</h1><p>...by Simplicité</p></html>"));
String[] headers = {"Content-Type:application/json"};
String encoding = Globals.BINARY;
byte[] pdf = null;
try{
pdf = Tool.readUrlAsByteArray(url, user, password, postData.toString(), headers, encoding);
}catch(Exception e){
AppLog.error(getClass(), "pubPdf", "------------", e, getGrant());
}
return pdf;
}
}