Skip to content

Commit a13fcad

Browse files
authored
🤖 Merge PR DefinitelyTyped#73129 feat(pdfkit): upgrade, update methods for PDFDocument by @hkleungai
1 parent 560071f commit a13fcad

File tree

2 files changed

+151
-23
lines changed

2 files changed

+151
-23
lines changed

‎types/pdfkit/index.d.ts‎

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,10 @@ declare namespace PDFKit.Mixins {
715715
}
716716

717717
interface PDFOutline {
718+
/**
719+
* The root outline
720+
*/
721+
outline: PDFKit.PDFOutline;
718722
initOutline(): void;
719723
endOutline(): void;
720724
}
@@ -848,26 +852,37 @@ declare namespace PDFKit {
848852
new(options?: PDFDocumentOptions): PDFDocument;
849853

850854
addPage(options?: PDFDocumentOptions): PDFDocument;
855+
continueOnNewPage(options?: PDFDocumentOptions): PDFDocument;
851856
bufferedPageRange(): { start: number; count: number };
852857
switchToPage(n?: number): PDFPage;
853858
flushPages(): void;
859+
860+
// See https://opensource.adobe.com/dc-acrobat-sdk-docs/library/pdfmark/pdfmark_Actions.html#view-destinations.
861+
// If `fitType` is missing, this method wll be invoked with (name, 'XYZ', null, null, null).
862+
addNamedDestination(name: string): void;
863+
addNamedDestination(name: string, fitType: "Fit"): void;
864+
addNamedDestination(name: string, fitType: "FitB"): void;
865+
addNamedDestination(name: string, fitType: "FitBH", top: number): void;
866+
addNamedDestination(name: string, fitType: "FitBV", left: number): void;
867+
addNamedDestination(name: string, fitType: "FitH", top: number): void;
868+
addNamedDestination(name: string, fitType: "FitR", x1: number, y1: number, x2: number, y2: number): void;
869+
addNamedDestination(name: string, fitType: "FitV", left: number): void;
870+
addNamedDestination(
871+
name: string,
872+
fitType: "XYZ",
873+
left: number | null,
874+
top: number | null,
875+
zoom: number | null,
876+
): void;
877+
addNamedDestination(name: string, fitType: string, ...args: number[]): void;
878+
879+
addNamedEmbeddedFile(name: string, ref: PDFKitReference): void;
880+
addNamedJavaScript(name: string, js: string): void;
881+
854882
ref(data: {}): PDFKitReference;
855883
addContent(data: any): PDFDocument;
856-
/**
857-
* Deprecated
858-
*/
859-
write(fileName: string, fn: any): void;
860-
/**
861-
* Deprecated. Throws exception
862-
*/
863-
output(fn: any): void;
864884
end(): void;
865885
toString(): string;
866-
867-
/**
868-
* The root outline
869-
*/
870-
outline: PDFOutline;
871886
}
872887
}
873888

‎types/pdfkit/pdfkit-tests.ts‎

Lines changed: 123 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,135 @@ var doc: PDFKit.PDFDocument = new PDFDocument({
3333
fontLayoutCache: true,
3434
});
3535

36+
// $ExpectType PDFDocument
37+
doc.addPage();
38+
// $ExpectType PDFDocument
39+
doc.addPage({});
40+
// $ExpectType PDFDocument
3641
doc.addPage({
37-
margin: 50,
42+
compress: true,
43+
info: {
44+
Title: "Sample PDF",
45+
Author: "John Doe",
46+
Subject: "Testing",
47+
Keywords: "typescript, pdf, test",
48+
},
49+
userPassword: "user123",
50+
ownerPassword: "owner456",
51+
permissions: {
52+
printing: "highResolution",
53+
modifying: false,
54+
copying: true,
55+
annotating: true,
56+
fillingForms: false,
57+
contentAccessibility: true,
58+
documentAssembly: false,
59+
},
60+
pdfVersion: "1.7",
61+
autoFirstPage: false,
62+
size: [595.28, 841.89],
63+
margin: 10,
64+
margins: { top: 20, left: 20, bottom: 20, right: 20 },
65+
layout: "portrait",
66+
font: "Helvetica",
67+
bufferPages: true,
68+
tagged: true,
69+
lang: "en-US",
70+
displayTitle: true,
71+
subset: "PDF/A-1",
72+
fontLayoutCache: false,
3873
});
3974

40-
doc.addPage({
41-
margins: {
42-
top: 50,
43-
bottom: 50,
44-
left: 72,
45-
right: 72,
75+
// $ExpectType PDFDocument
76+
doc.continueOnNewPage();
77+
// $ExpectType PDFDocument
78+
doc.continueOnNewPage({});
79+
// $ExpectType PDFDocument
80+
doc.continueOnNewPage({
81+
compress: true,
82+
info: {
83+
Title: "Sample PDF",
84+
Author: "John Doe",
85+
Subject: "Testing",
86+
Keywords: "typescript, pdf, test",
4687
},
88+
userPassword: "user123",
89+
ownerPassword: "owner456",
90+
permissions: {
91+
printing: "highResolution",
92+
modifying: false,
93+
copying: true,
94+
annotating: true,
95+
fillingForms: false,
96+
contentAccessibility: true,
97+
documentAssembly: false,
98+
},
99+
pdfVersion: "1.7",
100+
autoFirstPage: false,
101+
size: [595.28, 841.89],
102+
margin: 10,
103+
margins: { top: 20, left: 20, bottom: 20, right: 20 },
104+
layout: "portrait",
105+
font: "Helvetica",
106+
bufferPages: true,
107+
tagged: true,
108+
lang: "en-US",
109+
displayTitle: true,
110+
subset: "PDF/A-1",
111+
fontLayoutCache: false,
47112
});
48113

49-
doc.addPage({
50-
layout: "landscape",
51-
});
114+
// $ExpectType { start: number; count: number; }
115+
doc.bufferedPageRange();
116+
117+
// $ExpectType PDFPage
118+
doc.switchToPage();
119+
// $ExpectType PDFPage
120+
doc.switchToPage(2);
121+
122+
// $ExpectType void
123+
doc.flushPages();
124+
125+
// $ExpectType void
126+
doc.addNamedDestination("name");
127+
// $ExpectType void
128+
doc.addNamedDestination("name", "Fit");
129+
// $ExpectType void
130+
doc.addNamedDestination("name", "FitB");
131+
// $ExpectType void
132+
doc.addNamedDestination("name", "FitBH", 10);
133+
// $ExpectType void
134+
doc.addNamedDestination("name", "FitBV", 10);
135+
// $ExpectType void
136+
doc.addNamedDestination("name", "FitH", 10);
137+
// $ExpectType void
138+
doc.addNamedDestination("name", "FitR", 10, 20, 30, 40);
139+
// $ExpectType void
140+
doc.addNamedDestination("name", "FitV", 10);
141+
// $ExpectType void
142+
doc.addNamedDestination("name", "XYZ", 10, 20, 30);
143+
// Test the "default" overload
144+
// $ExpectType void
145+
doc.addNamedDestination("name", Math.random() < 0.5 ? "XYZ" : "Fit", 10, 20);
146+
147+
declare let ref: PDFKit.PDFKitReference;
148+
// $ExpectType void
149+
doc.addNamedEmbeddedFile("name", ref);
150+
151+
// $ExpectType void
152+
doc.addNamedJavaScript("name", "let it = 'some js script';");
153+
154+
// $ExpectType PDFKitReference
155+
doc.ref({});
156+
157+
// $ExpectType PDFDocument
158+
doc.addContent({});
159+
160+
// $ExpectType void
161+
doc.end();
162+
163+
// $ExpectType string
164+
doc.toString();
52165

53166
doc.info.Title = "Sample";
54167
doc.info.Author = "kila Mogrosso";

0 commit comments

Comments
 (0)