shiveshnavin commited on
Commit
ba31655
·
1 Parent(s): 6781001
scripts/img2pdf.js CHANGED
@@ -28,13 +28,30 @@ for (const file of files) {
28
  file.endsWith('.jpeg')
29
  ) {
30
  const imgPath = path.join(inputFolder, file);
31
- const {width, height} = doc.openImage(imgPath);
32
 
33
- // Add a new page with the same dimensions as the image
34
- doc.addPage({size: [width, height], margin: 0});
35
 
36
- // Add the image without margins or padding, covering the full page
37
- doc.image(imgPath, 0, 0, {width, height});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
  }
40
 
 
28
  file.endsWith('.jpeg')
29
  ) {
30
  const imgPath = path.join(inputFolder, file);
31
+ const img = doc.openImage(imgPath);
32
 
33
+ // Add a new page with size 8.5 x 11 inches (612 x 792 points)
34
+ doc.addPage({size: [612, 792], margin: 0});
35
 
36
+ // Scale and center the image on the page
37
+ const pageWidth = 612;
38
+ const pageHeight = 792;
39
+ const imgWidth = img.width;
40
+ const imgHeight = img.height;
41
+
42
+ // Calculate scaling to fit the image within the page, preserving aspect ratio
43
+ const scaleFactor = Math.min(pageWidth / imgWidth, pageHeight / imgHeight);
44
+
45
+ // Calculate new image dimensions
46
+ const scaledWidth = imgWidth * scaleFactor;
47
+ const scaledHeight = imgHeight * scaleFactor;
48
+
49
+ // Calculate coordinates to center the image
50
+ const x = (pageWidth - scaledWidth) / 2;
51
+ const y = (pageHeight - scaledHeight) / 2;
52
+
53
+ // Add the image to the page, scaled to fit
54
+ doc.image(imgPath, x, y, {width: scaledWidth, height: scaledHeight});
55
  }
56
  }
57
 
src/paperdrive/PaperDriveComposition.tsx CHANGED
@@ -1,6 +1,6 @@
1
  import { Series } from "remotion";
2
  import { OriginalManuscript } from 'common-utils';
3
- import { PaperDrivePage } from './PaperDrivePage';
4
  import { PaperDriveIndex } from './PaperDriveIndex';
5
 
