-
Notifications
You must be signed in to change notification settings - Fork 26
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 #42 from dichovsky/updatePdfJsToVersion4
update dfjs-dist to version ^4.0.269
- Loading branch information
Showing
24 changed files
with
1,608 additions
and
4,239 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
reporter: 'spec', | ||
timeout: '60000', | ||
spec: ['out/__tests__/**/*.js'], | ||
parallel: true | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,19 +1,57 @@ | ||
import { existsSync } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
import { expect } from 'chai'; | ||
import { test } from 'mocha'; | ||
import { existsSync, readFileSync } from 'node:fs'; | ||
import { parse, resolve } from 'node:path'; | ||
import { PngPageOutput, pdfToPng } from '../src'; | ||
import { comparePNG } from '../src/compare.png'; | ||
import { PDF_TO_PNG_OPTIONS_DEFAULTS } from '../src/const'; | ||
|
||
const pdfFilePath: string = resolve('./test-data/large_pdf.pdf'); | ||
const pdfBuffer: Buffer = readFileSync(pdfFilePath); | ||
|
||
test(`should convert PDF To PNG buffer (without saving to file)`, async () => { | ||
const pdfFilePath: string = resolve('test-data/large_pdf.pdf'); | ||
const pngPages: PngPageOutput[] = await pdfToPng(pdfFilePath, { | ||
viewportScale: 2.0, | ||
}); | ||
|
||
pngPages.forEach((pngPage: PngPageOutput) => { | ||
const expectedFilePath: string = resolve('test-data/pdf.to.buffer/expected', pngPage.name); | ||
const expectedFilePath: string = resolve('./test-data/pdf.to.buffer/expected', pngPage.name); | ||
const compareResult: number = comparePNG(pngPage.content, expectedFilePath); | ||
|
||
expect(existsSync(pngPage.path)).to.equal(false); | ||
expect(compareResult).to.equal(0); | ||
}); | ||
}); | ||
|
||
test(`should convert PDF To PNG without saving to file, output file mask is defined`, async () => { | ||
const pngPages: PngPageOutput[] = await pdfToPng(pdfBuffer, { | ||
viewportScale: 2.0, | ||
outputFileMask: 'large_pdf', | ||
}); | ||
|
||
pngPages.forEach((pngPage: PngPageOutput) => { | ||
const expectedFilePath: string = resolve('./test-data/pdf.to.buffer/expected', pngPage.name); | ||
const compareResult: number = comparePNG(pngPage.content, expectedFilePath); | ||
|
||
expect(existsSync(pngPage.path)).to.equal(false); | ||
expect(compareResult).to.equal(0); | ||
}); | ||
}); | ||
|
||
test(`should convert PDF To PNG without saving to file, output file mask is not defined`, async () => { | ||
const pngPages: PngPageOutput[] = await pdfToPng(pdfBuffer, { | ||
viewportScale: 2.0, | ||
}); | ||
|
||
pngPages.forEach((pngPage: PngPageOutput, index: number) => { | ||
const expectedFilePath: string = resolve( | ||
'test-data/pdf.to.buffer/expected', | ||
pngPage.name.replace(PDF_TO_PNG_OPTIONS_DEFAULTS.outputFileMask as string, parse(pdfFilePath).name), | ||
); | ||
const compareResult: number = comparePNG(pngPage.content, expectedFilePath); | ||
|
||
expect(existsSync(pngPage.path)).toBe(false); | ||
expect(compareResult).toBe(0); | ||
expect(pngPage.name).to.equal(`${PDF_TO_PNG_OPTIONS_DEFAULTS.outputFileMask as string}_page_${index + 1}.png`); | ||
expect(existsSync(pngPage.path)).to.equal(false); | ||
expect(compareResult).to.equal(0); | ||
}); | ||
}); |
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,19 +1,59 @@ | ||
import { expect } from 'chai'; | ||
import { test } from 'mocha'; | ||
import { readFileSync } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
import { PngPageOutput, pdfToPng } from '../src'; | ||
import { comparePNG } from '../src/compare.png'; | ||
|
||
test(`should convert PDF To PNG files`, async () => { | ||
const pdfFilePath: string = resolve('test-data/large_pdf.pdf'); | ||
const pdfFilePath: string = resolve('./test-data/large_pdf.pdf'); | ||
const pngPages: PngPageOutput[] = await pdfToPng(pdfFilePath, { | ||
outputFolder: 'test-results/pdf.to.file/actual', | ||
}); | ||
|
||
pngPages.forEach((pngPage: PngPageOutput) => { | ||
const expectedFilePath: string = resolve('test-data/pdf.to.file/expected', pngPage.name); | ||
const expectedFilePath: string = resolve('./test-data/pdf.to.file/expected', pngPage.name); | ||
const actualFileContent: Buffer = readFileSync(pngPage.path); | ||
const compareResult: number = comparePNG(actualFileContent, expectedFilePath); | ||
|
||
expect(compareResult).toBe(0); | ||
expect(compareResult).to.equal(0); | ||
}); | ||
}); | ||
|
||
test(`should convert specific PDF pages To PNG files`, async () => { | ||
const pdfFilePath: string = resolve('./test-data/large_pdf.pdf'); | ||
const pngPages: PngPageOutput[] = await pdfToPng(pdfFilePath, { | ||
outputFolder: 'test-results/pdf.pages.to.file/actual', | ||
pagesToProcess: [-1, 0, 2, 5, 7, 99, 999999], | ||
}); | ||
|
||
// Should skip page 99 since it's beyond PDF bounds | ||
expect(pngPages.length).to.equal(3); | ||
|
||
pngPages.forEach((pngPage: PngPageOutput) => { | ||
const expectedFilePath: string = resolve('./test-data/pdf.to.file/expected', pngPage.name); | ||
const actualFileContent: Buffer = readFileSync(pngPage.path); | ||
const compareResult: number = comparePNG(actualFileContent, expectedFilePath); | ||
|
||
expect(compareResult).to.equal(0); | ||
}); | ||
}); | ||
|
||
test(`should convert simple sample`, async () => { | ||
const pdfFilePath: string = resolve('./test-data/sample.pdf'); | ||
const pngPages: PngPageOutput[] = await pdfToPng(pdfFilePath, { | ||
outputFolder: 'test-results/sample/actual', | ||
disableFontFace: true, | ||
useSystemFonts: false, | ||
viewportScale: 2.0, | ||
}); | ||
|
||
expect(pngPages.length).to.equal(2); | ||
pngPages.forEach((pngPage: PngPageOutput) => { | ||
const expectedFilePath: string = resolve('./test-data/sample/expected', pngPage.name); | ||
const actualFileContent: Buffer = readFileSync(pngPage.path); | ||
const compareResult: number = comparePNG(actualFileContent, expectedFilePath); | ||
|
||
expect(compareResult).to.equal(0); | ||
}); | ||
}); |
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,26 +1,31 @@ | ||
import { test } from 'mocha'; | ||
import { resolve } from 'node:path'; | ||
import { pdfToPng } from '../src'; | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
chai.use(require('chai-as-promised')); | ||
|
||
test(`should throw error when page index = 0 is requested`, async () => { | ||
const pdfFilePath: string = resolve('test-data/large_pdf.pdf'); | ||
const pdfFilePath: string = resolve('./test-data/large_pdf.pdf'); | ||
|
||
await expect(async () => { | ||
await pdfToPng(pdfFilePath, { pagesToProcess: [0, 1, 2], strictPagesToProcess: true }); | ||
}).rejects.toThrow('Invalid pages requested'); | ||
await expect(pdfToPng(pdfFilePath, { pagesToProcess: [0, 1, 2], strictPagesToProcess: true })).to.be.rejectedWith( | ||
Error, | ||
); | ||
}); | ||
|
||
test(`should throw error when page index < 1 is requested`, async () => { | ||
const pdfFilePath: string = resolve('test-data/large_pdf.pdf'); | ||
const pdfFilePath: string = resolve('./test-data/large_pdf.pdf'); | ||
|
||
await expect(async () => { | ||
await pdfToPng(pdfFilePath, { pagesToProcess: [1, 2, -1], strictPagesToProcess: true }); | ||
}).rejects.toThrow('Invalid pages requested'); | ||
await expect(pdfToPng(pdfFilePath, { pagesToProcess: [1, 2, -1], strictPagesToProcess: true })).to.be.rejectedWith( | ||
Error, | ||
); | ||
}); | ||
|
||
test(`should throw error when page index > then file contains and strictPagesToProcess is enabled`, async () => { | ||
const pdfFilePath: string = resolve('test-data/large_pdf.pdf'); | ||
const pdfFilePath: string = resolve('./test-data/large_pdf.pdf'); | ||
|
||
await expect(async () => { | ||
await pdfToPng(pdfFilePath, { pagesToProcess: [1, 2, 1000], strictPagesToProcess: true }); | ||
}).rejects.toThrow('Invalid pages requested'); | ||
await expect( | ||
pdfToPng(pdfFilePath, { pagesToProcess: [1, 2, 1000], strictPagesToProcess: true }), | ||
).to.be.rejectedWith(Error); | ||
}); |
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
Oops, something went wrong.