Repository navigation
Examples: projects for the README's C# tasks and for OCR - #95
Merged
Merged
Conversation
Adds ConvertDocxToPdf, ConvertHtmlToPdf (an HTML file and an HTML string), ConvertExcelToPdf, ExtractTextFromPdf, CompressPdf (prints the size before and after) and ConvertHtmlToDocx, the "... in C#" tasks of the README that had no example of their own, and OcrPdf with a made-up scanned letter in Examples/TestFiles/scanned.pdf. Each is in ConvertApi.sln, so CI builds and runs it, and is linked from the Tasks table, its README section and the More examples list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues blocking approval of the new examples and README links.
No open issues 🎉
What changed in this PR
Adds seven runnable examples for the README’s C# conversion tasks, including the OCR documentation introduced in #94. The examples use the library source and follow the existing console-project structure.
Changes:
- Demonstrates Word, Excel and HTML conversions, PDF text extraction, compression and OCR.
- Adds .NET 10 projects with sample-file copying and solution registration.
- Links the examples from the README’s task table, relevant sections and examples list.
| File | Description |
|---|---|
| README.md | Links all seven new examples. |
| Examples/OcrPdf/Program.cs | Demonstrates making a scanned PDF searchable. |
| Examples/OcrPdf/OcrPdf.csproj | Configures the OCR project and scan sample. |
| Examples/ExtractTextFromPdf/Program.cs | Reads extracted PDF text into a string. |
| Examples/ExtractTextFromPdf/ExtractTextFromPdf.csproj | Configures the text-extraction project and sample. |
| Examples/ConvertHtmlToPdf/Program.cs | Converts an HTML file and string to PDFs. |
| Examples/ConvertHtmlToPdf/ConvertHtmlToPdf.csproj | Configures the HTML-to-PDF project and sample. |
| Examples/ConvertHtmlToDocx/Program.cs | Converts HTML to an editable Word document. |
| Examples/ConvertHtmlToDocx/ConvertHtmlToDocx.csproj | Configures the HTML-to-Word project and sample. |
| Examples/ConvertExcelToPdf/Program.cs | Demonstrates Excel-to-PDF conversion. |
| Examples/ConvertExcelToPdf/ConvertExcelToPdf.csproj | Configures the Excel project and workbook sample. |
| Examples/ConvertDocxToPdf/Program.cs | Demonstrates Word-to-PDF conversion. |
| Examples/ConvertDocxToPdf/ConvertDocxToPdf.csproj | Configures the Word project and document sample. |
| Examples/CompressPdf/Program.cs | Compresses a PDF and reports before-and-after sizes. |
| Examples/CompressPdf/CompressPdf.csproj | Configures the compression project and sample. |
| ConvertApi.sln | Registers all seven projects under Examples. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Seven example projects. The first six are the README's "... in C#" tasks that had no example of their own; OcrPdf goes with the OCR section that #94 added.
test.docxtest.htmltest.xlsxtest.pdfPreset=web, printing the size before and aftertest.pdftest.htmlscanned.pdf(new)They follow the existing examples and
Examples/README.md: a .NET 10 console project that references the library source, reads the token fromCONVERTAPI_TOKEN, finds its sample throughAppContext.BaseDirectory, saves the result in the temp folder, catchesConvertApiExceptionand printsStatus Code:andResponse:, and waits for Enter.ConvertApi.slnunder the Examples folder, sobuildcompiles it and the Examples workflow runs it. The 49 solution lines were added by hand:dotnet sln addwould also have rewritten every existing project with x64 and x86 platforms.Examples/TestFiles/scanned.pdfis a made-up letter (fictional companies, an example.com address) rendered to a 150 dpi grayscale JPEG and wrapped in a one-page A4 PDF, with no text layer and no document metadata: 113 KB. The default OCR settings read all of it.How it was checked
ConvertApi.sln: 0 errors. The only warnings are the 3 that ConverterCatalogDemo and GetConverterInfoDemo already had..github/ci/check_csharp.py exampleswith.github/ci/ci-host.targets, as the Examples workflow runs it, but against the staging API (CONVERTAPI_BASE_URI=https://stag-v2.convertapi.com): 7 of 7 passed, and CiHost deleted every uploaded and result file.compressed.pdf, 246,542 bytes: 23% oftest.pdf's 1,086,060word-to-pdf.pdf, 146,734 bytesexcel-to-pdf.pdf, 43,891 byteshtml-to-word.docx, 13,241 byteshtml-file.pdf, 21,994 bytes, andhtml-string.pdf, 12,791 bytessearchable.pdf, 139,419 bytes, with the letter's text as its text layerIn the Examples workflow, which runs against the production API, these add 8 conversions per job (ConvertHtmlToPdf converts twice).
Not changed: the library, the existing examples, build.yml, the CI files, CHANGELOG.md and RELEASING.md.
🤖 Generated with Claude Code