{"id":25939225,"url":"https://github.com/FPTOJ-OJ/html-to-pdf-flask","last_synced_at":"2026-05-29T08:05:38.841Z","repository":{"id":280145381,"uuid":"941116305","full_name":"KienPC1234/html-to-pdf-flask","owner":"KienPC1234","description":"A simple Flask-based web service that converts HTML to PDF using PDFKit. This application provides an API that accepts HTML content and generates a PDF, returning it as a base64-encoded string. It supports running with both Flask's built-in server for development and uWSGI for production deployment.","archived":false,"fork":false,"pushed_at":"2025-03-01T14:58:40.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-25T18:02:34.496Z","etag":null,"topics":["flask","flask-application","pdf","pdf-generation","post","python","python3","uwsgi","wsgi-server"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KienPC1234.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-01T14:27:50.000Z","updated_at":"2025-03-01T14:58:43.000Z","dependencies_parsed_at":"2025-03-01T15:28:53.879Z","dependency_job_id":"ef18bf6c-49be-41df-ac70-9b8dacb12676","html_url":"https://github.com/KienPC1234/html-to-pdf-flask","commit_stats":null,"previous_names":["kienpc1234/html-to-pdf-flask"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KienPC1234/html-to-pdf-flask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KienPC1234%2Fhtml-to-pdf-flask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KienPC1234%2Fhtml-to-pdf-flask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KienPC1234%2Fhtml-to-pdf-flask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KienPC1234%2Fhtml-to-pdf-flask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KienPC1234","download_url":"https://codeload.github.com/KienPC1234/html-to-pdf-flask/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KienPC1234%2Fhtml-to-pdf-flask/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269289752,"owners_count":24392100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-07T02:00:09.698Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","flask-application","pdf","pdf-generation","post","python","python3","uwsgi","wsgi-server"],"created_at":"2025-03-04T04:16:02.348Z","updated_at":"2026-05-29T08:05:38.812Z","avatar_url":"https://github.com/KienPC1234.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Flask Application to Generate PDF from HTML\n\nThis application uses Flask and PDFKit to convert HTML to PDF and returns it as a base64 string. You can run this app in two ways: directly via Flask or using uWSGI for production environments.\n\n---\n\n### 1. Install Dependencies\n\nBefore running the app, ensure that the necessary dependencies are installed:\n\n1. **Install Python** (if not already installed):\n   ```bash\n   sudo apt install python3 python3-pip\n   ```\n\n2. **Install Python libraries**:\n   ```bash\n   pip install flask pdfkit\n   ```\n\n3. **Install wkhtmltopdf**:\n   This app uses `wkhtmltopdf` to convert HTML to PDF. Install `wkhtmltopdf` according to your operating system:\n\n   - **Linux (Debian/Ubuntu)**:\n     ```bash\n     sudo apt-get install wkhtmltopdf\n     ```\n\n   - **Fedora / RHEL / CentOS**:\n     ```bash\n     sudo yum install wkhtmltopdf\n     ```\n\n   - **Windows**:\n     Download the installer from the [wkhtmltopdf downloads page](https://wkhtmltopdf.org/downloads.html) and add the folder containing the `wkhtmltopdf` binary to your PATH.\n\n   - **Mac**:\n     Install via Homebrew:\n     ```bash\n     brew install wkhtmltopdf\n     ```\n\n---\n\n### 2. Running the Flask App\n\n#### Option 1: Run Directly with Flask\n\n1. Start the application with the desired `host` and `port` arguments:\n\n   ```bash\n   python main.py --host 0.0.0.0 --port 8888\n   ```\n\n   **Note**: You can change the `host` and `port` values as needed.\n\n2. The app will be running and accessible at `http://0.0.0.0:8888`.\n\n#### Option 2: Run with uWSGI\n\n1. **Install uWSGI**:\n   ```bash\n   pip install uwsgi\n   ```\n\n2. Create the `uwsgi.ini` configuration file with the following content:\n\n   ```ini\n   [uwsgi]\n   module = wsgi:app\n\n   http = 127.0.0.1:8888\n   processes = 4\n   threads = 2\n   logto = /var/log/uwsgi/myapp.log\n   chdir = /path/to/your/application\n   virtualenv = /path/to/your/virtualenv\n   ```\n\n3. **Run uWSGI**:\n   ```bash\n   uwsgi --ini uwsgi.ini\n   ```\n\n---\n\n### 3. Using the API\n\n- **POST Request** to the `/` endpoint with the following parameters:\n  - **`title`**: The title of the PDF.\n  - **`html`**: The HTML content to be converted to a PDF.\n\n  **Example cURL**:\n  ```bash\n  curl -d \"title=Hello\u0026html=Hello, World\" -X POST -H \"Content-Type: application/x-www-form-urlencoded\" http://localhost:8888\n  ```\n\n  **Response**:\n  ```json\n  {\n      \"success\": true,\n      \"pdf\": \"base64 encoded pdf content\"\n  }\n  ```\n\n  **Error Handling**: If an error occurs during the PDF generation or if the required parameters are missing, the response will include a `\"success\": false` status with a message describing the issue.\n\n  **Example error response**:\n  ```json\n  {\n      \"success\": false,\n      \"message\": \"Missing required parameters\"\n  }\n  ```\n\n---\n\n### 4. Project Structure\n\nYour project should have the following structure:\n\n```\n/your-application\n    ├── main.py           # Flask app\n    ├── wsgi.py           # Entry point for uWSGI\n    ├── requirements.txt  # Required libraries\n    └── uwsgi.ini         # uWSGI configuration file\n```\n\n---\n\n### 5. Troubleshooting\n\n- **ModuleNotFoundError**: Ensure that all Python libraries are installed correctly.\n- **PDFKit errors**: Ensure that `wkhtmltopdf` is installed and accessible by your Flask application.\n\n---\n\nThank you for using our app!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFPTOJ-OJ%2Fhtml-to-pdf-flask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFPTOJ-OJ%2Fhtml-to-pdf-flask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFPTOJ-OJ%2Fhtml-to-pdf-flask/lists"}