Categorygithub.com/emeraldls/platnova-task
modulepackage
0.0.0-20241108223511-4a597719be9f
Repository: https://github.com/emeraldls/platnova-task.git
Documentation: pkg.go.dev

# README

PDF Generator

A simple and efficient Golang application designed to parse JSON data and generate PDF documents. This tool is ideal for converting structured data stored in JSON format into professionally formatted PDF reports. The project leverages the power of the UniDoc library to handle PDF creation and manipulation, ensuring high-quality output.

JSON Schema for PDF Statement Generation

The following JSON structure outlines the schema for generating PDF statements:

{
    "title": "string",
    "generated_date": "string",
    "bank_name": "string",
    "customer_name": "string",
    "customer_address": {
        "address_line1": "string",
        "address_line2": "string",
        "city": "string",
        "county": "string",
        "post_code": "string"
    },
    "balance_summary": [
        {
            "product": "string",
            "opening_balance": number,
            "money_in": number,
            "money_out": number,
            "closing_balance": number
        }
    ],
    "account_transactions": [
        {
            "date": "string",
            "description": "string",
            "money_in": number,
            "money_out": number,
            "balance": number
        }
    ],
    "iban_details": [
        {
            "iban": "string",
            "bic": "string"
        }
    ]
}

Usage

You can find sample data to use in the samples folder

  • Using Online Version

    • Visit the PDF Generator web application.
    • Upload a JSON file containing the data to be converted into a PDF document and it downloads instantly
  • Using Local Version

    • You need an API key to use the local version of the application. You can obtain an API key by signing up on the UniDoc website.

    You need to have .env file with the following content:

    apiKey=<your_api_key>
    PORT=8080
    useApi=false
    
    
    1. Local version is made of two aspects, first is, you can use the api which support upload of .json file and downloads the generated pdf file to your computer instantly. It requires some data in the .env file, there's a .env.example file you can follow through:

      • Clone the repository to your local machine.

      • Navigate to the project directory.

      • Set the useApi to true in the .env file.

      • Run the following command to start the server:

        make run
        

        or

        go run main.go 
        
      • Open your browser and visit http://localhost:8080.

      • Upload a JSON file containing the data to be converted into a PDF document using the defined schema above.

    2. Second is, you can run the application on your local machine and generate the pdf file with the useApi set to false or left empty string in the .env file.

    • Clone the repository to your local machine.
    • Navigate to the project directory.
    • Run the following command to generate a PDF statement:
      make run
      
      or
      go run main.go || go run main.go -json_file=<path_to_json_file> 
      
      e.g
          go run main.go -json_file=./samples/acc_stmt2.json
      

Testing

  • Run the following command to execute the unit tests:

    make test
    

    or

    go test -v ./...
    

Project Structure

main.go - The entry point of the application.
static/ - Contains the static files for the web application.
internal/
    generator/ - Contains the API client for interacting with the UniDoc API and the PDF generator.
    rest/ - Contains the REST API server implementation.
    types/ - Contains the data structures used in the application.
    utils/ - Contains utility functions used in the application.