This standalone service exposes the functionality of converting an html file into pdf and also preview of an html file via using the pagedjs previewer. The API offered is as follows:
POST /api/authPOST /api/htmlToPDFGET /api/getPreviewerLink
- As this service is meant to be from many clients, the first endpoint allows clients to acquire their access tokens in order to be able to use the service*. A call to the
api/authendpoint considered valid if it contains the Authorization header with valueBasic base64encoded(clientId:clientSecret).
The response of a valid call to theapi/authwill return anaccessToken** (JWT) - A call to the
api/htmlToPDFin order to be considered valid should have theAuthorizationproperty in its headers with valueBearer <the value of an accessToken provided by this service>. The propertyContent-Typeshould bemultipart/form-dataand finally the body should contain the actual html file under a form field calledzip. Additional body options areimagesFormandonlySourceStylesheet. TheimagesFormshould be set tobase64if the included images in theHTMLcontent are encoded inbase64format. TheonlySourceStylesheetoption should be set totrueif the calling application requires only the provided stylesheet to be included in the conversion to PDF process (without this flag two additional stylesheets are included by default, one of the highlight.js library and one for the katex.js library) The response of this endpoint will be a file stream containing the actual pdf file which was created or aJSONif any errors occurred. - A call to the
api/getPreviewerLinkin order to be considered valid should have theAuthorizationproperty in its headers with valueBearer <the value of an accessToken provided by this service>. The propertyContent-Typeshould bemultipart/form-dataand finally the body should contain a zip file which will have the html which should be previewed, a css file and possible any font files referenced in the css file. The response of this endpoint will be aJSONobject with one property calllinkwhich will present the link of the html preview in pagedjs, or amsgproperty if any errors occurred
*client's registration required beforehand
**the life span of an accessToken is 8 hours
The service is fully dockerized for ease of use for either development or for use in production.
In the root of the service run docker-compose up
This container includes the actual service as well as a Postgres DB
In the root of the service run docker-compose -f docker-compose.production.yml up
This container contains just the service. An external Postgres DB should be provided.
PUBSWEET_SECRET
SERVER_PORT
SERVER_HOST
SERVER_PROTOCOL
POSTGRES_USER
POSTGRES_PASSWORD
POSTGRES_HOST
POSTGRES_DB
POSTGRES_PORT
NODE_ENV=production
All the above are required
When the service is up by executing docker exec -it <name_of_the_pagedjs_server_container> yarn create:client.
The above will produce a valid pair of clientId and clientSecret