diff --git a/types/pdf2image/index.d.ts b/types/pdf2image/index.d.ts new file mode 100644 index 0000000000..b02ccb8852 --- /dev/null +++ b/types/pdf2image/index.d.ts @@ -0,0 +1,53 @@ +// Type definitions for pdf2image 1.2 +// Project: https://bitbucket.org/RicardoCacheira/pdf2image#readme +// Definitions by: taoqf +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// TypeScript Version: 2.9 + +/** + * A token starts with the character '%' + * + * d - the page number, if the first page of the PDF is page 1 + * D - the page number, if the first page of the PDF is page 0 + * i - the processed page number, if the first processed page is page 1 + * I - the processed page number, if the first processed page is page 0 + * t - the total number of pages in the pdf + * T - the total of processed pages + * s - the name of the pdf file + * p - the path of the pdf file + * % - the character '%' + * {...} - a custom piece of code where all of the above values can be used + */ + +/// + +export type OutputFormat = ((pageNum: number, pageIndex: number, totalPagesProcessed: number, totalPDFPages: number, name: string, path: string, vm: typeof import ('vm')) => string) | string; + +export interface Options { + density: number; + height: number; + width: number; + outputType: 'jpg' | 'png' | '.jpg' | '.png'; + quality: number; + pages: '*' | string; // * | even | odd | '/1,/3,5-6,-8, 9-' + singleProcess: boolean; + backgroundColor: string; // #ffffff + outputFormat: OutputFormat; +} + +export interface ConvertedFile { + page: number; + index: number; + name: string; + path: string; +} + +export function convertPDF(pdfFilePath: string, options?: Partial): Promise; + +export interface Converter { + convertPDF(pdfFilePath: string): Promise; + convertPDFList(pdfList: string[]): Promise; +} + +export function compileConverter(options?: Partial): Converter; diff --git a/types/pdf2image/pdf2image-tests.ts b/types/pdf2image/pdf2image-tests.ts new file mode 100644 index 0000000000..5b12192b2d --- /dev/null +++ b/types/pdf2image/pdf2image-tests.ts @@ -0,0 +1,8 @@ +import { convertPDF } from 'pdf2image'; + +// converts all the pages of the given pdf using the default options +convertPDF('example.pdf').then( + (pageList) => { + console.log(pageList); + } +); diff --git a/types/pdf2image/tsconfig.json b/types/pdf2image/tsconfig.json new file mode 100644 index 0000000000..9593266a66 --- /dev/null +++ b/types/pdf2image/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "strictFunctionTypes": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pdf2image-tests.ts" + ] +} \ No newline at end of file diff --git a/types/pdf2image/tslint.json b/types/pdf2image/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pdf2image/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }