Skip to content

mimilabs/mimi-pdf-services

Repository files navigation

mimi-pdf-services

A lightweight, super fast, and publishing-grade PDF (+ PNG, SVG) generator.

How Fast?

With the bulk mode, it only takes 35 milliseconds to generate a PDF document on average.

In other words, it takes 35 seconds, less than a minute, to generate 1,000 PDF documents.

Publishing-grade?

mimi-pdf-services generates publishing-grade, really good quality documents. You can also use some healthcare-specific templates to mass-produce these high-quality documents. For more details, please check out the gallery folder.

Template Name Sample Document End-point Use Cases
Blank {URL}/use_blank_template Any use case
Basic {URL}/use_basic_template Free-form official letters
PRC {URL}/use_prc_template PRC Form, e.g., wellness check
PAS {URL}/use_pas_template Prior Authorization for surgeries
PAM {URL}/use_pam_template Prior Authorization for medications

Background/Why

For many years, I have been bothered by PDFs. Yes, we deal with many PDF files in healthcare, and often, we need to generate millions of PDF files. The problem is that we do not have a lightweight solution for the task.

That was the case until I came across Typst. Typst is a typesetting system built in Rust that can generate PDF, PNG, and SVG documents blazingly fast. With Typst, I realized that I could finally reliably and swiftly generate PDF files, which I have always wanted.

mimi-pdf-services is built on four separate technologies:

  • Typst: PDF/PNG/SVG compiler
  • FastAPI: API server
  • Auth0: As the API server faces the internet, we want to protect the endpoints. We use Auth0 for that.
  • Docker: We use Docker to containerize the whole service.

On top of these four technologies, I added a bit of spices to make it more immediately useable/useful in the healthcare industry.

It is lightweight and easy to use. To learn more, please check out the API documentations at https://pdfservices.mimilabs.org/docs.

Getting Started

There are two ways to get started with the mimi-pdf-services engine: easy full-service way and hard DIY way.

First, we recommend the easy full-service model. You just need to contact us for an API key, and that's it. You can start using the service immediately. We will manage all the hairy details and groundwork for you. If you chose this path, you can go to the next section on how to use the engine.

Please check out the test_ with_realserver.py script to learn about how to use all the end points. Also, don't forget to checkout the dommentations at https://pdfservices.mimilabs.org/docs.

However, if you want more freedom, you can choose the latter path - using it from the source code. This section will illustrate how to do the latter.

Setting up the Auth0 account

The API server faces the internet, and you want to prevent any random folk using the service. For that, we use Auth0 as an authentication authority. If you are not signed up for Auth0, you would need to sign up. Once you signed up, you would need to create a new API application to fill out these environment variables:

AUTH0_DOMAIN = 
AUTH0_API_AUDIENCE = 
AUTH0_ISSUER = 
AUTH0_ALGORITHMS = RS256
AUTH0_CLIENT_ID = 
AUTH0_CLIENT_SECRET = 

After you fill out the values, save this information in .env on the root path of the project folder.

For more details, please see these blog posts from Auth0:

Building the image

Once you are done with Auth0, you can now build a container image using the Dockerfile in this repository as below:

# build the image
docker build -t mimi-pdf-services .

# test running the image (optional)
docker run -it -p 8000:8000 mimi-pdf-services

Running the image on AWS

You can run the container image however you want - run it locally or on different cloud providers. If you want to run it on AWS, you can follow the steps based on the AWS ECS Tutorial as below:

# Create an Amazon ECR repository
aws ecr create-repository --repository-name mimi-pdf-services --region <region>

# Tag with the repository URI returned from the above command
docker tag mimi-pdf-services <aws_account_id>.dkr.ecr.<region>.amazonaws.com/mimi-pdf-services

# Authenticate
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.<region>.amazonaws.com

# Upload the image
docker push <aws_account_id>.dkr.ecr.<region>.amazonaws.com/mimi-pdf-services

The Rest

Once the image is uploaded to AWS, you can use the image however you want. For example, you can use the AWS Fargate to create an auto-scalable service, which we did for pdfservices.mimilabs.org.

Good luck!

License

APACHE LICENSE, VERSION 2.0

About

A containerized PDF generator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors