Skip to content

Commit

Permalink
Merge pull request #8 from victorsoares96/docs/update-readme
Browse files Browse the repository at this point in the history
📝 docs: update readme
  • Loading branch information
victorsoares96 committed Apr 7, 2023
2 parents 51225b4 + e583631 commit 512838e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
59 changes: 51 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

<https://docs.github.com/en/enterprise-cloud@latest/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-an-organization>
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.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 512838e

Please sign in to comment.