|
| 1 | +# C++ Samples for pdfRest |
| 2 | + |
| 3 | +These C++ examples mirror the DotNET samples: JSON Payload (upload → JSON call), Multipart Payload (single multipart request), and a Complex Flow (convert then merge). All binaries are placed in `build/` for convenience. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | +- CMake 3.16+ and a C++20 compiler (Clang/GCC/MSVC) |
| 7 | +- vcpkg (package manager): https://vcpkg.io/en/getting-started |
| 8 | +- pdfRest API key: https://pdfrest.com/getstarted/ |
| 9 | + |
| 10 | +## Install Dependencies (vcpkg) |
| 11 | +- Install required libraries: |
| 12 | + - `vcpkg install cpr nlohmann-json` |
| 13 | +- Tip: set `VCPKG_ROOT` to your vcpkg folder (e.g., `~/vcpkg`). |
| 14 | + - Note: use the vcpkg CMake toolchain file; do not rely on `vcpkg integrate install`. |
| 15 | + |
| 16 | +## Build (macOS/Linux/Windows) |
| 17 | +- macOS/Linux: |
| 18 | + - `cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release` |
| 19 | + - `cmake --build build --parallel` |
| 20 | +- Windows (PowerShell): |
| 21 | + - `cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DCMAKE_BUILD_TYPE=Release` |
| 22 | + - `cmake --build build --config Release --parallel` |
| 23 | + - Note: specifying `-DCMAKE_TOOLCHAIN_FILE=...` is required to use vcpkg with CMake across platforms. |
| 24 | + |
| 25 | +## Environment |
| 26 | +- Copy `.env.example` to `.env` and set: |
| 27 | + - `PDFREST_API_KEY=your_api_key_here` |
| 28 | + - Optional: `PDFREST_URL=https://eu-api.pdfrest.com` (EU/GDPR region). More info: https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work |
| 29 | + |
| 30 | +## Run Samples |
| 31 | +- JSON two‑step (upload → JSON): |
| 32 | + - `./build/markdown_json /path/to/input.pdf` |
| 33 | + - `./build/rasterized_pdf_json /path/to/input.pdf` |
| 34 | +- Multipart (single POST): |
| 35 | + - `./build/markdown_multipart /path/to/input.pdf` |
| 36 | + - `./build/rasterized_pdf_multipart /path/to/input.pdf` |
| 37 | +- Complex flow (convert files to PDF, then merge): |
| 38 | + - `./build/merge_different_file_types image.png slides.pptx` |
| 39 | + |
| 40 | +Notes |
| 41 | +- Output: responses are printed as JSON; non‑2xx results exit non‑zero with concise errors. |
| 42 | +- Proxies: respect `HTTPS_PROXY` / `HTTP_PROXY` if set. |
| 43 | +- Paths with spaces: quote your paths on all platforms. |
0 commit comments