> ## 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 use cases for markpdf-cpp: uploads, large PDFs, BYOS, RAG and ZIPs.

# Ejemplos

## Convert an uploaded file to memory

```cpp theme={null}
#include <markpdf/client.hpp>

markpdf::Client client("YOUR_API_KEY");

// When you already have the bytes in memory (e.g. read from a socket or multipart)
std::vector<uint8_t> bytes = readUploadedBytes();

markpdf::ConvertOptions opts;
opts.filename = "report.pdf";
opts.mode = markpdf::Mode::Fast;

auto result = client.convertBytes(bytes, opts);
if (result) {
    send(result->markdown);
}
```

`convertBytes(data, opts)` is the variant of `convertFile` for when the content is already in memory and you don't want to touch the filesystem.

## PDF large with page range

```cpp theme={null}
markdown::ConvertOptions opts;
opts.pages = "120-145";
opts.mode = markpdf::Mode::Fast;

auto result = client.convertFromUrl(
    "https://bucket.example.com/manual-800-papages.pdf?sig=...", opts);
```

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

## BYOS: upload the result directly to your storage

```cpp theme={null}
markpdf::ConvertOptions opts;
opts.responseFormat = markpdf::ResponseFormat::Json;
opts.outputUrl = presignedPutUrl;      // pre-signed PUT to your bucket
opts.outputHeadUrl = presignedHeadUrl; // optional: detect cache hits

auto result = client.convertFromUrl(pdfUrl, opts);
if (result) {
    std::cout << result->outputUrl.value() << "\n";
}
```

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`

```cpp theme={null}
markpdf::Client client("YOUR_API_KEY");
std::string pdf = "https://bucket.example.com/informe-anual.pdf?sig=...";

// 1. Index without converting the entire document
auto spineResult = client.pdfIndex(pdf);
if (!spineResult) return;
auto& spine = *spineResult;

// 2. Choose the section of interest
auto it = std::find_if(spine.sections.begin(), spine.sections.end(),
    [](const markpdf::Section& s) { return s.text.find("Resultados") != std::string::npos; });
int startPage = it->page;
auto next = std::find_if(it + 1, spine.sections.end(),
    [&](const markpdf::Section& s) { return s.page > startPage; });
int endPage = (next != spine.sections.end()) ? next->page - 1 : spine.pageCount;

// 3. Bring Markdown only from that section
markdown::ConvertOptions opts;
opts.pages = std::to_string(startPage) + "-" + std::to_string(endPage);
auto result = client.convertFromUrl(pdf, opts);
```

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

## Process a ZIP

```cpp theme={null}
markpdf::ConvertOptions opts;
opts.inputFormat = markpdf::InputFormat::Zip;
opts.responseFormat = markpdf::ResponseFormat::Json;

auto result = client.convertFile("documents.zip", opts);
if (result) {
    std::cout << result->markdown; // Markdown concatenated from the 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`, mapped to `ErrorKind::PayloadTooLarge`.
</Warning>

## Convert multiple files in parallel with `std::async`

```cpp theme={null}
#include <future>
#include <vector>

std::vector<std::string> paths = {"a.pdf", "b.pdf", "c.pdf"};
std::vector<std::future<markpdf::Result<markpdf::ConversionResult, markpdf::MarkpdfError>>> futures;

for (const auto& p : paths) {
    futures.push_back(std::async(std::launch::async, [&client, p]() {
        markpdf::ConvertOptions opts;
        opts.mode = markpdf::Mode::Fast;
        return client.convertFile(p, opts);
    }));
}

for (auto& f : futures) {
    auto result = f.get();
    if (result) {
        std::cout << result->filename << ": " << result->markdown.size() << " bytes\n";
    }
}
```

<Tip>
  `markpdf::Client` maintains an internal pool of `curl easy handle` to support concurrent calls from multiple threads without each having to create its own client.
</Tip>
