GithubHelp home page GithubHelp logo

pdf-generator-base's Introduction

Setup Guide

Install

Chromium runtime engine

apt install chromium

Node package

yarn install

OS font For displaying Chinese characters

apt-get install -y fonts-indic fonts-noto fonts-noto-cjk

Run All Tests Cases

The pdf with mapped name will be placed in the tests folder. same name in inputs folder will also be captured for testing

chmod -R 777 src/tests
cd src/tests
./all.sh

for example: invoices.sh will import inputs/invoice.json and export invoices.pdf

FAQ

Why get is empty

Please be reminded that add api routing path /api/v1/pdf/invoices

PM2 could not find Chromium problem

  1. find out pm2 cannot accept .env
  2. chromium exec path maybe difference. which chromium and copy path to generate.js launch
  3. pm2 cannot use with root. Resolved by add --no-sanbox args

Run

Curl

Start server

yarn start

Run Script

curl -0 -Lo output.pdf -H "Content-Type: application/json" -d @input.json -X POST http://localhost:8081/api/v1/pdf/templates

API

const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

const raw = JSON.stringify({
  "customerName": "Chan Tai Man",
  "authorizedPerson": "John Doe",
  "passportId": "A1234567",
  "receiptNo": "123456",
  "dateTime": 1674550554469,
  "telephone": "(852) 9123 4567",
  "fax": "(852) 9123 4567",
  "email": "[email protected]",
  "address": "Address line1\nLine 2 UK",
  "openingHours": "0000-2359"
});

const requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("http://localhost:8082", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Job Description

Requirements

  • Develop a HTML page based on the requirement
  • Write a node.js Express.js program to generate PDF using pdf.js or similar library which is compatible with node 18

Expected Flow

$ PORT=8080 node pdf-generator.js &
$ curl -Lo output.pdf -X POST -H "Content-Type: application/json" -d @input.json http://localhost:8081
$ open output.pdf

The above command will open the output.pdf using Apple's preview or Google Chrome.

Input.json contains 15-20 fields and most values are inserted into template.html and some values are for page formatting. Output PDF should only fit in one A4 page. No graphics design is required but a HTML page formatting is required. The text should be selectable in the PDF. The input.json, template HTML and output PDF contains Chinese characters. Developer are not required to know the characters. See attached the sample output.

Deliverable

  1. node.js program called run.js
  2. package.json
  3. template.html which contains the template of the HTML page
  4. template.css
  5. sample output PDF
  6. Other files

Code server will be provided for development.

pdf-generator-base's People

Contributors

kerrickchan avatar eric88work avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.