> ## 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

> Casos de uso reales de SDK Node.js/TypeScript: cargas, archivos PDF grandes, BYOS, RAG y ZIP.

# Ejemplos

## Convertir una carga de usuario (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 grande con rango de páginas

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

Combínelo con [`pdfIndex`](/docs/public/es/sdks/nodejs/reference#pdfindex) para saber qué rango ordenar sin descargar todo el PDF del lado del cliente.

## BYOS: sube el resultado directamente a tu almacenamiento

```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
```

Con `outputUrl`, API carga el Markdown directamente a su almacenamiento y devuelve un JSON liviano en lugar del cuerpo completo. Consulte [Compresión](/docs/public/es/concepts/compression) para `outputEncoding`.

## Canalización RAG con `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",
});
```

Consulte el [PDF Índice de agentes de IA](/docs/public/es/concepts/pdf-index-for-ai-agents).

## Procesar un 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>
  Los límites de tamaño y cantidad de archivos dentro de ZIP están en [Límites](/docs/public/es/concepts/limits). Un ZIP fuera de rango devuelve `413`, que SDK convierte en `MarkpdfPayloadTooLargeError`.
</Warning>

## Trabajadores de Cloudflare/tiempo de ejecución perimetral

```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 no utiliza las API de Node.js (se requieren `fs`, `Buffer`, etc.) en su núcleo; funciona igual en Workers, Deno Deploy o Vercel Edge Functions siempre que el tiempo de ejecución tenga `fetch`, `FormData` y `ReadableStream`.
