Merge pull request #30367 from taoqf/master

Add type definition pdf2image
This commit is contained in:
Armando Aguirre
2018-11-19 13:33:55 -08:00
committed by GitHub
4 changed files with 85 additions and 0 deletions

53
types/pdf2image/index.d.ts vendored Normal file
View File

@@ -0,0 +1,53 @@
// Type definitions for pdf2image 1.2
// Project: https://bitbucket.org/RicardoCacheira/pdf2image#readme
// Definitions by: taoqf <https://github.com/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
*/
/// <reference types="node" />
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<Options>): Promise<ConvertedFile[]>;
export interface Converter {
convertPDF(pdfFilePath: string): Promise<ConvertedFile[]>;
convertPDFList(pdfList: string[]): Promise<ConvertedFile[]>;
}
export function compileConverter(options?: Partial<Options>): Converter;

View File

@@ -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);
}
);

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }