generated from victorsoares96/lib-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from victorsoares96/feat/handle-protected-files
✨ feat: added support to compress protected pdf files
- Loading branch information
Showing
8 changed files
with
100 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
import fs from 'fs'; | ||
import type pdfParser from 'pdf-parse'; | ||
|
||
// https://gitlab.com/autokent/pdf-parse/-/issues/24 | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const PDFParser = require('pdf-parse'); | ||
|
||
export async function parsePDF( | ||
file: string | Buffer, | ||
src: unknown, | ||
options?: pdfParser.Options | ||
): Promise<pdfParser.Result> { | ||
let dataBuffer: Buffer; | ||
|
||
if (typeof file === 'string') { | ||
dataBuffer = fs.readFileSync(file); | ||
} else dataBuffer = file; | ||
|
||
const data = await PDFParser(dataBuffer, options); | ||
const data = await PDFParser(src, options); | ||
|
||
return data; | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { compress } from '@/index'; | ||
|
||
(async () => { | ||
const pdf = path.resolve(__dirname, 'A17_FlightPlan-protected.pdf'); | ||
const buffer = await compress(pdf, { pdfPassword: 'a17' }); | ||
|
||
const compressedPdf = path.resolve(__dirname, 'compressed_protected_pdf.pdf'); | ||
await fs.promises.writeFile(compressedPdf, buffer); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters