diff --git a/README.md b/README.md index 7094687..ff1b326 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,59 @@ -# lib-template +# compress-pdf -## After all +This library provides compress your PDFs using ghostscript -Insert this secrets into your project repository. +## Installation - +Download ghostscript binaries available in releases page inside this repository. Example name: `gs_10.01.linux/windows.zip` or run: `npx compress-pdf --fetchBinaries [win32/linux]` to download binaries to inside **lib_folder/bin/gs** -```json -NPM_TOKEN= -CODECOV_TOKEN= +Then, extract and appoint: + +```sh +npm install compress-pdf +``` + +```sh +yarn add compress-pdf ``` +### Code Usage + +```tsx +import path from 'path'; +import fs from 'fs'; +import compressPdf from 'compress-pdf'; + +/** + * After this run: + * `npx compress-pdf --fetchBinaries [win32/linux]` + * This will download properly binaries to your current os. + */ + +(async () => { + const pdf = path.resolve(__dirname, 'A17_FlightPlan.pdf'); + const buffer = await compressPdf(pdf); + + const compressedPdf = path.resolve(__dirname, 'compressed_pdf.pdf'); + await fs.promises.writeFile(compressedPdf, buffer); +})(); +``` + +## CLI Usage + +``` +npx compress-pdf --file [PDF_FILE] --output ./compressed.pdf + +Options: + --file [PDF_FILE] (REQUIRED) + --output [COMPRESSED_PDF_FILE] (REQUIRED) + --resolution [ebook/printer/screen/prepress] + --compatibilityLevel [NUMBER] The compatibility pdf level + --binPath [DIRECTORY] The directory of ghostscript binaries. Default is lib_folder/bin/gs + --fetchBinaries [win32/linux] Download binaries to default binaries path +``` + +**You can see examples in [examples folder](https://github.com/victorsoares96/compress-pdf/tree/master/examples)** + ## License -lib-template is licensed under the [MIT License](http://www.opensource.org/licenses/mit-license.php). +This project is under MIT license, see [LICENSE.md](https://github.com/victorsoares96/compress-pdf/blob/master/LICENSE) for details. diff --git a/package.json b/package.json index 1c08c67..9151753 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "compress-pdf", - "version": "0.1.0", + "version": "0.2.0", "templateVersion": "1.3.0", "description": "An compress pdf library using ghostscript", "main": "dist/index.js", diff --git a/src/compress.ts b/src/compress.ts index 3fe7981..5e4286d 100644 --- a/src/compress.ts +++ b/src/compress.ts @@ -33,6 +33,8 @@ async function compress(file: string, options?: Options) { const readFile = await fs.promises.readFile(output); const buffer = Buffer.from(readFile); + await fs.unlinkSync(output); + return buffer; }