6
  export const PaperDriveComposition = (props: OriginalManuscript) => {
@@ -8,17 +8,27 @@ export const PaperDriveComposition = (props: OriginalManuscript) => {
8
  let fps = meta.fps
9
  return (
10
  <Series>
11
- <Series.Sequence durationInFrames={props.transcript[0].durationInSeconds * fps}>
12
- <PaperDriveIndex transcript={props.transcript[0]} />
13
- </Series.Sequence>
14
  {
15
- props.transcript.slice(1).map(transcript => {
16
- return (
17
- <Series.Sequence durationInFrames={transcript.durationInSeconds * fps}>
18
- <PaperDrivePage transcript={transcript} />
19
- </Series.Sequence>
20
- )
21
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  }
23
  </Series>
24
  );
 
1
  import { Series } from "remotion";
2
  import { OriginalManuscript } from 'common-utils';
3
+ import { PaperDrivePage, PaperDrivePageExtras } from './PaperDrivePage';
4
  import { PaperDriveIndex } from './PaperDriveIndex';
5
 
6
  export const PaperDriveComposition = (props: OriginalManuscript) => {
 
8
  let fps = meta.fps
9
  return (
10
  <Series>
 
 
 
11
  {
12
+ props.transcript
13
+ .filter(transcript => ['index', 'page'].includes(transcript.extras?.template))
14
+ .map(transcript => {
15
+ const extras = transcript.extras as PaperDrivePageExtras
16
+ let page = undefined
17
+ if (extras.template == 'index') {
18
+ page = <PaperDriveIndex transcript={transcript} />
19
+ }
20
+ else if (extras.template == 'page') {
21
+ page = <PaperDrivePage transcript={transcript} />
22
+ }
23
+ if (page == undefined) {
24
+ return undefined
25
+ }
26
+ return (
27
+ <Series.Sequence durationInFrames={transcript.durationInSeconds * fps}>
28
+ {page}
29
+ </Series.Sequence>
30
+ )
31
+ })
32
  }
33
  </Series>
34
  );
src/paperdrive/PaperDriveHorizontalCoverComposition.tsx CHANGED
@@ -1,27 +1,122 @@
1
  import { AbsoluteFill, Img, staticFile } from 'remotion';
2
  import React from 'react'
3
- import { loadFont } from "@remotion/google-fonts/MontserratAlternates";
4
  import { PaperDrivePoster } from './types';
 
5
 
6
- function adjustFontSize(text: string, fullFont?: number): number {
7
- if (!fullFont) {
8
- fullFont = 160
9
- }
10
- const wordCount = text.split(' ').length;
11
- return fullFont - (wordCount * (wordCount > 5 ? 4.5 : 1));
12
- }
13
-
14
- function splitSentence(sentence: string): [string, string] {
15
- const words = sentence.trim().split(' ');
16
- const lastWord = words[words.length - 1];
17
- const lastWordIndex = sentence.lastIndexOf(lastWord);
18
- const firstPart = sentence.slice(0, lastWordIndex).trim();
19
- const secondPart = sentence.slice(lastWordIndex).trim();
20
- return [firstPart, secondPart];
21
- }
22
 
23
  export const PaperDriveHorizontalCoverComposition: React.FC<PaperDrivePoster> = (props: PaperDrivePoster) => {
24
- const { fontFamily } = loadFont();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  return (
27
  <AbsoluteFill>
 
1
  import { AbsoluteFill, Img, staticFile } from 'remotion';
2
  import React from 'react'
 
3
  import { PaperDrivePoster } from './types';
4
+ import { loadFont } from '@remotion/google-fonts/Lato';
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  export const PaperDriveHorizontalCoverComposition: React.FC<PaperDrivePoster> = (props: PaperDrivePoster) => {
8
+ const data = [
9
+ {
10
+ "title": "ClassPad",
11
+ "text": "By Paper Drive",
12
+ "index": 0,
13
+ "status": true,
14
+ "durationInSeconds": 1,
15
+ "extras": {
16
+ "url": "https://app.mypaperdrive.com/notebooks/landing",
17
+ "marginLeft": "5vh",
18
+ "marginTop": "5vh",
19
+ "marginBottom": "5vh",
20
+ "leftMarginLineColor": "#e0e0e0",
21
+ "lineColor": "#bdbdbd",
22
+ "backgroundColor": "white",
23
+ "qr": {
24
+ "qrStyle": "dots",
25
+ "color": "#1a1a1c",
26
+ "logo": "./logo-transparent-grey.png",
27
+ "logoOpacity": 0.1,
28
+ "size": "7vh",
29
+ "position": {
30
+ "zIndex": 1000,
31
+ "borderWidth": 2,
32
+ "borderColor": "lightgray",
33
+ "borderRadius": 10,
34
+ "backgroundColor": "#fff",
35
+ "padding": 0.1,
36
+ "margin": 5,
37
+ "position": "absolute",
38
+ "top": 0,
39
+ "right": 0
40
+ }
41
+ },
42
+ "header": {
43
+ "fontFamily": "Lato, sans-serif",
44
+ "color": "lightgray",
45
+ "text_title": "Topic&nbsp;:",
46
+ "text_date": "Date&nbsp;&nbsp;:",
47
+ "text_page": "Page No. 1",
48
+ "underline_style": {
49
+ "textDecoration": "underline",
50
+ "borderBottom": "1px dotted black"
51
+ }
52
+ },
53
+ "footer": {
54
+ "text": "Scan the QR to view or attach photos, videos and other files on this page or Visit mypaperdrive.com/p/1",
55
+ "text_style": {
56
+ "fontSize": "1.1rem",
57
+ "fontFamily": "Lato, sans-serif",
58
+ "color": "lightgray"
59
+ }
60
+ }
61
+ }
62
+ },
63
+ {
64
+ "text": "Scan me",
65
+ "index": 0,
66
+ "status": true,
67
+ "title": "Page 0",
68
+ "extras": {
69
+ "url": "https://app.mypaperdrive.com/notebooks/page?page=0",
70
+ "marginLeft": "5vh",
71
+ "marginTop": "5vh",
72
+ "marginBottom": "5vh",
73
+ "leftMarginLineColor": "#e0e0e0",
74
+ "lineColor": "#bdbdbd",
75
+ "backgroundColor": "white",
76
+ "qr": {
77
+ "qrStyle": "dots",
78
+ "color": "#1a1a1c",
79
+ "logo": "./logo-transparent-grey.png",
80
+ "logoOpacity": 0.1,
81
+ "size": "7vh",
82
+ "position": {
83
+ "zIndex": 1000,
84
+ "borderWidth": 2,
85
+ "borderColor": "lightgray",
86
+ "borderRadius": 10,
87
+ "backgroundColor": "#fff",
88
+ "padding": 0.1,
89
+ "margin": 5,
90
+ "position": "absolute",
91
+ "top": 0,
92
+ "right": 0
93
+ }
94
+ },
95
+ "header": {
96
+ "fontFamily": "Lato, sans-serif",
97
+ "color": "lightgray",
98
+ "text_title": "Topic&nbsp;:",
99
+ "text_date": "Date&nbsp;&nbsp;:",
100
+ "text_page": "Page No. 0",
101
+ "underline_style": {
102
+ "textDecoration": "underline",
103
+ "borderBottom": "1px dotted black"
104
+ }
105
+ },
106
+ "footer": {
107
+ "text": "Scan the QR to view or attach photos, videos and other files on this page or Visit mypaperdrive.com/p/0",
108
+ "text_style": {
109
+ "fontSize": "1.1rem",
110
+ "fontFamily": "Lato, sans-serif",
111
+ "color": "lightgray"
112
+ }
113
+ }
114
+ },
115
+ "imageAbsPaths": [],
116
+ "durationInSeconds": 1
117
+ }
118
+ ]
119
+ loadFont();
120
 
121
  return (
122
  <AbsoluteFill>
src/paperdrive/PaperDriveIndex.css CHANGED
@@ -1,11 +1,8 @@
1
- table,
2
- th,
3
- td {
4
- border: 1px solid black;
5
- }
6
 
7
- th,
8
- td {
9
- padding: 8px;
10
- text-align: center;
11
- }
 
1
+ .border {
2
+ border: 1px solid black;
3
+ }
 
 
4
 
5
+ .center-padded {
6
+ padding: 8px;
7
+ text-align: center;
8
+ }
 
src/paperdrive/PaperDriveIndex.tsx CHANGED
@@ -1,8 +1,6 @@
1
  import { Transcript } from "common-utils"
2
- import React, { CSSProperties, } from "react"
3
- import { AbsoluteFill, Img, staticFile } from "remotion"
4
- import { QRCode } from 'react-qrcode-logo';
5
- import { RenderUtils } from '../RenderUtils';
6
  import { loadFont as loadLato } from "@remotion/google-fonts/Lato";
7
  import { loadFont as loadPoppins } from "@remotion/google-fonts/Poppins";
8
  import { PaperDrivePageExtras } from "./PaperDrivePage";
@@ -34,7 +32,7 @@ export function PaperDriveIndex({ transcript }: { transcript: Transcript }) {
34
  padding: '5%',
35
  width: '100%'
36
  }}>
37
- <table style={{
38
  fontFamily: extras?.header?.fontFamily,
39
  width: '100%',
40
  borderRadius: '10px',
@@ -46,7 +44,7 @@ export function PaperDriveIndex({ transcript }: { transcript: Transcript }) {
46
 
47
  {
48
  extras?.index?.columns?.map(col => {
49
- return <th dangerouslySetInnerHTML={{ __html: col.text }} style={{
50
  fontFamily: extras?.header?.fontFamily,
51
  width: col.width,
52
  ...tableHeadStyles
@@ -60,7 +58,7 @@ export function PaperDriveIndex({ transcript }: { transcript: Transcript }) {
60
  <tr key={row.id}>
61
  {
62
  extras?.index?.columns?.map(col => {
63
- return <td style={{
64
  padding: '20px',
65
  ...tableHeadStyles
66
  }} ></td>
 
1
  import { Transcript } from "common-utils"
2
+ import { CSSProperties, } from "react"
3
+ import { AbsoluteFill } from "remotion"
 
 
4
  import { loadFont as loadLato } from "@remotion/google-fonts/Lato";
5
  import { loadFont as loadPoppins } from "@remotion/google-fonts/Poppins";
6
  import { PaperDrivePageExtras } from "./PaperDrivePage";
 
32
  padding: '5%',
33
  width: '100%'
34
  }}>
35
+ <table className="border" style={{
36
  fontFamily: extras?.header?.fontFamily,
37
  width: '100%',
38
  borderRadius: '10px',
 
44
 
45
  {
46
  extras?.index?.columns?.map(col => {
47
+ return <th className="border center-padded" dangerouslySetInnerHTML={{ __html: col.text }} style={{
48
  fontFamily: extras?.header?.fontFamily,
49
  width: col.width,
50
  ...tableHeadStyles
 
58
  <tr key={row.id}>
59
  {
60
  extras?.index?.columns?.map(col => {
61
+ return <td className="border center-padded" style={{
62
  padding: '20px',
63
  ...tableHeadStyles
64
  }} ></td>
src/paperdrive/PaperDrivePage.tsx CHANGED
@@ -14,6 +14,7 @@ export type PaperDrivePageExtras = {
14
  lineColor?: string,
15
  marginLeft: string // "10%"
16
  marginTop: string // "10%"
 
17
  qr?: {
18
  logoOpacity?: number;
19
  logo?: string;
@@ -35,10 +36,12 @@ export type PaperDrivePageExtras = {
35
  text_title?: string // Title
36
  text_date?: string // Date
37
  text_page?: string // Page
 
38
  },
39
  footer?: {
40
  text?: string // Lorem ipsum dolor
41
- text_style?: CSSProperties
 
42
  },
43
  index?: {
44
  pageCount: number,
@@ -121,52 +124,82 @@ export function PaperDrivePage({ transcript }: { transcript: Transcript }) {
121
  left: extras?.marginLeft ?? '10%',
122
  paddingLeft: 20,
123
  height: extras?.marginTop,
 
124
  }}>
125
  <div style={{
126
  padding: 20,
127
  flex: 1,
128
  height: '100%',
129
  display: 'flex',
130
- justifyContent: 'space-evenly', // Even vertical spacing
131
- alignItems: 'flex-start', // Align items to the left (start of flex container)
132
- flexDirection: 'column' // Stack items in a column (Y-axis)
133
  }}>
134
- {extras?.header?.text_title && <h2 style={{
135
- display: 'inline-block'
136
- }}>
137
- <span dangerouslySetInnerHTML={{ __html: extras?.header?.text_title }} />
138
- <span style={{
139
- textDecoration: 'underline',
140
- marginLeft: '1rem',
141
- display: 'inline-block',
142
- width: '40vw',
143
- borderBottom: '1px dotted black',
144
- ...extras?.header?.underline_style
145
- }}>
146
- </span>
147
- </h2>}
148
- {
149
- extras?.header?.text_date &&
150
- <div style={{
151
- display: 'inline-block'
152
- }}>
153
- <span dangerouslySetInnerHTML={{ __html: extras?.header?.text_date }} />
154
- <span style={{
155
- textDecoration: 'underline',
156
- marginLeft: '1rem',
157
- display: 'inline-block',
158
- borderBottom: '1px dotted black',
159
- ...extras?.header?.underline_style,
160
- width: '10vw',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
- }}>
163
- </span>
164
- </div>
165
- }
166
- {
167
- extras?.header?.text_page &&
168
- <span dangerouslySetInnerHTML={{ __html: extras?.header?.text_page }} />
169
- }
170
 
171
  </div>
172
  </div>
@@ -185,13 +218,15 @@ export function PaperDrivePage({ transcript }: { transcript: Transcript }) {
185
  height: extras?.marginBottom ?? '10vh',
186
  position: 'absolute',
187
  left: 0,
188
- bottom: 0
 
189
  }}>
190
  <div style={{
191
  height: '100%',
192
  display: 'flex',
193
  justifyContent: 'center',
194
- alignItems: 'center'
 
195
  }}>
196
  {
197
  extras?.footer?.text && (
 
14
  lineColor?: string,
15
  marginLeft: string // "10%"
16
  marginTop: string // "10%"
17
+ template?: "page" | "index" | "one-cover" | "two-cover"
18
  qr?: {
19
  logoOpacity?: number;
20
  logo?: string;
 
36
  text_title?: string // Title
37
  text_date?: string // Date
38
  text_page?: string // Page
39
+ position?: CSSProperties
40
  },
41
  footer?: {
42
  text?: string // Lorem ipsum dolor
43
+ text_style?: CSSProperties,
44
+ position?: CSSProperties
45
  },
46
  index?: {
47
  pageCount: number,
 
124
  left: extras?.marginLeft ?? '10%',
125
  paddingLeft: 20,
126
  height: extras?.marginTop,
127
+ ...extras.header?.position
128
  }}>
129
  <div style={{
130
  padding: 20,
131
  flex: 1,
132
  height: '100%',
133
  display: 'flex',
134
+ justifyContent: 'space-evenly',
135
+ alignItems: 'flex-start',
136
+ flexDirection: 'column'
137
  }}>
138
+ <table>
139
+ <thead>
140
+ <tr>
141
+ <th></th>
142
+ <th></th>
143
+ </tr>
144
+ {extras?.header?.text_title && (
145
+ <tr>
146
+ <td style={{
147
+ textAlign: 'left'
148
+ }}>
149
+ <span dangerouslySetInnerHTML={{ __html: extras?.header?.text_title }} />
150
+ </td>
151
+ <td style={{
152
+ textAlign: 'left',
153
+ }}>
154
+ <span style={{
155
+ textDecoration: 'underline',
156
+ marginLeft: '1rem',
157
+ display: 'inline-block',
158
+ width: '40vw',
159
+ borderBottom: '1px dotted black',
160
+ ...extras?.header?.underline_style
161
+ }}>
162
+ </span>
163
+ </td>
164
+ </tr>
165
+
166
+ )}
167
+ {
168
+ extras?.header?.text_date &&
169
+ <tr>
170
+ <td >
171
+ <span dangerouslySetInnerHTML={{ __html: extras?.header?.text_date }} />
172
+ </td>
173
+ <td style={{
174
+ textAlign: 'left',
175
+ }}>
176
+ <span style={{
177
+ textDecoration: 'underline',
178
+ marginLeft: '1rem',
179
+ display: 'inline-block',
180
+ borderBottom: '1px dotted black',
181
+ ...extras?.header?.underline_style,
182
+ width: '10vw',
183
+
184
+ }}>
185
+ </span>
186
+ </td>
187
+ </tr>
188
+ }
189
+
190
+ {
191
+ extras?.header?.text_page &&
192
+ <tr>
193
+ <td>
194
+ <span dangerouslySetInnerHTML={{ __html: extras?.header?.text_page }} />
195
+ </td>
196
+ </tr>
197
+
198
+ }
199
+ </thead>
200
+ </table>
201
+
202
 
 
 
 
 
 
 
 
 
203
 
204
  </div>
205
  </div>
 
218
  height: extras?.marginBottom ?? '10vh',
219
  position: 'absolute',
220
  left: 0,
221
+ bottom: 0,
222
+ ...extras.footer?.position
223
  }}>
224
  <div style={{
225
  height: '100%',
226
  display: 'flex',
227
  justifyContent: 'center',
228
+ alignItems: 'center',
229
+ paddingBottom: 10,
230
  }}>
231
  {
232
  extras?.footer?.text && (