node-pdfbox-util
Version:
Package for integration with apache pdfbox
426 lines (422 loc) • 9.67 kB
text/typescript
import { NodePdfBoxUtilsBasic } from '../src/index';
const PDFPATH = "/mnt/c/_personal/_borrar/test_to_ofuscate.pdf";
// test('extract_text_fail_path', async () => {
// const filePath = ""
// const result = await NodePdfBoxUtilsBasic.getDocumentText('filePath', 'outputFile', { buffer: 1 });
// console.log("[ ~ test ~ result]:", result)
// expect(result.success).toBe(false);
// });
// test('extract_text_ok', async () => {
// const filePath = ""
// const result = await NodePdfBoxUtilsBasic.getDocumentText(PDFPATH, '', { buffer: 1 });
// console.log("[ ~ test ~ result]:", result)
// expect(result.success).toBe(true);
// });
// test('pdf_info', async () => {
// const filePath = ""
// const result = await NodePdfBoxUtilsBasic.getDocumentInfo(PDFPATH, { buffer: 1 });
// console.log("[pdf_info]:", result)
// expect(result.success).toBe(true);
// });
// test('pdf_split', async () => {
// const outputPath = "/home/aalmansa/temp/_varios/pdfsplit/pdf_split"
// //"{\"startPage\":1, \"numberOfPages\":5, \"recursive\":true}"
// const options = { startPage: 1, numberOfPages: 20, recursive: true, buffer: 1 }
// const result = await NodePdfBoxUtilsBasic.splitDocument(PDFPATH, outputPath, options);
// console.log("[pdf_info]:", result)
// expect(result.success).toBe(true);
// });
test('pdf_obfuscate', async () => {
const outputFile = "/mnt/c/_personal/_borrar/test_obfuscated.pdf"
const options = {
"resultObfuscate": [
{
"boundingBox": [
2.4117,
2.9319,
4.287,
2.9319,
4.287,
3.0348,
2.4117,
3.0348
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 1,
"text": "ignacio sancho gargallo"
},
{
"boundingBox": [
2.2163,
6.6548,
3.6971,
6.6548,
3.6971,
6.7893,
2.2163,
6.7893
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 1,
"text": "ignacio sancho gargallo"
},
{
"boundingBox": [
2.2163,
8.1272,
3.6971,
8.1272,
3.6971,
8.2617,
2.2163,
8.2617
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 1,
"text": "ignacio sancho gargallo"
},
{
"boundingBox": [
0.9548,
9.5997,
2.4627,
9.5997,
2.4627,
9.7341,
0.9548,
9.7341
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 1,
"text": "ignacio sancho gargallo"
},
{
"boundingBox": [
4.0209,
7.1244,
5.7036,
7.1244,
5.7036,
7.2526,
4.0209,
7.2526
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 1,
"text": "juan manuel ávila de encío"
},
{
"boundingBox": [
4.0209,
8.3514,
5.7036,
8.3514,
5.7036,
8.4796,
4.0209,
8.4796
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 1,
"text": "juan manuel ávila de encío"
},
{
"boundingBox": [
1.0159,
9.8238,
2.5166,
9.8238,
2.5166,
9.9795,
1.0159,
9.9795
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 1,
"text": "m.ª ángeles parra lucán"
},
{
"boundingBox": [
0.946,
10.0905,
2.7778,
10.0905,
2.7778,
10.2249,
0.946,
10.2249
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 1,
"text": "josé luis seoane spiegelberg"
},
{
"boundingBox": [
2.8207,
1.9541,
4.3332,
1.9541,
4.3332,
2.0885,
2.8207,
2.0885
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "ignacio sancho gargallo"
},
{
"boundingBox": [
3.0604,
1.3739,
4.6711,
1.3739,
4.6711,
1.5098,
3.0604,
1.5098
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "maría irene blasco lafarga"
},
{
"boundingBox": [
6.4477,
1.3755,
6.9322,
1.3755,
6.9322,
1.5091,
6.4477,
1.5091
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "joaquín"
},
{
"boundingBox": [
6.9791,
1.3753,
7.47,
1.3753,
7.47,
1.5091,
6.9791,
1.5091
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "esquivel"
},
{
"boundingBox": [
0.7989,
1.542,
1.2818,
1.542,
1.2818,
1.6489,
0.7989,
1.6489
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "estrada"
},
{
"boundingBox": [
6.6257,
1.5421,
6.9179,
1.5421,
6.9179,
1.6489,
6.6257,
1.6489
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "josé"
},
{
"boundingBox": [
6.9627,
1.542,
7.4729,
1.542,
7.4729,
1.6489,
6.9627,
1.6489
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "córdoba"
},
{
"boundingBox": [
0.7893,
1.7087,
1.2082,
1.7087,
1.2082,
1.8156,
0.7893,
1.8156
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "almela"
},
{
"boundingBox": [
3.0471,
1.7087,
5.5466,
1.7087,
5.5466,
1.8156,
3.0471,
1.8156
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "carlos gonzález-bueno catalán de ocón"
},
{
"boundingBox": [
1.7924,
2.8871,
3.4575,
2.8871,
3.4575,
3.0124,
1.7924,
3.0124
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "josé luis córdoba almela"
},
{
"boundingBox": [
3.4406,
1.3739,
4.6711,
1.3739,
4.6711,
1.5098,
3.4406,
1.5098
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "irene blasco lafarga"
},
{
"boundingBox": [
1.8997,
8.9093,
3.1878,
8.9093,
3.1878,
9.0451,
1.8997,
9.0451
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "irene blasco lafarga"
},
{
"boundingBox": [
3.0604,
1.3739,
4.6711,
1.3739,
4.6711,
1.5098,
3.0604,
1.5098
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 2,
"text": "maría irene blasco lafarga"
},
{
"boundingBox": [
0.791,
2.1115,
2.4598,
2.1115,
2.4598,
2.2368,
0.791,
2.2368
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 3,
"text": "josé luis córdoba almela"
},
{
"boundingBox": [
1.8999,
8.6245,
3.1882,
8.6245,
3.1882,
8.7603,
1.8999,
8.7603
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 3,
"text": "irene blasco lafarga"
},
{
"boundingBox": [
3.4341,
7.0052,
4.7793,
7.0052,
4.7793,
7.1122,
3.4341,
7.1122
],
"imageWidth": 8.2639,
"imageHeight": 11.6806,
"page": 4,
"text": "josé córdoba almela"
}
]
};
const result = await NodePdfBoxUtilsBasic.obfuscateDocument(PDFPATH, outputFile, options);
console.log("[pdf_obfuscate]:", result)
expect(result.success).toBe(true);
});