Skip to content

Commit 2c42764

Browse files
author
chris
committed
feat(pdf): add the exportToPdf command
1 parent 5674a7a commit 2c42764

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/extensions/ExportPdf/ExportPdf.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ import { printEditorContent } from '@/utils/pdf';
55

66
import type { GeneralOptions, PaperSize, PageMargin } from '@/types';
77

8+
declare module '@tiptap/core' {
9+
interface Commands<ReturnType> {
10+
exportPdf: {
11+
exportToPdf: () => ReturnType
12+
}
13+
}
14+
}
15+
816
export interface ExportPdfOptions extends GeneralOptions<ExportPdfOptions> {
917
paperSize: PaperSize;
18+
title?: string;
1019
margins: {
1120
top?: PageMargin;
1221
right?: PageMargin;
@@ -21,6 +30,7 @@ export const ExportPdf = /* @__PURE__ */ Extension.create<ExportPdfOptions>({
2130
return {
2231
...this.parent?.(),
2332
paperSize: 'Letter',
33+
title: 'Echo Editor',
2434
margins: {
2535
top: '0.4in',
2636
right: '0.4in',
@@ -41,4 +51,13 @@ export const ExportPdf = /* @__PURE__ */ Extension.create<ExportPdfOptions>({
4151
}),
4252
};
4353
},
54+
addCommands() {
55+
return {
56+
exportToPdf:
57+
() =>
58+
({ editor }) => {
59+
return printEditorContent(editor, this.options);
60+
},
61+
};
62+
},
4463
});

src/utils/pdf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function printHtml(content: string, exportPdfOptions: ExportPdfOptions) {
1515

1616
const {
1717
paperSize,
18+
title = 'Echo Editor',
1819
margins: {
1920
top: marginTop,
2021
right: marginRight,
@@ -27,7 +28,7 @@ function printHtml(content: string, exportPdfOptions: ExportPdfOptions) {
2728
<!DOCTYPE html>
2829
<html lang="en">
2930
<head>
30-
<title>Echo Editor</title>
31+
<title>${title}</title>
3132
<meta charset="UTF-8">
3233
<meta name="viewport" content="width=device-width, initial-scale=1.0">
3334
<style>

0 commit comments

Comments
 (0)