Skip to content

Examples: use documented converters, read the production catalog, save SplitPDF to temp, hide account secrets - #86

Merged
tomasr78 merged 7 commits into
mainfrom
examples-documented-converters
Nov 9, 2026
Merged

tomasr78 merged 7 commits into
mainfrom
examples-documented-converters

Conversation

@tomasr78

@tomasr78 tomasr78 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #85, which is stacked on #82. Please merge #82 and #85 first; until then this pull request also shows their three commits (3d70c44, 0d44e92, e6a4edd). This pull request's own changes are the last four commits: examples-run-as-written...examples-documented-converters

#85 made the examples run as written and listed these problems without fixing them, to stay focused.

Problem

  • Converters the API spec does not list. ConvertUrlToPdf (web -> pdf), WatermarkPdf (pdf -> watermark, pdf -> watermark-overlay) and Workflow (jpg -> zip) call converters that still convert on production but are not in the API spec (https://v2.convertapi.com/info/openapi, 332 paths on 2026-11-09), so neither the docs nor the converter pages describe them. GetConverterInfoDemo asks for any -> pdf, which is not in the spec either, and printed Failed to get converter info for any->pdf: Converter path '/convert/any/to/pdf' not found in OpenAPI document.
  • ConverterCatalogDemo read the staging catalog. It printed Base URI: https://v2.convertapi.com and then set ConvertApi.ApiBaseUri = "https://stag-v2.convertapi.com".
  • SplitPDF wrote into the repository. It saved its 19 result files to output/ in the working directory, which is the repository root with dotnet run --project Examples/SplitPDF, and .gitignore does not cover output/.
  • RetrieveUserInformation printed the account Secret and ApiKey. People paste console output into issues and support tickets.

Change

  • The examples call the documented converters. Their parameters have the same names, so only the converter names change:

    Example Before Now Parameters the example sets
    ConvertUrlToPdf web -> pdf html -> pdf Url, FileName
    WatermarkPdf pdf -> watermark pdf -> text-watermark Text, FontSize, VerticalAlignment
    WatermarkPdf pdf -> watermark-overlay pdf -> pdf-watermark OverlayFile, Style, Opacity
    Workflow jpg -> zip file -> zip Files
    GetConverterInfoDemo any -> pdf file -> pdf none, it only reads the converter info

    The doc comments link the pages of the new converters: https://www.convertapi.com/html-to-pdf, https://www.convertapi.com/pdf-to-text-watermark and https://www.convertapi.com/pdf-to-pdf-watermark. All three are in the site's sitemap; /web-to-pdf, /pdf-to-watermark and /pdf-to-watermark-overlay are not.

  • Workflow names the parameter, new ConvertApiFileParam("Files", firstTask), because file -> zip takes Files. Under the default name File, the SDK sends files[0], files[1], ... only when there are two or more files; the single JPG of a one-page PDF would go as file and be rejected. One file posted to /convert/file/to/zip under each name:

    Files    -> 200
    Files[0] -> 200
    File     -> 400 {"Code":4000,"Message":"Parameter validation error.","InvalidParameters":{"Files":["Files array item count must be greater than 0."]}}
    
  • ConverterCatalogDemo no longer sets ApiBaseUri, so it reads the production catalog, at the address it prints.

  • SplitPDF saves to a SplitPDF folder in the temp folder (Path.GetTempPath()), in the same six subfolders, and prints where.

  • RetrieveUserInformation no longer prints Secret and ApiKey; it still prints the account status, name, email and conversion counts.

Only the examples change, not the library, so there is no CHANGELOG entry.

Verification

Run on macOS (arm64) with .NET SDK 10.0.401 against the production API on 2026-11-09, with CONVERTAPI_TOKEN set and nothing edited. $TMPDIR is the local temp folder; account fields are masked as ***.

  • Build: dotnet build ConvertApi.sln: 0 errors. Merged into current main, the CI steps (dotnet build ConvertApi.sln -c Release -p:ContinuousIntegrationBuild=true, then dotnet test ConvertApi.Tests/ConvertApi.Tests.csproj) give 0 errors and 4 of 4 tests passed. The 3 warnings are the ones Examples: read the token from CONVERTAPI_TOKEN and find the sample files from any folder #85 lists (CS8603 and CS8625 in ConverterCatalogDemo, CS0618 in GetConverterInfoDemo), in lines this pull request does not change.
  • Runs: the seven changed examples ran with dotnet run --project Examples/<Name> < /dev/null from the repository root and exited with code 0.
    • ConvertUrlToPdf: html -> pdf saved $TMPDIR/web-example.pdf, but Wikimedia answered with its "Too many requests" page instead of the article, as it also did for the old web -> pdf (see "Found, not changed"). With another page, https://www.w3.org/, html -> pdf returned the whole web page, 2 pages with its images and styles.
    • WatermarkPdf: a 10-page PDF with the text watermark at the bottom of every page and the overlay PDF (the ConvertAPI logo) stamped at 50% opacity. Its first page looks the same as the result of the old watermark and watermark-overlay converters with the same parameters, apart from the time in the text.
    • Workflow: test.zip holds the six page JPGs, test.jpg and test-2.jpg to test-6.jpg.
    • GetConverterInfoDemo: title, accepted formats and parameters of all four converters, no failure.
    • ConverterCatalogDemo: while it ran, its only connection (seen with lsof) went to 159.8.243.100, an address of v2.convertapi.com. Before this change it connected only to 52.117.108.126, stag-v2.convertapi.com, while it printed the production address. Staging and production serve the same spec today (328 converters each), so the printed output does not show the difference.
    • SplitPDF: 19 PDFs in the six subfolders of $TMPDIR/SplitPDF. No output/ folder in the repository, and git status is clean after the run.
    • RetrieveUserInformation: no Secret or ApiKey line.
$ dotnet run --project Examples/ConvertUrlToPdf < /dev/null
Converting web page https://en.wikipedia.org/wiki/Data_conversion to PDF...
The web page PDF saved to $TMPDIR/web-example.pdf

$ dotnet run --project Examples/WatermarkPdf < /dev/null
The example shows how to watermark PDF with text and put overlay PDF
PDF sent for text watermarking...
PDF sent for overlay watermarking...
The PDF saved to $TMPDIR/watermarked-a4aacfd1-3a63-4b81-8589-c3786fdd00d8.pdf
Elapsed 00:00:01.9811620

$ dotnet run --project Examples/Workflow < /dev/null
Converting PDF to JPG and compressing result files with ZIP
Conversions done. Cost: 1. Total files created: 6
Conversions done. Cost: 1. Total files created: 1
File saved to $TMPDIR/test.zip

$ dotnet run --project Examples/SplitPDF < /dev/null
All splits complete! Files saved to $TMPDIR/SplitPDF
$ cd $TMPDIR && find SplitPDF -type f | sort
SplitPDF/bookmark-splits-example/Chapter 1.pdf
SplitPDF/bookmark-splits-example/Chapter 2.pdf
SplitPDF/bookmark-splits-example/Chapter 3.pdf
SplitPDF/extract-specific-pages-example/sample-10.pdf
SplitPDF/extract-specific-pages-example/sample-5.pdf
SplitPDF/extract-specific-pages-example/sample-6.pdf
SplitPDF/extract-specific-pages-example/sample-7.pdf
SplitPDF/extract-specific-pages-example/sample-8.pdf
SplitPDF/extract-specific-pages-example/sample-9.pdf
SplitPDF/merged-output-example/sample.pdf
SplitPDF/pattern-splits-example/sample-1-2.pdf
SplitPDF/pattern-splits-example/sample-11-12.pdf
SplitPDF/pattern-splits-example/sample-3-5.pdf
SplitPDF/pattern-splits-example/sample-6-7.pdf
SplitPDF/pattern-splits-example/sample-8-10.pdf
SplitPDF/split-by-ranges-example/sample-1.pdf
SplitPDF/split-by-ranges-example/sample-3.pdf
SplitPDF/split-by-ranges-example/sample-5-7.pdf
SplitPDF/text-pattern-splits-example/sample-1-12.pdf

$ dotnet run --project Examples/RetrieveUserInformation < /dev/null
Active=True
FullName=***
Email=***
ConversionsTotal=***
ConversionsConsumed=***
GetConverterInfoDemo and ConverterCatalogDemo output
$ dotnet run --project Examples/GetConverterInfoDemo < /dev/null | grep -E '^(Converter|Title|AcceptsFormats|AcceptsMultiple|Failed)'
Converter docx -> pdf
Title           : DOCX to PDF API
AcceptsFormats  : .doc,.docx
AcceptsMultiple : False
Converter pdf -> pptx
Title           : PDF to PPTX API
AcceptsFormats  : .pdf
AcceptsMultiple : False
Converter pdf -> merge
Title           : Merge PDF API
AcceptsFormats  : .pdf
AcceptsMultiple : True
Converter file -> pdf
Title           : File to PDF API
AcceptsFormats  : .bmp,.csv,.djvu,.doc,.docx,.dot,.dotx,.dwf,.dwfx,.dwg,.dxf,.eml,.eps,.epub,.gif,.heic,.heif,.htm,.html,.ico,.jfif,.jpeg,.jpg,.key,.log,.md,.mobi,.msg,.numbers,.odc,.odf,.odg,.odp,.ods,.odt,.pages,.png,.potx,.pps,.ppsx,.ppt,.pptx,.prn,.ps,.psd,.pub,.rtf,.svg,.tif,.tiff,.txt,.vsd,.vsdx,.webp,.wpd,.xls,.xlsb,.xlsx,.xltx
AcceptsMultiple : False

$ dotnet run --project Examples/ConverterCatalogDemo < /dev/null   # first lines and the GetConverter section
=== ConvertAPI Converter Catalog Demo ===
Base URI: https://v2.convertapi.com

Loading catalog (OpenAPI fetch + parse)...
Loaded.

--- GetAllConverters() ---
Total converters: 328
[...]
--- GetConverter(src, dst) ---
Found: md -> html | MD to HTML API
Source extensions: md -> Destination extensions: html
Found: pdf -> docx | PDF to DOCX API
Source extensions: pdf -> Destination extensions: docx
Found: docx -> pdf | DOCX to PDF API
Source extensions: doc,docx -> Destination extensions: pdf
Found: pdf -> merge | Merge PDF API
Source extensions: pdf -> Destination extensions: pdf
[...]
--- Reload() ---
Reloaded. Converters count now: 328

Demo finished.

Found, not changed

  • Wikipedia rate-limits the web page conversion, whichever converter fetches it. ConvertUrlToPdf converts https://en.wikipedia.org/wiki/Data_conversion. On 2026-11-09 Wikimedia answered ConvertAPI's renderer with its "Too many requests. Please email noc@wikimedia.org" page, so the PDF showed that error instead of the article: html -> pdf on all 12 tries over 35 minutes, and the old web -> pdf on 3 of 4 tries (the first rendered the 3-page article). From a developer machine the page answers 200 to the same HeadlessChrome user agent, so it looks like rate limiting of ConvertAPI's servers. The same URL is in the Go, Java, Node, PHP, Python and Ruby examples and in code samples on convertapi.com, so a different demo page, or a change in the converter, belongs in its own change.

🤖 Generated with Claude Code

tomasr78 and others added 7 commits November 6, 2026 16:48
…x300

The example already converts page 1 straight to JPG, but its comment
still described the old extract-then-convert chain and linked
pdf-to-extract, which is now the AI data-extraction converter.

ScaleImage and ScaleProportions are not pdf -> jpg parameters and the API
ignored them, so the 300x300 request came back 300x388 for test.pdf.
FitToSize keeps the thumbnail inside 300x300 (231x300).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…les from any folder

The examples reached Examples/TestFiles through paths relative to the working
directory, three levels up in six places and four in nine. From bin/Debug/net10.0
only the four-level form reached TestFiles, from the project or repository folder
neither did, and the backslash paths do not resolve on macOS or Linux.
UploadOnceReuseTwice and Workflow climbed four levels from AppContext.BaseDirectory,
and SplitPDF read files/sample.pdf from the working directory.

Each example's .csproj now copies the sample files it uses to TestFiles/ next to
the program, and Program.cs reads them through AppContext.BaseDirectory, so the
examples run from dotnet run, Visual Studio and Rider, on any OS.

The examples read the API token from the CONVERTAPI_TOKEN environment variable,
the name the README quick start (#83) and the C# pages on convertapi.com use,
instead of a hard-coded "api_token". Examples/README.md says how to set it and
run an example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Process.Start(path) uses UseShellExecute = false on .NET Core and later, so it
tries to execute the saved PDF itself and throws Win32Exception on every OS
(on macOS: "Permission denied"). The result was already saved and its path
printed, so the example now ends there, like the other examples.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
web -> pdf, pdf -> watermark, pdf -> watermark-overlay and jpg -> zip still
convert on production, but the API spec (https://v2.convertapi.com/info/openapi)
does not list them, so neither the docs nor the converter pages describe them.
The examples now call the documented converters, which take the same parameters:

- ConvertUrlToPdf: html -> pdf (Url, FileName).
- WatermarkPdf: pdf -> text-watermark (Text, FontSize, VerticalAlignment) and
  pdf -> pdf-watermark (OverlayFile, Style, Opacity). The result looks the same
  as with the old converters.
- Workflow: file -> zip. The JPGs go in as Files, the converter's parameter.
  Under the default name File, a single JPG (from a one-page PDF) is rejected
  with "Files array item count must be greater than 0".
- GetConverterInfoDemo: any -> pdf is not in the spec and printed "Converter
  path '/convert/any/to/pdf' not found in OpenAPI document."; the demo shows
  file -> pdf instead, which also accepts many formats.

The doc comments link the pages of the converters the examples now use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The demo printed the production address and then set ApiBaseUri to staging
(https://stag-v2.convertapi.com), so it listed the staging converters. It now
reads https://v2.convertapi.com, the address it prints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The example wrote its 19 result files to output/ in the working directory,
which is the repository root with dotnet run --project Examples/SplitPDF, and
output/ is not in .gitignore. It now saves them in a SplitPDF folder in the
temp folder, like the other examples save theirs, and prints where.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
People paste console output into issues and support tickets. The example still
prints the account status, name, email and conversion counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 10:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the .NET SDK example updates.

No open issues 🎉

What changed in this PR

Updates the .NET SDK examples to use documented converters, production catalog data, and safer output handling without changing the library. The diff also includes the portability and thumbnail fixes from stacked PRs #82 and #85.

Changes:

  • Uses documented converter names and explicitly supplies Files for ZIP conversion, including single-file inputs.
  • Removes the staging catalog override, saves SplitPDF results under the temp folder, and stops printing account credentials.
  • Reads tokens from CONVERTAPI_TOKEN, bundles sample inputs for working-directory independence, and corrects thumbnail sizing and run instructions.
File Description
Examples/​Workflow/​Workflow.csproj Copies the sample PDF into build output.
Examples/​Workflow/​Program.cs Uses portable inputs and documented ZIP conversion with Files.
Examples/​WatermarkPdf/​WatermarkPdf.csproj Copies both watermark sample PDFs.
Examples/​WatermarkPdf/​Program.cs Updates converters and documentation links; removes automatic file launching.
Examples/​UploadOnceReuseTwice/​UploadOnceReuseTwice.csproj Copies the sample DOCX into build output.
Examples/​UploadOnceReuseTwice/​README.md Documents environment-token setup and command-line execution.
Examples/​UploadOnceReuseTwice/​Program.cs Reads the environment token and bundled DOCX.
Examples/​SplitPDF/​Program.cs Uses a bundled input and saves results under the temp folder.
Examples/​SplitAndMergePdf/​SplitAndMergePdf.csproj Copies the sample PDF into build output.
Examples/​SplitAndMergePdf/​Program.cs Reads the environment token and bundled PDF.
Examples/​RetrieveUserInformation/​Program.cs Reads the environment token and omits credential output.
Examples/​README.md Adds setup, execution, and sample-file guidance.
Examples/​MergeWordDocsToPdf/​Program.cs Uses the environment token and bundled document inputs.
Examples/​MergeWordDocsToPdf/​MergeWordDocsToPdf.csproj Copies the DOCX and PowerPoint samples.
Examples/​HandleRetry/​Program.cs Reads the environment token and bundled PDF.
Examples/​HandleRetry/​HandleRetry.csproj Copies the sample PDF into build output.
Examples/​GetConverterInfoDemo/​Program.cs Uses the environment token and documented file → pdf lookup.
Examples/​FromStreamToStream/​Program.cs Reads the token from the environment.
Examples/​ExceptionHandling/​Program.cs Uses the environment token and bundled invalid-format sample.
Examples/​ExceptionHandling/​ExceptionHandling.csproj Copies the sample DOCX into build output.
Examples/​DeleteFiles/​Program.cs Reads the environment token and bundled DOCX.
Examples/​DeleteFiles/​DeleteFiles.csproj Copies the sample DOCX into build output.
Examples/​CreatePdfThumbnail/​Program.cs Corrects documentation and uses FitToSize with portable inputs.
Examples/​CreatePdfThumbnail/​CreatePdfThumbnail.csproj Copies the sample PDF into build output.
Examples/​ConvertWordToPdfAndPng/​Program.cs Reads the environment token and bundled DOCX.
Examples/​ConvertWordToPdfAndPng/​ConvertWordToPdfAndPng.csproj Copies the sample DOCX into build output.
Examples/​ConvertUrlToPdf/​Program.cs Uses documented html → pdf conversion and the environment token.
Examples/​ConvertRemoteFile/​Program.cs Reads the token from the environment.
Examples/​ConvertPdfToXlsx/​Program.cs Reads the environment token and bundled PDF.
Examples/​ConvertPdfToXlsx/​ConvertPdfToXlsx.csproj Copies the sample PDF into build output.
Examples/​ConvertPdfToPptx/​Program.cs Reads the environment token and bundled PDF.
Examples/​ConvertPdfToPptx/​ConvertPdfToPptx.csproj Copies the sample PDF into build output.
Examples/​ConvertPdfToPdfA/​Program.cs Uses the environment token and bundled invoice inputs.
Examples/​ConvertPdfToPdfA/​ConvertPdfToPdfA.csproj Copies the invoice PDF and XML samples.
Examples/​ConvertPdfToDocx/​Program.cs Reads the environment token and bundled PDF.
Examples/​ConvertPdfToDocx/​ConvertPdfToDocx.csproj Copies the sample PDF into build output.
Examples/​ConverterCatalogDemo/​Program.cs Removes the staging override to use the production catalog.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants