> ## Documentation Index
> Fetch the complete documentation index at: https://docs.markpdf.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Ejemplos

> Real SDK Node.js/TypeScript use cases: uploads, large PDFs, BYOS, RAG and ZIPs.

# Ejemplos

## Convert a user upload (Express)

```ts theme={null}
import express from "express";
import multer from "multer";
import { MarkpdfClient } from "@markpdf/sdk";

const app = express();
const upload = multer();
const client = new MarkpdfClient({ apiKey: process.env.MARKPDF_API_KEY! });

app.post("/upload", upload.single("file"), async (req, res) => {
  const markdown = await client.convertFile(req.file!.buffer, {
    filename: req.file!.originalname,
    mode: "fast",
  });
  res.type("text/markdown").send(markdown);
});
```

## PDF large with page range

```ts theme={null}
const markdown = await client.convertFromUrl(
  "https://bucket.example.com/manual-800-papages.pdf?sig=...",
  { pages: "120-145", mode: "fast" }
);
```

Combine it with [`pdfIndex`](/docs/sdks/nodejs/reference#pdfindex) to know what range to order without downloading the entire PDF client-side.

## BYOS: upload the result directly to your storage

```ts theme={null}
const result = await client.convertFromUrl(pdfUrl, {
  responseFormat: "json",
  outputUrl: presignedPutUrl,     // pre-signed PUT to your bucket
  outputHeadUrl: presignedHeadUrl, // optional: detect cache hits
});

console.log(result.cached);     // true si ya existía y no se reprocesó
console.log(result.outputUrl);  // URL final del Markdown subido
```

With `outputUrl`, the API uploads the Markdown directly to your storage and returns a lightweight JSON instead of the full body. See [Compression](/docs/concepts/compression) for `outputEncoding`.

## Pipeline RAG with `pdfIndex`

```ts theme={null}
import { MarkpdfClient } from "@markpdf/sdk";

const client = new MarkpdfClient({ apiKey: "YOUR_API_KEY" });
const PDF = "https://bucket.example.com/informe-anual.pdf?sig=...";

// 1. Index without converting the entire document
const spine = await client.pdfIndex(PDF);
console.log(`${spine.pageCount} pápages, ~${spine.estimatedTokensFull} full tokens`);

// 2. Choose the section of interest
const target = spine.sections.find((s) => s.text.includes("Resultados"))!;
const following = spine.sections.find((s) => s.page > target.page);
const endPage = following ? following.page - 1 : spine.pageCount;

// 3. Bring Markdown only from that section
const markdown = await client.convertFromUrl(PDF, {
  pages: `${target.page}-${endPage}`,
  mode: "fast",
});
```

See [PDF Index for AI agents](/docs/concepts/pdf-index-for-ai-agents).

## Process a ZIP

```ts theme={null}
const result = await client.convertFile(zipBuffer, {
  filename: "documents.zip",
  inputFormat: "zip",
  responseFormat: "json",
});

console.log(result.markdown); // Markdown concatenated from the supported documents inside the ZIP
```

<Warning>
  The file size and quantity limits within ZIP are in [Limits](/docs/concepts/limits). An out-of-range ZIP returns `413`, which SDK converts to `MarkpdfPayloadTooLargeError`.
</Warning>

```ts theme={null}
export default {
  async fetch(request: Request, env: { MARKPDF_API_KEY: string }) {
    const client = new MarkpdfClient({ apiKey: env.MARKPDF_API_KEY });
    const form = await request.formData();
    const file = form.get("file") as File;

    const markdown = await client.convertFile(file, { filename: file.name, mode: "fast" });
    return new Response(markdown, { headers: { "content-type": "text/markdown" } });
  },
};
```

SDK does not use Node.js APIs (`fs`, `Buffer` required, etc.) in its core — it works the same in Workers, Deno Deploy or Vercel Edge Functions as long as the runtime has `fetch`, `FormData` and `ReadableStream`.
