Integration Examples

Invoice Processing Example

Extract structured data from invoices using PDF conversion and AI analysis:

// Convert PDF to PNG
const convertResponse = await fetch('http://localhost:3000/api/convert/analyze', {
  method: 'POST',
  headers: {
    'X-Api-Token': 'YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    inputFormat: 'pdf',
    outputFormat: 'png',
    file: pdfBase64,
    prompt: `Extract the following information from this invoice and return as JSON:
    - vendor_name
    - vendor_address
    - invoice_number
    - invoice_date
    - items: array of {description, quantity, unit_price, total}
    - subtotal
    - tax
    - total`,
    model: 'openai',
    modelName: 'gpt-4o'
  })
});

const result = await convertResponse.json();
const invoiceData = JSON.parse(result.ai.text);
console.log(invoiceData);

Document OCR Example

Convert scanned documents to text:

const response = await fetch('http://localhost:3000/api/convert/analyze', {
  method: 'POST',
  headers: {
    'X-Api-Token': 'YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    inputFormat: 'pdf',
    outputFormat: 'txt',
    file: scannedPdfBase64,
    prompt: 'Extract all text from this document, preserving structure and formatting.',
    model: 'openai'
  })
});

Batch Processing

Process multiple files:

const files = ['file1.pdf', 'file2.pdf', 'file3.pdf'];

const results = await Promise.all(
  files.map(async (file) => {
    const base64 = await readFileAsBase64(file);
    const response = await fetch('http://localhost:3000/api/convert', {
      method: 'POST',
      headers: {
        'X-Api-Token': 'YOUR_API_TOKEN',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        inputFormat: 'pdf',
        outputFormat: 'png',
        file: base64
      })
    });
    return response.json();
  })
);