{"id":28758638,"url":"https://github.com/samirpaulb/filecompressor","last_synced_at":"2025-06-17T04:09:04.905Z","repository":{"id":298567467,"uuid":"500531107","full_name":"SamirPaulb/FileCompressor","owner":"SamirPaulb","description":"An online PDF file compression tool to reduce the size of a .pdf file. Python Flask is used to upload the file to a temporary location on the server. ","archived":false,"fork":false,"pushed_at":"2023-10-26T14:30:41.000Z","size":48013,"stargazers_count":25,"open_issues_count":3,"forks_count":16,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-11T20:25:25.190Z","etag":null,"topics":["c","css","file-compressor","flask","flask-application","html","javascript","nix","online-pdf-compressor","pdf","pdf-compression","pdfnet","pdfnetpython","python","python-server","python3","repl","reple","server","shell"],"latest_commit_sha":null,"homepage":"https://filecompressor.samirpaul.repl.co","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SamirPaulb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2022-06-06T17:32:08.000Z","updated_at":"2024-07-05T08:47:04.000Z","dependencies_parsed_at":"2025-06-11T20:35:31.802Z","dependency_job_id":null,"html_url":"https://github.com/SamirPaulb/FileCompressor","commit_stats":null,"previous_names":["samirpaulb/filecompressor"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SamirPaulb/FileCompressor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamirPaulb%2FFileCompressor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamirPaulb%2FFileCompressor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamirPaulb%2FFileCompressor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamirPaulb%2FFileCompressor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SamirPaulb","download_url":"https://codeload.github.com/SamirPaulb/FileCompressor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamirPaulb%2FFileCompressor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260288443,"owners_count":22986668,"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","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":["c","css","file-compressor","flask","flask-application","html","javascript","nix","online-pdf-compressor","pdf","pdf-compression","pdfnet","pdfnetpython","python","python-server","python3","repl","reple","server","shell"],"created_at":"2025-06-17T04:09:03.305Z","updated_at":"2025-06-17T04:09:04.888Z","avatar_url":"https://github.com/SamirPaulb.png","language":"Python","readme":"\u003c!-- Author: Samir Paul --\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eOnline PDF Compression Tool \u003c/h1\u003e\n\u003c/div\u003e\n\n### 💡About The Project:\n\nAn online PDF file compression tool to reduce the size of a .pdf file. Python Flask is used to upload the file to a temporary location on the server. \nIn the backend, using the ```PDFNetPython``` library that file gets reduced and saved to its final location. After download, the files are automatically deleted from the server after 1 hour. Technologies used in this project: ```Python3```, ```Flask```, ```C```, ```Shell```, ```Nix```, ```Replit```, ```Git```, ```HTML```, ```CSS```, ```JavaScript```.\n\n\n- [Live Demo 🚀 ](https://filecompressor.samirpaul.repl.co)\n\n## Video:\nhttps://user-images.githubusercontent.com/77569653/172896703-9e4998c1-40da-46ae-810e-780e47a391f9.mp4\n\n\n\n\n- Landing Page:\n![screenshot](https://raw.githubusercontent.com/SamirPaulb/assets/main/filecompressor-samirpaul1-repl-co-landing-page.png)\n\n\n### Flask File Uploading:\n In HTML form, the enctype property is set to ```\"multipart/form-data\"``` to publish the file to the URL.The URL handler extracts the file from the ```request.files []``` object and saves it to the required location. The path to the upload folder is defined as ```app.config['UPLOAD_FOLDER']``` and maximum size (in bytes) as \n```maximum size (in bytes)```.\nThe server-side flask script fetches the file from the request object using ```name = request.files['file'].filename```.\nOn successfully uploading the file, it is saved to the desired location on the server.\nHere’s the Python code for the Flask application.\n```python\nfrom flask import Flask, render_template, request\nfrom werkzeug import secure_filename\napp = Flask(__name__)\n\n@app.route('/upload')\ndef upload_file():\n   return render_template('upload.html')\n\t\n@app.route('/uploader', methods = ['GET', 'POST'])\ndef upload_file():\n   if request.method == 'POST':\n      f = request.files['file']\n      f.save(secure_filename(f.filename))\n      return 'file uploaded successfully'\n\t\t\nif __name__ == '__main__':\n   app.run(debug = True)\n```\n\n\n### How PDF is compressed in backend:\n```python\nimport os\nimport sys\nfrom PDFNetPython3.PDFNetPython import PDFDoc, Optimizer, SDFDoc, PDFNet\n\ndef compress_file(input_file: str, output_file: str):\n    if not output_file:\n        output_file = input_file\n    try:\n        PDFNet.Initialize()\n        doc = PDFDoc(input_file)\n        doc.InitSecurityHandler()\n        Optimizer.Optimize(doc)\n        doc.Save(output_file, SDFDoc.e_linearized)\n        doc.Close()\n    except Exception as e:\n        doc.Close()\n        return False\n    return True\n\nif __name__ == \"__main__\":\n    input_file = sys.argv[1]\n    output_file = sys.argv[2]\n    compress_file(input_file, output_file)\n```\n\n### File Download:\n```js\nfunction downloadFile(filename) {\n\tif(response !== null) {\n\t\tfname = response.filename;\n\t  var url = \"static/resource/\" + fname.toString(2);\n\t  console.log(url);\n\t    fetch(url)\n\t    .then(response =\u003e response.blob())\n\t    .then(blob =\u003e {\n\t      const link = document.createElement(\"a\");\n\t      link.href = URL.createObjectURL(blob);\n\t      link.download = fname;\n\t      link.click();\n\t  })\n\t  .catch(console.error);\n\t}\n}\n```\n\n\n## 🤔 How to contribute\n\n- [x] Fork this repository;\n- [x] Create a branch with your feature: `git checkout -b my-feature`;\n- [x] Commit your changes: `git commit -m \"feat: my new feature\"`;\n- [x] Push to your branch: `git push origin my-feature`.\n\nMade with ❤️ by [@SamirPaulb](https://github.com/SamirPaulb) :wave: [Get in touch](https://www.linkedin.com/in/SamirPaul)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamirpaulb%2Ffilecompressor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamirpaulb%2Ffilecompressor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamirpaulb%2Ffilecompressor/lists"}