Skip to content

Commit 5cbb884

Browse files
authored
🤖 Merge PR DefinitelyTyped#72040 added type definitions for pdf2html by @manuzcheruz
1 parent 49c61c6 commit 5cbb884

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

types/pdf2html/.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/pdf2html/index.d.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Project: https://github.com/shebinleo/pdf2html
2+
// Definitions by: manuzcheruz <https://github.com/manuzcheruz>
3+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
4+
5+
/// <reference types="node" />
6+
7+
import { Stream } from "stream";
8+
9+
/**
10+
* Configuration options for PDF to HTML conversion
11+
*/
12+
interface PDF2HTMLOptions {
13+
binary?: string; // Path to the pdftohtml binary
14+
first_page?: number; // First page to convert
15+
last_page?: number; // Last page to convert
16+
complex?: boolean; // Generate complex output
17+
single_page?: boolean; // Generate a single HTML file
18+
no_background?: boolean; // No background images
19+
no_frames?: boolean; // No frames in HTML
20+
zoom?: number; // Zoom factor
21+
}
22+
23+
/**
24+
* Error type for PDF2HTML conversion errors
25+
*/
26+
interface PDF2HTMLError extends Error {
27+
code?: string;
28+
path?: string;
29+
syscall?: string;
30+
}
31+
32+
/**
33+
* Callback function type for async operations
34+
*/
35+
type PDF2HTMLCallback = (error: PDF2HTMLError | null, html?: string) => void;
36+
37+
/**
38+
* Convert PDF file to HTML synchronously
39+
* @param source - Path to PDF file or readable stream
40+
* @param options - Conversion options
41+
* @returns HTML string
42+
*/
43+
declare function pdf2htmlSync(source: string | Stream, options?: PDF2HTMLOptions): string;
44+
45+
/**
46+
* Convert PDF file to HTML asynchronously
47+
* @param source - Path to PDF file or readable stream
48+
* @param options - Conversion options
49+
* @param callback - Callback function
50+
*/
51+
declare function pdf2html(source: string | Stream, options: PDF2HTMLOptions, callback: PDF2HTMLCallback): void;
52+
53+
/**
54+
* Convert PDF file to HTML asynchronously (overload without options)
55+
* @param source - Path to PDF file or readable stream
56+
* @param callback - Callback function
57+
*/
58+
declare function pdf2html(source: string | Stream, callback: PDF2HTMLCallback): void;
59+
60+
declare namespace pdf2html {
61+
export { pdf2htmlSync };
62+
}
63+
64+
export = pdf2html;

types/pdf2html/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/pdf2html",
4+
"version": "3.1.9999",
5+
"projects": [
6+
"https://github.com/shebinleo/pdf2html#readme"
7+
],
8+
"dependencies": {
9+
"@types/node": "*"
10+
},
11+
"devDependencies": {
12+
"@types/pdf2html": "workspace:."
13+
},
14+
"owners": [
15+
{
16+
"name": "manuz cheruz",
17+
"githubUsername": "manuzcheruz"
18+
}
19+
]
20+
}

types/pdf2html/pdf2html-tests.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import pdf2html = require('pdf2html');
2+
import { Readable } from 'stream';
3+
4+
// Test async conversion with callback
5+
pdf2html('test.pdf', (error, html) => {
6+
if (error) {
7+
console.error(error);
8+
return;
9+
}
10+
console.log(html);
11+
});
12+
13+
// Test async conversion with options
14+
const options = {
15+
binary: '/usr/local/bin/pdftohtml',
16+
first_page: 1,
17+
last_page: 10,
18+
complex: true,
19+
single_page: false,
20+
no_background: true,
21+
no_frames: true,
22+
zoom: 1.5
23+
};
24+
25+
pdf2html('test.pdf', options, (error, html) => {
26+
if (error) {
27+
console.error(error);
28+
return;
29+
}
30+
console.log(html);
31+
});
32+
33+
// Test sync conversion
34+
const htmlSync = pdf2html.pdf2htmlSync('test.pdf');
35+
console.log(htmlSync);
36+
37+
// Test with stream input
38+
const stream = new Readable();
39+
stream.push('PDF content');
40+
stream.push(null);
41+
42+
pdf2html(stream, (error, html) => {
43+
if (error) {
44+
console.error(error);
45+
return;
46+
}
47+
console.log(html);
48+
});
49+
50+
// Test sync conversion with stream and options
51+
const htmlStreamSync = pdf2html.pdf2htmlSync(stream, {
52+
complex: true,
53+
zoom: 2.0
54+
});
55+
console.log(htmlStreamSync);

types/pdf2html/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+
"pdf2html-tests.ts"
18+
]
19+
}

0 commit comments

Comments
 (0)