Skip to content

Commit f1b8cd5

Browse files
authored
🤖 Merge PR DefinitelyTyped#72030 added pdf2docx typescript definitions by @manuzcheruz
1 parent c473373 commit f1b8cd5

File tree

5 files changed

+167
-0
lines changed

5 files changed

+167
-0
lines changed

types/pdf2docx/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts

types/pdf2docx/index.d.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Project: https://www.npmjs.com/package/pdf2docx
2+
// Definitions by: manuzcheruz <https://github.com/manuzcheruz>
3+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
4+
5+
/// <reference types="node" />
6+
7+
export class Parser {
8+
/**
9+
* Creates an instance of Parser for PDF processing
10+
* @param pdf_file Path to the PDF file or Buffer containing PDF data
11+
* @param password Optional password for encrypted PDF
12+
*/
13+
constructor(pdf_file: string | Buffer, password?: string);
14+
15+
/**
16+
* Parse and convert PDF to DOCX
17+
* @param docx_file Output DOCX file path
18+
* @param options Conversion options
19+
* @returns Promise resolving to parsing status
20+
*/
21+
parse(docx_file: string, options?: ConversionOptions): Promise<ParsingStatus>;
22+
23+
/**
24+
* Convert a specific range of pages
25+
* @param docx_file Output DOCX file path
26+
* @param start_page Starting page number (1-based)
27+
* @param end_page Ending page number (1-based)
28+
* @param options Conversion options
29+
* @returns Promise resolving to parsing status
30+
*/
31+
parsePages(
32+
docx_file: string,
33+
start_page: number,
34+
end_page: number,
35+
options?: ConversionOptions
36+
): Promise<ParsingStatus>;
37+
}
38+
39+
export interface ConversionOptions {
40+
start?: number;
41+
end?: number;
42+
pages?: number[];
43+
password?: string;
44+
tables?: TableOptions;
45+
images?: ImageOptions;
46+
font_settings?: FontSettings;
47+
page_margin?: MarginSettings;
48+
}
49+
50+
export interface TableOptions {
51+
extract_tables?: boolean;
52+
cell_border_width?: number;
53+
cell_margin?: number;
54+
}
55+
56+
export interface ImageOptions {
57+
extract_images?: boolean;
58+
max_width?: number;
59+
max_height?: number;
60+
}
61+
62+
export interface FontSettings {
63+
default_font_size?: number;
64+
default_font_family?: string;
65+
text_direction?: 'horizontal' | 'vertical';
66+
}
67+
68+
export interface MarginSettings {
69+
top?: number;
70+
bottom?: number;
71+
left?: number;
72+
right?: number;
73+
}
74+
75+
export interface ParsingStatus {
76+
pages_processed: number;
77+
status: string;
78+
errors?: ParseError[];
79+
}
80+
81+
export interface ParseError {
82+
message: string;
83+
page?: number;
84+
code?: string;
85+
}
86+
87+
/**
88+
* Convert PDF to DOCX
89+
* @param pdf_file Input PDF file path or Buffer
90+
* @param docx_file Output DOCX file path
91+
* @param options Conversion options
92+
* @returns Promise resolving to parsing status
93+
*/
94+
export function convert(
95+
pdf_file: string | Buffer,
96+
docx_file: string,
97+
options?: ConversionOptions
98+
): Promise<ParsingStatus>;

types/pdf2docx/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"private": true,
3+
"name": "@types/pdf2docx",
4+
"version": "0.0.9999",
5+
"projects": [
6+
"https://www.npmjs.com/package/pdf2docx"
7+
],
8+
"dependencies": {
9+
"@types/node": "*"
10+
},
11+
"devDependencies": {
12+
"@types/pdf2docx": "workspace:."
13+
},
14+
"owners": [
15+
{
16+
"name": "manuz cheruz",
17+
"githubUsername": "manuzcheruz"
18+
}
19+
]
20+
}

types/pdf2docx/pdf2docx-tests.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Parser, convert } from 'pdf2docx';
2+
3+
// Test the Parser class
4+
const parser = new Parser('test.pdf');
5+
parser.parse('output.docx', {
6+
start: 1,
7+
end: 5,
8+
tables: {
9+
extract_tables: true,
10+
cell_border_width: 1
11+
}
12+
}).then(status => {
13+
console.log(`Processed ${status.pages_processed} pages`);
14+
});
15+
16+
// Test the convert function
17+
convert('input.pdf', 'output.docx', {
18+
pages: [1, 2, 3],
19+
images: {
20+
extract_images: true,
21+
max_width: 800
22+
}
23+
}).then(status => {
24+
console.log(status.status);
25+
});

types/pdf2docx/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6"
6+
],
7+
"strictFunctionTypes": true,
8+
"noImplicitAny": true,
9+
"noImplicitThis": true,
10+
"strictNullChecks": true,
11+
"types": [],
12+
"noEmit": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"pdf2docx-tests.ts"
18+
]
19+
}

0 commit comments

Comments
 (0)