npm package: @or-sdk/markitdowner
Description: The `Markitdowner` class provides methods for converting PDF documents to Markdown format and generating descriptions for images using various providers and models. It is designed to interact with external services for document and image processing.
Latest version: 0.1.0-beta.3487.0

# Markitdowner

The `Markitdowner` class provides methods for converting PDF documents to Markdown format and generating descriptions for images using various providers and models. It is designed to interact with external services for document and image processing.

## Installation

To use the `Markitdowner` class, install the package:

```bash
npm install @or-sdk/markitdowner
```

## Usage

### Importing and Instantiating

To use the `Markitdowner` class, import it into your project:

```typescript
import { Markitdowner } from '@or-sdk/markitdowner';

const markitdowner = new Markitdowner({
  token: 'your-token',
  discoveryUrl: 'https://api.example.com',
  accountId: 'your-account-id',
  serviceUrl: 'https://service.example.com',
});
```

### Methods

#### `pdfToMarkdown`

Converts a PDF document to Markdown format.

**Parameters:**

- `params` (object):
  - `url` (string): The URL of the PDF document to be converted.
  - `include_image_base64` (boolean, optional): Flag to include images as base64 strings in the output.
  - `provider` (PDFProviders): The provider to use for the PDF processing.
- `options` (CallOptions, optional): Additional call options for the request.

**Returns:**

A promise that resolves to an object containing:

- `pages` (array of objects):
  - `images` (array of strings): Array of image URLs or paths for the page.
  - `index` (number): The index of the page.
  - `markdown` (string): The Markdown content of the page.
- `usage_info` (object):
  - `doc_size_bytes` (number): The size of the document in bytes.
  - `pages_processed` (number): The number of pages processed.

**Example:**

```typescript
const markdownResult = await markitdowner.pdfToMarkdown({
  url: 'https://example.com/document.pdf',
  provider: 'pdfProvider',
});
console.log(markdownResult);
```

#### `imageDescription`

Generates a description for an image using the provided data and options.

**Parameters:**

- `data` (object):
  - `url` (string): The URL of the image to be described.
  - `provider` (string): The name of the provider for the image processing service.
  - `model` (string): The model used for generating the image description.
- `options` (CallOptions, optional): Additional call options for the request.

**Returns:**

A promise that resolves to an object containing:

- `content` (string): The description of the image.

**Example:**

```typescript
const imageDescriptionResult = await markitdowner.imageDescription({
  url: 'https://example.com/image.jpg',
  provider: 'imageProvider',
  model: 'imageModel',
});
console.log(imageDescriptionResult);
```

## Error Handling

The `Markitdowner` class includes an `errorParser` to handle errors from API requests. Use the `parseError` method to parse and handle errors:

```typescript
try {
  const result = await markitdowner.pdfToMarkdown({
    url: 'https://example.com/document.pdf',
    provider: 'pdfProvider',
  });
} catch (err) {
  const parsedError = markitdowner.parseError(err);
  console.error(parsedError);
}
```