|
1 | | -In this directory you will find sample calls to single endpoints, as well |
2 | | -as more advanced workflows presented in the DotNet framework |
| 1 | +# DotNET pdfRest API Samples |
| 2 | + |
| 3 | +This folder contains .NET 8 C# samples for the pdfRest API. It is a single console project that dispatches to many scenario‑focused samples: |
| 4 | + |
| 5 | +- Endpoint Examples/JSON Payload: upload a file, then call an endpoint with JSON. |
| 6 | +- Endpoint Examples/Multipart Payload: send files + parameters via multipart/form‑data. |
| 7 | +- Complex Flow Examples: multi‑step workflows across multiple endpoints. |
| 8 | + |
| 9 | +All samples are callable from a single dispatcher (`Program.cs`) using `dotnet run -- <command> [args]`. |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +- .NET 8 SDK installed (`dotnet --version` should print 8.x) |
| 14 | + |
| 15 | +## Setup |
| 16 | + |
| 17 | +1. From this folder, copy the environment template and set your key: |
| 18 | + |
| 19 | + ```bash |
| 20 | + cp .env.example .env |
| 21 | + # then edit .env and set your API key |
| 22 | + # PDFREST_API_KEY=your_api_key_here |
| 23 | + ``` |
| 24 | + |
| 25 | +2. Optional: set a regional API base (EU/GDPR). Add to `.env` if you want calls to remain in the EU: |
| 26 | + |
| 27 | + ``` |
| 28 | + PDFREST_URL=https://eu-api.pdfrest.com |
| 29 | + ``` |
| 30 | + |
| 31 | + For details see https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work |
| 32 | + |
| 33 | +Notes |
| 34 | +- This project loads `.env` via `DotNetEnv.Env.Load()` and reads settings from environment variables at runtime. |
| 35 | +- Never commit your real API key. Only `.env.example` is versioned. |
| 36 | + |
| 37 | +## Build |
| 38 | + |
| 39 | +Run from this folder: |
| 40 | + |
| 41 | +```bash |
| 42 | +dotnet build |
| 43 | +``` |
| 44 | + |
| 45 | +## Run: General Pattern |
| 46 | + |
| 47 | +The dispatcher prints a help summary. To see it: |
| 48 | + |
| 49 | +```bash |
| 50 | +dotnet run -- |
| 51 | +``` |
| 52 | + |
| 53 | +Run any sample via: |
| 54 | + |
| 55 | +```bash |
| 56 | +dotnet run -- <command> [args] |
| 57 | +``` |
| 58 | + |
| 59 | +Examples: |
| 60 | + |
| 61 | +- Convert to Markdown (JSON two‑step): |
| 62 | + ```bash |
| 63 | + dotnet run -- markdown-json /path/to/input.pdf |
| 64 | + ``` |
| 65 | +- Convert to PDF (multipart): |
| 66 | + ```bash |
| 67 | + dotnet run -- pdf-multipart /path/to/input.html |
| 68 | + ``` |
| 69 | +- Export form data (JSON two‑step): |
| 70 | + ```bash |
| 71 | + dotnet run -- exported-form-data /path/to/input.pdf |
| 72 | + ``` |
| 73 | +- Merge different file types (complex flow): |
| 74 | + ```bash |
| 75 | + dotnet run -- merge-different-file-types image.png slides.pptx |
| 76 | + ``` |
| 77 | + |
| 78 | +## Useful Commands (sampler) |
| 79 | + |
| 80 | +JSON two‑step (upload → JSON): |
| 81 | +- `markdown-json <pdf>` |
| 82 | +- `rasterized-pdf <pdf>` |
| 83 | +- `extracted-text <pdf>` |
| 84 | +- `extracted-images <pdf>` |
| 85 | +- `pdf-info <pdf>` |
| 86 | +- `exported-form-data <pdf>` |
| 87 | + |
| 88 | +Multipart (single call with files/params): |
| 89 | +- `pdf-multipart <file>` |
| 90 | +- `png-multipart|jpg-multipart|gif-multipart|bmp-multipart|tif-multipart <file>` |
| 91 | +- `word-multipart|excel-multipart|powerpoint-multipart <file>` |
| 92 | +- `merged-pdf-multipart <file1> <file2>` |
| 93 | +- `upload-multipart <file>` / `get-resource-multipart <id> [out]` |
| 94 | + |
| 95 | +Complex flows (multi‑step): |
| 96 | +- `merge-different-file-types <image> <ppt>` |
| 97 | +- `ocr-with-extract-text <pdf>` |
| 98 | +- `pdfa-3b-with-attachment <pdf> <xml>` |
| 99 | +- `preserve-word-document <officeFile>` |
| 100 | +- `protected-watermark <pdf>` |
| 101 | +- `redact-preview-and-finalize <pdf>` |
| 102 | + |
| 103 | +The dispatcher prints a complete list with arguments and brief descriptions. |
| 104 | + |
| 105 | +## Handy Runner Scripts |
| 106 | + |
| 107 | +Quick sanity runners are provided under `scripts/`: |
| 108 | + |
| 109 | +- JSON endpoints: `scripts/run_json_samples.sh /path/to/input_dir` |
| 110 | +- Multipart endpoints: `scripts/run_multipart_samples.sh /path/to/input_dir` |
| 111 | +- Complex flows: `scripts/run_complex_flow.sh /path/to/input_dir` |
| 112 | + |
| 113 | +Each script builds the project once, discovers suitable inputs inside the directory you provide, and runs a curated set of commands, reporting PASS/FAIL/SKIP. |
| 114 | + |
| 115 | +## Output & Verification |
| 116 | + |
| 117 | +- Most endpoints return JSON. The samples print the response body for inspection. |
| 118 | +- Some flows produce downloadable files; use `upload*`/`get-resource*` or JSON resource IDs to retrieve binary outputs when needed. |
| 119 | +- For binary verification, write bytes to disk and open the file (e.g., PDFs/images) in your preferred viewer. |
| 120 | + |
| 121 | +## Project Structure & Build Notes |
| 122 | + |
| 123 | +- Single .NET 8 console app; `Program.cs` dispatches to all samples. |
| 124 | +- Source is organized in scenario folders; each sample is a static class with `Execute(string[] args)`. |
| 125 | +- The project uses default compile globs and loads `.env` automatically. |
| 126 | +- If you add new samples, follow the header + wrapper pattern already present and register the command in `Program.cs`. |
| 127 | + |
| 128 | +## Region/GDPR |
| 129 | + |
| 130 | +Set `PDFREST_URL=https://eu-api.pdfrest.com` to keep processing in the EU region. By default, the base URL is `https://api.pdfrest.com`. |
| 131 | + |
| 132 | +## Support |
| 133 | + |
| 134 | +- API docs and endpoint details: https://pdfrest.com/docs |
| 135 | +- Solutions guides: https://pdfrest.com/solutions |
0 commit comments