Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#60022 [@types/pdfkit] Add definition for m…
Browse files Browse the repository at this point in the history
…ixin Attachment by @longdoan7421

* Add mixin Attachment to pdfkit

* Update pdfkit-tests.ts for mixin Attachment
  • Loading branch information
longdoan7421 authored Apr 28, 2022
1 parent 702534d commit 7827d85
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion types/pdfkit/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ declare namespace PDFKit.Mixins {
textAnnotation(x: number, y: number, w: number, h: number, text: string, option?: AnnotationOption): this;
}

interface PDFAttachmentOptions {
name?: string;
type?: string;
description?: string;
hidden?: boolean;
creationDate?: Date;
modifiedDate?: Date;
}

interface PDFAttachment {
/**
* Embed content of `src` in PDF
*/
file(src: Buffer | ArrayBuffer | string, options?: PDFAttachmentOptions): this;
}

// The color forms accepted by PDFKit:
// example: "red" [R, G, B] [C, M, Y, K]
type ColorValue = string | PDFGradient | [number, number, number] | [number, number, number, number];
Expand Down Expand Up @@ -398,7 +414,8 @@ declare namespace PDFKit {
Mixins.PDFVector,
Mixins.PDFFont,
Mixins.PDFAcroForm,
Mixins.PDFMarking {
Mixins.PDFMarking,
Mixins.PDFAttachment {
/**
* PDF Version
*/
Expand Down
6 changes: 6 additions & 0 deletions types/pdfkit/pdfkit-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ doc.image('path/to/image.png', {
destination: 'lorem',
});

doc.file('/path/to/file/example.txt');

doc.file(Buffer.from('this will be a text file'), { name: 'example.txt' });

doc.file('data:text/plain;base64,YmFzZTY0IHN0cmluZw==', { name: 'base64.txt' });


// AcroForm
doc.initForm();
Expand Down

0 comments on commit 7827d85

Please sign in to comment.