ai-pdf-builder 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ai-pdf-builder might be problematic. Click here for more details.

package/README.md ADDED
@@ -0,0 +1,507 @@
1
+ # ai-pdf-builder
2
+
3
+ Professional PDF generation from Markdown using Pandoc and LaTeX. Create beautiful whitepapers, memos, agreements, and term sheets with ease.
4
+
5
+ ## Features
6
+
7
+ - **Multiple Document Types**: Built-in templates for memos, agreements, term sheets, and whitepapers
8
+ - **Custom Styling**: Apply custom colors and branding to any template
9
+ - **TypeScript Support**: Full type definitions included
10
+ - **Flexible Output**: Get PDF as Buffer or save directly to file
11
+ - **Template System**: Use built-in templates or register your own
12
+ - **Security**: Built-in content sanitization for LaTeX safety
13
+
14
+ ## Prerequisites
15
+
16
+ This package requires **Pandoc** and **LaTeX** to be installed on your system:
17
+
18
+ ### macOS
19
+
20
+ ```bash
21
+ # Install Pandoc
22
+ brew install pandoc
23
+
24
+ # Install BasicTeX (minimal LaTeX)
25
+ brew install --cask basictex
26
+
27
+ # After installing BasicTeX, install required packages
28
+ sudo tlmgr update --self
29
+ sudo tlmgr install collection-fontsrecommended fancyhdr titlesec enumitem xcolor booktabs longtable geometry hyperref setspace array multirow listings
30
+ ```
31
+
32
+ ### Ubuntu/Debian
33
+
34
+ ```bash
35
+ # Install Pandoc and TeX Live
36
+ sudo apt-get update
37
+ sudo apt-get install -y pandoc texlive-latex-base texlive-latex-extra texlive-fonts-recommended
38
+ ```
39
+
40
+ ### Windows
41
+
42
+ 1. Download and install [Pandoc](https://pandoc.org/installing.html)
43
+ 2. Download and install [MiKTeX](https://miktex.org/download)
44
+
45
+ ### Docker
46
+
47
+ For containerized environments, use a Pandoc/LaTeX image:
48
+
49
+ ```dockerfile
50
+ FROM pandoc/latex:latest
51
+ ```
52
+
53
+ ## Installation
54
+
55
+ ```bash
56
+ npm install ai-pdf-builder
57
+ ```
58
+
59
+ Or with yarn:
60
+
61
+ ```bash
62
+ yarn add ai-pdf-builder
63
+ ```
64
+
65
+ ## Quick Start
66
+
67
+ ```typescript
68
+ import { generatePDF } from 'ai-pdf-builder';
69
+ import * as fs from 'fs';
70
+
71
+ const result = await generatePDF({
72
+ content: '# My Document\n\nThis is the content of my PDF.',
73
+ metadata: {
74
+ title: 'My First PDF',
75
+ author: 'John Doe',
76
+ date: 'January 2026'
77
+ }
78
+ });
79
+
80
+ if (result.success && result.buffer) {
81
+ fs.writeFileSync('output.pdf', result.buffer);
82
+ console.log(`PDF generated! Size: ${result.fileSize} bytes`);
83
+ }
84
+ ```
85
+
86
+ ## Usage Examples
87
+
88
+ ### Basic PDF Generation
89
+
90
+ ```typescript
91
+ import { generatePDF } from 'ai-pdf-builder';
92
+
93
+ const result = await generatePDF({
94
+ content: `
95
+ # Executive Summary
96
+
97
+ This document outlines our strategic initiatives for Q1 2026.
98
+
99
+ ## Key Objectives
100
+
101
+ - Increase market share by 15%
102
+ - Launch new product line
103
+ - Expand to 3 new markets
104
+
105
+ ## Timeline
106
+
107
+ Implementation begins February 1st, 2026.
108
+ `,
109
+ metadata: {
110
+ title: 'Q1 Strategic Plan',
111
+ subtitle: 'Confidential',
112
+ author: 'Strategy Team',
113
+ date: 'January 2026',
114
+ version: 'v1.0'
115
+ },
116
+ toc: true,
117
+ numberSections: true
118
+ });
119
+ ```
120
+
121
+ ### Generate a Business Memo
122
+
123
+ ```typescript
124
+ import { generateMemo } from 'ai-pdf-builder';
125
+
126
+ const memo = await generateMemo(
127
+ `
128
+ # Executive Summary
129
+
130
+ Key findings from our market analysis indicate strong growth potential.
131
+
132
+ ## Recommendations
133
+
134
+ 1. Accelerate product development
135
+ 2. Increase marketing budget by 20%
136
+ 3. Hire 5 additional engineers
137
+ `,
138
+ {
139
+ title: 'STRYKR PRISM',
140
+ subtitle: 'Intelligence Infrastructure for Financial Markets',
141
+ author: 'Ty Blackard, COO',
142
+ date: 'January 2026'
143
+ }
144
+ );
145
+ ```
146
+
147
+ ### Generate a Legal Agreement
148
+
149
+ ```typescript
150
+ import { generateAgreement } from 'ai-pdf-builder';
151
+
152
+ const agreement = await generateAgreement(
153
+ `
154
+ # Advisor Agreement
155
+
156
+ This Advisor Agreement is entered into as of the Effective Date.
157
+
158
+ ## 1. Services
159
+
160
+ The Advisor agrees to provide strategic guidance and introductions to potential investors.
161
+
162
+ ## 2. Compensation
163
+
164
+ In consideration of the Services, the Company shall pay the Advisor:
165
+
166
+ - 8% of cash raised through Advisor's introductions
167
+ - 0.25% equity per $250,000 raised, up to 1% maximum
168
+
169
+ ## 3. Term
170
+
171
+ This Agreement shall remain in effect for 12 months from the Effective Date.
172
+ `,
173
+ {
174
+ title: 'Capital Introduction Agreement',
175
+ subtitle: 'Strykr AI Inc.',
176
+ date: 'January 15, 2026'
177
+ }
178
+ );
179
+ ```
180
+
181
+ ### Generate a Term Sheet
182
+
183
+ ```typescript
184
+ import { generateTermsheet } from 'ai-pdf-builder';
185
+
186
+ const termsheet = await generateTermsheet(
187
+ `
188
+ # Series Seed Term Sheet
189
+
190
+ ## Investment Amount
191
+
192
+ $2,000,000 (Two Million Dollars)
193
+
194
+ ## Pre-Money Valuation
195
+
196
+ $8,000,000
197
+
198
+ ## Security Type
199
+
200
+ Series Seed Preferred Stock
201
+
202
+ ## Investors
203
+
204
+ Lead Investor: TBD
205
+ `,
206
+ {
207
+ title: 'Series Seed',
208
+ company: 'STRYKR AI',
209
+ doctype: 'Term Sheet',
210
+ date: 'January 2026'
211
+ }
212
+ );
213
+ ```
214
+
215
+ ### Generate a Whitepaper
216
+
217
+ ```typescript
218
+ import { generateWhitepaper } from 'ai-pdf-builder';
219
+
220
+ const whitepaper = await generateWhitepaper(
221
+ `
222
+ # Abstract
223
+
224
+ This paper presents a novel approach to financial market intelligence.
225
+
226
+ # Introduction
227
+
228
+ Financial markets generate vast amounts of data...
229
+
230
+ # Technical Architecture
231
+
232
+ Our system consists of three main components...
233
+
234
+ # Conclusion
235
+
236
+ We have demonstrated a scalable solution for...
237
+ `,
238
+ {
239
+ title: 'STRYKR PRISM',
240
+ subtitle: 'A Canonical Asset Resolution System',
241
+ author: 'Strykr AI Research',
242
+ version: 'v1.0',
243
+ date: 'January 2026'
244
+ }
245
+ );
246
+ ```
247
+
248
+ ### Custom Colors
249
+
250
+ ```typescript
251
+ import { generatePDF } from 'ai-pdf-builder';
252
+
253
+ const result = await generatePDF({
254
+ content: '# Branded Document\n\nWith custom colors!',
255
+ metadata: { title: 'Custom Branded PDF' },
256
+ customColors: {
257
+ primary: '#3B82F6', // Blue
258
+ secondary: '#6B7280', // Gray
259
+ accent: '#111827' // Dark
260
+ }
261
+ });
262
+ ```
263
+
264
+ ### Save to File
265
+
266
+ ```typescript
267
+ import { generatePDF } from 'ai-pdf-builder';
268
+
269
+ const result = await generatePDF({
270
+ content: '# My Document',
271
+ metadata: { title: 'Saved PDF' },
272
+ outputPath: './output/my-document.pdf'
273
+ });
274
+
275
+ if (result.success) {
276
+ console.log(`PDF saved to: ${result.path}`);
277
+ }
278
+ ```
279
+
280
+ ### Custom Templates
281
+
282
+ ```typescript
283
+ import { generatePDF, registerTemplate } from 'ai-pdf-builder';
284
+
285
+ // Register a custom template
286
+ registerTemplate({
287
+ name: 'company-branded',
288
+ path: './templates/company.latex',
289
+ description: 'Company branded template with logo',
290
+ supportedDocTypes: ['memo', 'whitepaper', 'report']
291
+ });
292
+
293
+ // Use the custom template
294
+ const result = await generatePDF({
295
+ content: '# Company Report',
296
+ metadata: { title: 'Annual Report' },
297
+ template: 'company-branded'
298
+ });
299
+ ```
300
+
301
+ ### List Available Templates
302
+
303
+ ```typescript
304
+ import { listTemplates } from 'ai-pdf-builder';
305
+
306
+ const templates = listTemplates();
307
+ templates.forEach(t => {
308
+ console.log(`${t.name}: ${t.description}`);
309
+ console.log(` Supports: ${t.supportedDocTypes.join(', ')}`);
310
+ });
311
+ ```
312
+
313
+ ### Check System Requirements
314
+
315
+ ```typescript
316
+ import { checkSystem } from 'ai-pdf-builder';
317
+
318
+ const status = checkSystem();
319
+ if (status.ready) {
320
+ console.log('System ready:', status.message);
321
+ } else {
322
+ console.error('Missing dependencies:', status.message);
323
+ if (!status.pandoc.available) {
324
+ console.error('Pandoc:', status.pandoc.error);
325
+ }
326
+ if (!status.latex.available) {
327
+ console.error('LaTeX:', status.latex.error);
328
+ }
329
+ }
330
+ ```
331
+
332
+ ## Integration with Next.js
333
+
334
+ ### API Route Example
335
+
336
+ ```typescript
337
+ // app/api/generate-pdf/route.ts
338
+ import { generatePDF } from 'ai-pdf-builder';
339
+ import { NextResponse } from 'next/server';
340
+
341
+ export async function POST(request: Request) {
342
+ const { content, title, type } = await request.json();
343
+
344
+ const result = await generatePDF({
345
+ content,
346
+ metadata: { title },
347
+ template: type === 'memo' ? 'memo' : 'default'
348
+ });
349
+
350
+ if (!result.success) {
351
+ return NextResponse.json({ error: result.error }, { status: 500 });
352
+ }
353
+
354
+ return new NextResponse(result.buffer, {
355
+ headers: {
356
+ 'Content-Type': 'application/pdf',
357
+ 'Content-Disposition': `attachment; filename="${title}.pdf"`
358
+ }
359
+ });
360
+ }
361
+ ```
362
+
363
+ ### Server Action Example
364
+
365
+ ```typescript
366
+ // app/actions/pdf.ts
367
+ 'use server';
368
+
369
+ import { generateMemo } from 'ai-pdf-builder';
370
+
371
+ export async function createMemo(content: string, title: string) {
372
+ const result = await generateMemo(content, { title });
373
+
374
+ if (!result.success) {
375
+ throw new Error(result.error);
376
+ }
377
+
378
+ return result.buffer?.toString('base64');
379
+ }
380
+ ```
381
+
382
+ ## API Reference
383
+
384
+ ### generatePDF(options: PDFOptions): Promise<PDFResult>
385
+
386
+ Main function to generate a PDF from Markdown content.
387
+
388
+ #### PDFOptions
389
+
390
+ | Property | Type | Required | Description |
391
+ |----------|------|----------|-------------|
392
+ | `content` | `string` | Yes | Markdown content to convert |
393
+ | `metadata` | `DocumentMetadata` | No | Document metadata (title, author, etc.) |
394
+ | `template` | `string` | No | Template name or path (default: 'default') |
395
+ | `customColors` | `ColorConfig` | No | Custom color configuration |
396
+ | `outputPath` | `string` | No | Save PDF to this path instead of returning buffer |
397
+ | `toc` | `boolean` | No | Include table of contents (default: true) |
398
+ | `tocDepth` | `number` | No | Depth of TOC (1-3, default: 2) |
399
+ | `numberSections` | `boolean` | No | Number sections (default: true) |
400
+ | `fontSize` | `number` | No | Font size in points (default: 11) |
401
+ | `margin` | `string` | No | Page margins (default: '1in') |
402
+ | `paperSize` | `'letter' \| 'a4'` | No | Paper size (default: 'letter') |
403
+ | `timeout` | `number` | No | Timeout in ms (default: 60000) |
404
+
405
+ #### PDFResult
406
+
407
+ | Property | Type | Description |
408
+ |----------|------|-------------|
409
+ | `success` | `boolean` | Whether generation succeeded |
410
+ | `buffer` | `Buffer` | Generated PDF (if outputPath not specified) |
411
+ | `path` | `string` | Path to saved PDF (if outputPath specified) |
412
+ | `error` | `string` | Error message if failed |
413
+ | `pageCount` | `number` | Estimated page count |
414
+ | `fileSize` | `number` | File size in bytes |
415
+ | `generationTime` | `number` | Generation time in ms |
416
+
417
+ ### Preset Functions
418
+
419
+ All preset functions have the signature:
420
+
421
+ ```typescript
422
+ function preset(
423
+ content: string,
424
+ metadata: DocumentMetadata,
425
+ options?: Partial<PDFOptions>
426
+ ): Promise<PDFResult>
427
+ ```
428
+
429
+ Available presets:
430
+ - `generateMemo` - Business memos
431
+ - `generateAgreement` - Legal agreements
432
+ - `generateTermsheet` - Investment term sheets
433
+ - `generateWhitepaper` - Technical whitepapers
434
+ - `generateReport` - Business reports
435
+ - `generateProposal` - Proposals
436
+ - `generateCapitalIntroAgreement` - Fundraising agreements
437
+ - `generateSAFE` - SAFE documents
438
+ - `generateNDA` - Non-disclosure agreements
439
+
440
+ ### Template Functions
441
+
442
+ - `getTemplate(name: string): string | null` - Get template content
443
+ - `listTemplates(): TemplateConfig[]` - List all templates
444
+ - `registerTemplate(config: TemplateConfig): void` - Register custom template
445
+ - `hasTemplate(name: string): boolean` - Check if template exists
446
+
447
+ ### Utility Functions
448
+
449
+ - `checkSystem(): SystemCheck` - Check Pandoc/LaTeX availability
450
+ - `checkPandoc(): PandocCheck` - Check Pandoc installation
451
+ - `checkLaTeX(): LaTeXCheck` - Check LaTeX installation
452
+ - `sanitizeContent(content: string): string` - Sanitize for LaTeX safety
453
+
454
+ ## Built-in Templates
455
+
456
+ | Template | Description | Best For |
457
+ |----------|-------------|----------|
458
+ | `default` | Clean, professional styling | Whitepapers, reports |
459
+ | `memo` | Compact business memo | Executive summaries |
460
+ | `agreement` | Formal legal document | Contracts, agreements |
461
+ | `termsheet` | Premium dark + gold finance | Term sheets, investment docs |
462
+
463
+ ## Troubleshooting
464
+
465
+ ### "Pandoc not found"
466
+
467
+ Install Pandoc:
468
+ - macOS: `brew install pandoc`
469
+ - Ubuntu: `sudo apt-get install pandoc`
470
+ - Windows: Download from [pandoc.org](https://pandoc.org)
471
+
472
+ ### "pdflatex not found"
473
+
474
+ Install LaTeX:
475
+ - macOS: `brew install --cask basictex`
476
+ - Ubuntu: `sudo apt-get install texlive-latex-base texlive-latex-extra`
477
+ - Windows: Install [MiKTeX](https://miktex.org)
478
+
479
+ ### Missing LaTeX packages
480
+
481
+ ```bash
482
+ sudo tlmgr install <package-name>
483
+ ```
484
+
485
+ Common packages needed:
486
+ ```bash
487
+ sudo tlmgr install fancyhdr titlesec enumitem xcolor booktabs longtable geometry hyperref
488
+ ```
489
+
490
+ ### Timeout errors
491
+
492
+ Increase the timeout for large documents:
493
+
494
+ ```typescript
495
+ const result = await generatePDF({
496
+ content: longContent,
497
+ timeout: 120000 // 2 minutes
498
+ });
499
+ ```
500
+
501
+ ## License
502
+
503
+ MIT
504
+
505
+ ## Contributing
506
+
507
+ Contributions welcome! Please read our contributing guidelines before submitting PRs.