Back to list
doanchienthangdev

processing-documents

by doanchienthangdev

Omega Vibecode Kit

2🍴 1📅 Jan 21, 2026

SKILL.md


name: Processing Documents description: Processes PDF, DOCX, XLSX, and PPTX files with extraction, generation, and batch operations. Use when building document pipelines, extracting content from office files, or generating reports. category: tools triggers:

  • document processing
  • pdf extraction
  • docx parsing
  • excel manipulation
  • spreadsheet data
  • powerpoint generation
  • office documents

Processing Documents

Quick Start

import { PDFDocument } from 'pdf-lib';
import ExcelJS from 'exceljs';
import { Document, Packer, Paragraph, TextRun } from 'docx';

// Extract text from PDF
async function extractPDFText(buffer: Buffer): Promise<string> {
  const pdfDoc = await PDFDocument.load(buffer);
  const pages = pdfDoc.getPages();
  return pages.map(page => page.getTextContent()).join('\n\n');
}

// Read Excel spreadsheet
async function readExcel(buffer: Buffer) {
  const workbook = new ExcelJS.Workbook();
  await workbook.xlsx.load(buffer);
  return workbook.worksheets.map(sheet => ({
    name: sheet.name,
    rows: sheet.getSheetValues(),
  }));
}

// Generate Word document
async function generateDOCX(title: string, content: string[]): Promise<Buffer> {
  const doc = new Document({
    sections: [{
      children: [
        new Paragraph({ children: [new TextRun({ text: title, bold: true, size: 48 })] }),
        ...content.map(text => new Paragraph({ children: [new TextRun(text)] })),
      ],
    }],
  });
  return await Packer.toBuffer(doc);
}

Features

FeatureDescriptionGuide
PDF ExtractionExtract text, tables, images, and metadata from PDFsUse pdf-lib or pdf-parse for text extraction
PDF GenerationCreate PDFs from templates with data bindingUse pdf-lib with text, images, and table elements
DOCX ParsingParse Word documents preserving structureUse mammoth or docx library for parsing
DOCX GenerationGenerate Word documents with formattingUse docx package with paragraphs and tables
Excel ReadingRead spreadsheets with formulas and formattingUse exceljs to iterate sheets and cells
Excel GenerationCreate spreadsheets with charts and stylingUse exceljs with conditional formatting
PPTX GenerationCreate presentations with slides and chartsUse pptxgenjs for slide creation
Batch ProcessingProcess multiple documents with concurrencyUse p-queue for controlled parallel processing
Template EngineGenerate documents from templates with placeholdersUse docxtemplater for DOCX templates
StreamingHandle large files without memory exhaustionProcess files in chunks with streams

Common Patterns

Batch Document Processing

import PQueue from 'p-queue';

async function processBatch(files: string[], transform: (buffer: Buffer) => Promise<Buffer>) {
  const queue = new PQueue({ concurrency: 4 });
  const results: { file: string; success: boolean; error?: string }[] = [];

  for (const file of files) {
    queue.add(async () => {
      try {
        const buffer = await fs.readFile(file);
        const output = await transform(buffer);
        await fs.writeFile(file.replace(/\.\w+$/, '_processed.pdf'), output);
        results.push({ file, success: true });
      } catch (error) {
        results.push({ file, success: false, error: error.message });
      }
    });
  }

  await queue.onIdle();
  return results;
}

Excel Report Generation

async function generateReport(data: Record<string, any>[]): Promise<Buffer> {
  const workbook = new ExcelJS.Workbook();
  const sheet = workbook.addWorksheet('Report');

  // Add headers with styling
  const headers = Object.keys(data[0] || {});
  sheet.addRow(headers);
  sheet.getRow(1).font = { bold: true };
  sheet.getRow(1).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE0E0E0' } };

  // Add data rows
  data.forEach(row => sheet.addRow(headers.map(h => row[h])));

  // Auto-fit columns
  sheet.columns.forEach(col => { col.width = 15; });

  return Buffer.from(await workbook.xlsx.writeBuffer());
}

Invoice Generation from Template

import Docxtemplater from 'docxtemplater';
import PizZip from 'pizzip';

async function generateInvoice(templatePath: string, invoiceData: InvoiceData): Promise<Buffer> {
  const templateBuffer = await fs.readFile(templatePath);
  const zip = new PizZip(templateBuffer);
  const doc = new Docxtemplater(zip, { paragraphLoop: true, linebreaks: true });

  doc.render({
    invoiceNumber: invoiceData.number,
    date: invoiceData.date,
    customer: invoiceData.customer,
    items: invoiceData.items,
    total: invoiceData.total,
  });

  return doc.getZip().generate({ type: 'nodebuffer', compression: 'DEFLATE' });
}

PDF Table Extraction

async function extractTables(pdfBuffer: Buffer): Promise<ExtractedTable[]> {
  const pdfDoc = await PDFDocument.load(pdfBuffer);
  const tables: ExtractedTable[] = [];

  for (let i = 0; i < pdfDoc.getPageCount(); i++) {
    const page = pdfDoc.getPage(i);
    const content = await extractPageContent(page);
    const detectedTables = detectTableStructures(content);
    tables.push(...detectedTables.map(t => ({ ...t, pageNumber: i + 1 })));
  }

  return tables;
}

Best Practices

DoAvoid
Stream large files (>10MB) to prevent memory issuesLoading entire large files into memory
Validate file types before processingAssuming file extensions match content
Handle password-protected documents gracefullyIgnoring encrypted document errors
Preserve original formatting when transformingStripping formatting without user consent
Cache parsed results for repeated accessRe-parsing the same document multiple times
Use appropriate libraries per formatBuilding custom parsers for standard formats
Set file size limits for uploadsProcessing unbounded file sizes
Sanitize filenames and pathsUsing untrusted paths directly
Handle encoding issues (UTF-8, BOM)Assuming all files use the same encoding
Log processing errors with contextSilently failing on corrupt files
  • media-processing - Video and audio processing
  • image-processing - Image manipulation with Sharp
  • typescript - Type-safe document handling

References

Score

Total Score

60/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon