Docker file
FROM alpine:3.7
# https://dev.to/setevoy/docker-configure-tzdata-and-timezone-during-build-20bk
RUN ln -snf /usr/share/zoneinfo/Europe/London /etc/localtime && echo Europe/London > /etc/timezone
# https://jsreport.net/learn/dotnet-local#docker
RUN apt-get update && apt-get install -y --no-install-recommends libgconf-2-4 gnupg git curl wget ca-certificates && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && \
apt-get install -y lsb-release google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst libxtst6 libxss1 --no-install-recommends && \
apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 \
libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 \
libxrender1 ca-certificates fonts-liberation libappindicator1 libnss3 xdg-utils
ENV chrome_launchOptions_executablePath google-chrome-stable
ENV chrome_launchOptions_args --no-sandbox,--disable-dev-shm-usage,--single-process,--no-zygote
RUN mkdir -p /unmanaged/bin/jsreport && curl -fsSL https://github.com/jsreport/jsreport/releases/download/2.11.0/jsreport-linux.tar.gz | tar zxC /unmanaged/bin/jsreport
ENV JSREPORT_EXEC="/unmanaged/bin/jsreport/jsreport"
ADD jsreport /unmanaged/bin/jsreport
ADD in/ /unmanaged/bin/tomcat/webapps/ROOT/
java file: we are trying to execute the command by java program and the template name will sent by client side.
private boolean excuteCommand(java.nio.file.Path parentPath, String templateName, String nodeId) {
String mTemplatePath = Paths.get( parentPath.toString(), "input", "template", templateName+".html").toString();
String mDataPath = Paths.get( parentPath.toString(), "input", "data", nodeId+".json").toString();
String mOutputPath = Paths.get( parentPath.toString(),"output", nodeId+".pdf").toString();
final String templatePath=String.format("--template.content=%s", mTemplatePath);
final String dataPath=String.format("--data=%s",mDataPath);
final String outputPath= String.format("--out=%s", mOutputPath);
try {
String outputString = new ProcessExecutor()
.command(jsReport, "render", "--template.engine=ejs", "--template.recipe=chrome-pdf", templatePath, dataPath, outputPath)
.directory(parentPath.toFile())
.readOutput(true)
.execute()
.outputString();
logger.info("Output of the command: {}", outputString);
return Files.exists(Paths.get(mOutputPath));
} catch (Exception e) {
logger.error("Exception while executing command:", e);
return false;
}
}