Skip to content

Commit da62507

Browse files
authored
feat(transforms): add pdfinfo and pdfconvert to transforms (#192)
* feat(transforms): add pdfinfo and pdfconvert to transforms
1 parent 931e5cc commit da62507

File tree

3 files changed

+149
-1
lines changed

3 files changed

+149
-1
lines changed

src/lib/api/transform.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ export interface TransformOptions {
408408
orientation?: EUrlscreenshotOrientation;
409409
device?: string;
410410
} | true;
411+
pdfinfo?: {
412+
colorinfo?: boolean
413+
} | true;
414+
pdfconvert?: {
415+
pageorientation?: string
416+
pageformat?: string
417+
pages?: (string | number)[]
418+
};
411419
}
412420

413421
/**

src/schema/transforms.schema.spec.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,89 @@ describe('Transforms Schema', () => {
251251
}));
252252
});
253253
});
254+
255+
describe('Pdfinfo', () => {
256+
it('should validate correct params with bool value', () => {
257+
assert.ok(validate({
258+
pdfinfo: true,
259+
}));
260+
});
261+
262+
it('should validate correct params with color info', () => {
263+
assert.ok(validate({
264+
pdfinfo: {
265+
colorinfo: true,
266+
},
267+
}));
268+
});
269+
});
270+
271+
describe('Pdfconvert', () => {
272+
describe('Pages', () => {
273+
[[1,2], ['1-', 3], ['-2']].forEach((val) => {
274+
it(`should validate on correct page "${val}"`, () => {
275+
assert.ok(validate({
276+
pdfconvert: {
277+
pages: val,
278+
},
279+
}));
280+
});
281+
});
282+
283+
it('should return error on fail page "1a"', () => {
284+
assertFail(validate({
285+
pdfconvert: {
286+
pages: '1a',
287+
},
288+
}));
289+
});
290+
291+
});
292+
293+
describe('Page orientation', () => {
294+
it('should pass on correct orientation "landscape"', () => {
295+
assert.ok(validate({
296+
pdfconvert: {
297+
pageorientation: 'landscape',
298+
},
299+
}));
300+
});
301+
302+
it('should pass on correct orientation "portrait"', () => {
303+
assert.ok(validate({
304+
pdfconvert: {
305+
pageorientation: 'portrait',
306+
},
307+
}));
308+
});
309+
310+
it('should fail on wrong orientation "landscape1"', () => {
311+
assertFail(validate({
312+
pdfconvert: {
313+
pageorientation: 'landscape1',
314+
},
315+
}));
316+
});
317+
});
318+
319+
describe('Page format', () => {
320+
['a2', 'a3', 'a4', 'a5', 'b4', 'b5', 'letter', 'legal', 'tabloid'].forEach((val) => {
321+
it(`should when correct page format is provided ${val}`, () => {
322+
assert.ok(validate({
323+
pdfconvert: {
324+
pageformat: val,
325+
},
326+
}));
327+
});
328+
});
329+
330+
it('should fail on wrong page format ie a22', () => {
331+
assertFail(validate({
332+
pdfconvert: {
333+
pageformat: 'a22',
334+
},
335+
}));
336+
});
337+
});
338+
});
254339
});

src/schema/transforms.schema.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ export const TransformSchema = {
2222
type: 'object',
2323
additionalProperties: false,
2424
definitions: {
25+
pageFormatDef: {
26+
'$id': '#pageFormatDef',
27+
type: 'string',
28+
enum: ['a2', 'a3', 'a4', 'a5', 'b4', 'b5', 'letter', 'legal', 'tabloid'],
29+
},
30+
pageRangeDef: {
31+
'$id': '#pageRangeDef',
32+
type: 'array',
33+
uniqueItems: true,
34+
items: [{
35+
oneOf: [{
36+
type: 'integer',
37+
minimum: 1,
38+
}, {
39+
type: 'string',
40+
pattern: '^(\\d+(?:-\\d+)?)$|^(-\\d+)$|^(\\d+-)$',
41+
errorMessage: 'Param should be provided in one of the following formats: "1,2,3,5", "1-3", "1-", "-2" ',
42+
}],
43+
}],
44+
},
2545
facesDef: {
2646
'$id': '#facesDef',
2747
oneOf: [{
@@ -954,7 +974,7 @@ export const TransformSchema = {
954974
},
955975
pageformat: {
956976
type: 'string',
957-
enum: ['a3', 'a4', 'a5', 'b4', 'b5', 'letter', 'legal', 'tabloid'],
977+
enum: ['a2', 'a3', 'a4', 'a5', 'b4', 'b5', 'letter', 'legal', 'tabloid'],
958978
},
959979
pageorientation: {
960980
type: 'string',
@@ -1256,5 +1276,40 @@ export const TransformSchema = {
12561276
},
12571277
required: ['policy', 'signature'],
12581278
},
1279+
pdfinfo: {
1280+
oneOf: [{
1281+
type: 'boolean',
1282+
}, {
1283+
type: 'object',
1284+
properties: {
1285+
colorinfo: {
1286+
type: 'boolean',
1287+
},
1288+
},
1289+
}],
1290+
},
1291+
pdfconvert: {
1292+
type: 'object',
1293+
additionalProperties: false,
1294+
properties: {
1295+
pageorientation: {
1296+
type: 'string',
1297+
enum: ['portrait', 'landscape'],
1298+
},
1299+
pageformat: {
1300+
'$ref': '#pageFormatDef',
1301+
},
1302+
pages: {
1303+
'$ref': '#pageRangeDef',
1304+
},
1305+
},
1306+
oneOf: [{
1307+
required: ['pageorientation'],
1308+
}, {
1309+
required: ['pageformat'],
1310+
}, {
1311+
required: ['pages'],
1312+
}],
1313+
},
12591314
},
12601315
};

0 commit comments

Comments
 (0)