diff --git a/ConvertApi.sln b/ConvertApi.sln index 7f8a346..6211cbc 100644 --- a/ConvertApi.sln +++ b/ConvertApi.sln @@ -61,6 +61,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConverterCatalogDemo", "Exa EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConvertApi.Tests", "ConvertApi.Tests\ConvertApi.Tests.csproj", "{2DBDE523-FC5A-4662-A99D-94835F760E20}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompressPdf", "Examples\CompressPdf\CompressPdf.csproj", "{5D3809FE-B06D-4F83-A027-1BB7EEE3C134}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConvertDocxToPdf", "Examples\ConvertDocxToPdf\ConvertDocxToPdf.csproj", "{DEC825E7-A38D-4E75-88AF-D7AD4FBD36FF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConvertExcelToPdf", "Examples\ConvertExcelToPdf\ConvertExcelToPdf.csproj", "{DBA758EF-81D9-40ED-97BF-869EC4476277}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConvertHtmlToDocx", "Examples\ConvertHtmlToDocx\ConvertHtmlToDocx.csproj", "{645B98F5-DEAB-4FB5-AC9F-711BBA1FF415}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConvertHtmlToPdf", "Examples\ConvertHtmlToPdf\ConvertHtmlToPdf.csproj", "{4744CF43-7156-4D71-A892-2D5262AB4256}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtractTextFromPdf", "Examples\ExtractTextFromPdf\ExtractTextFromPdf.csproj", "{479DC2EA-FA42-46C7-8D05-9FB41A97C175}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OcrPdf", "Examples\OcrPdf\OcrPdf.csproj", "{535367D2-8EFE-45F3-AB8E-703147F9406B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -159,6 +173,34 @@ Global {2DBDE523-FC5A-4662-A99D-94835F760E20}.Debug|Any CPU.Build.0 = Debug|Any CPU {2DBDE523-FC5A-4662-A99D-94835F760E20}.Release|Any CPU.ActiveCfg = Release|Any CPU {2DBDE523-FC5A-4662-A99D-94835F760E20}.Release|Any CPU.Build.0 = Release|Any CPU + {5D3809FE-B06D-4F83-A027-1BB7EEE3C134}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D3809FE-B06D-4F83-A027-1BB7EEE3C134}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D3809FE-B06D-4F83-A027-1BB7EEE3C134}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D3809FE-B06D-4F83-A027-1BB7EEE3C134}.Release|Any CPU.Build.0 = Release|Any CPU + {DEC825E7-A38D-4E75-88AF-D7AD4FBD36FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DEC825E7-A38D-4E75-88AF-D7AD4FBD36FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DEC825E7-A38D-4E75-88AF-D7AD4FBD36FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DEC825E7-A38D-4E75-88AF-D7AD4FBD36FF}.Release|Any CPU.Build.0 = Release|Any CPU + {DBA758EF-81D9-40ED-97BF-869EC4476277}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DBA758EF-81D9-40ED-97BF-869EC4476277}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DBA758EF-81D9-40ED-97BF-869EC4476277}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DBA758EF-81D9-40ED-97BF-869EC4476277}.Release|Any CPU.Build.0 = Release|Any CPU + {645B98F5-DEAB-4FB5-AC9F-711BBA1FF415}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {645B98F5-DEAB-4FB5-AC9F-711BBA1FF415}.Debug|Any CPU.Build.0 = Debug|Any CPU + {645B98F5-DEAB-4FB5-AC9F-711BBA1FF415}.Release|Any CPU.ActiveCfg = Release|Any CPU + {645B98F5-DEAB-4FB5-AC9F-711BBA1FF415}.Release|Any CPU.Build.0 = Release|Any CPU + {4744CF43-7156-4D71-A892-2D5262AB4256}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4744CF43-7156-4D71-A892-2D5262AB4256}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4744CF43-7156-4D71-A892-2D5262AB4256}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4744CF43-7156-4D71-A892-2D5262AB4256}.Release|Any CPU.Build.0 = Release|Any CPU + {479DC2EA-FA42-46C7-8D05-9FB41A97C175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {479DC2EA-FA42-46C7-8D05-9FB41A97C175}.Debug|Any CPU.Build.0 = Debug|Any CPU + {479DC2EA-FA42-46C7-8D05-9FB41A97C175}.Release|Any CPU.ActiveCfg = Release|Any CPU + {479DC2EA-FA42-46C7-8D05-9FB41A97C175}.Release|Any CPU.Build.0 = Release|Any CPU + {535367D2-8EFE-45F3-AB8E-703147F9406B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {535367D2-8EFE-45F3-AB8E-703147F9406B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {535367D2-8EFE-45F3-AB8E-703147F9406B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {535367D2-8EFE-45F3-AB8E-703147F9406B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -186,6 +228,13 @@ Global {C3C2C6C0-9F6E-4B9F-A6A9-1C0D7E4CB8B1} = {139F9822-4A90-475F-BAA5-F0471A85461B} {5C7E3B2A-0D7B-4D3F-9C64-2EA2F2E0E5C1} = {139F9822-4A90-475F-BAA5-F0471A85461B} {DFEC8F03-E140-488A-B457-59715605F5CA} = {139F9822-4A90-475F-BAA5-F0471A85461B} + {5D3809FE-B06D-4F83-A027-1BB7EEE3C134} = {139F9822-4A90-475F-BAA5-F0471A85461B} + {DEC825E7-A38D-4E75-88AF-D7AD4FBD36FF} = {139F9822-4A90-475F-BAA5-F0471A85461B} + {DBA758EF-81D9-40ED-97BF-869EC4476277} = {139F9822-4A90-475F-BAA5-F0471A85461B} + {645B98F5-DEAB-4FB5-AC9F-711BBA1FF415} = {139F9822-4A90-475F-BAA5-F0471A85461B} + {4744CF43-7156-4D71-A892-2D5262AB4256} = {139F9822-4A90-475F-BAA5-F0471A85461B} + {479DC2EA-FA42-46C7-8D05-9FB41A97C175} = {139F9822-4A90-475F-BAA5-F0471A85461B} + {535367D2-8EFE-45F3-AB8E-703147F9406B} = {139F9822-4A90-475F-BAA5-F0471A85461B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {337A0F6F-40A9-4993-BF66-05E4E374871F} diff --git a/Examples/CompressPdf/CompressPdf.csproj b/Examples/CompressPdf/CompressPdf.csproj new file mode 100644 index 0000000..5365d39 --- /dev/null +++ b/Examples/CompressPdf/CompressPdf.csproj @@ -0,0 +1,18 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + diff --git a/Examples/CompressPdf/Program.cs b/Examples/CompressPdf/Program.cs new file mode 100644 index 0000000..5d44222 --- /dev/null +++ b/Examples/CompressPdf/Program.cs @@ -0,0 +1,32 @@ +// Compresses a PDF and prints its size before and after. +// The Preset parameter accepts lossless, text, archive, web, ebook and printer. +// https://www.convertapi.com/pdf-to-compress +using ConvertApiDotNet; +using ConvertApiDotNet.Exceptions; + +try +{ + // Get your API token at https://www.convertapi.com/a/authentication + var convertApi = new ConvertApi(Environment.GetEnvironmentVariable("CONVERTAPI_TOKEN")); + + // Sample file from Examples/TestFiles, copied next to the program when it builds + var pdfFile = new FileInfo(Path.Combine(AppContext.BaseDirectory, "TestFiles", "test.pdf")); + + Console.WriteLine("Compressing the PDF..."); + var result = await convertApi.ConvertAsync("pdf", "compress", + new ConvertApiFileParam(pdfFile), + new ConvertApiParam("Preset", "web")); + + var compressed = await result.Files[0].SaveFileAsync(Path.Combine(Path.GetTempPath(), "compressed.pdf")); + + Console.WriteLine($"Before: {pdfFile.Length:N0} bytes"); + Console.WriteLine($"After: {compressed.Length:N0} bytes, {100.0 * compressed.Length / pdfFile.Length:F0}% of the original"); + Console.WriteLine("The compressed PDF saved to " + compressed.FullName); +} +catch (ConvertApiException e) +{ + Console.WriteLine("Status Code: " + e.StatusCode); + Console.WriteLine("Response: " + e.Response); +} + +Console.ReadLine(); diff --git a/Examples/ConvertDocxToPdf/ConvertDocxToPdf.csproj b/Examples/ConvertDocxToPdf/ConvertDocxToPdf.csproj new file mode 100644 index 0000000..eeec83d --- /dev/null +++ b/Examples/ConvertDocxToPdf/ConvertDocxToPdf.csproj @@ -0,0 +1,18 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + diff --git a/Examples/ConvertDocxToPdf/Program.cs b/Examples/ConvertDocxToPdf/Program.cs new file mode 100644 index 0000000..402514b --- /dev/null +++ b/Examples/ConvertDocxToPdf/Program.cs @@ -0,0 +1,27 @@ +// Converts a Word document (DOCX) to PDF. For a DOC file, keep "docx" and pass the DOC file. +// https://www.convertapi.com/docx-to-pdf +using ConvertApiDotNet; +using ConvertApiDotNet.Exceptions; + +try +{ + // Get your API token at https://www.convertapi.com/a/authentication + var convertApi = new ConvertApi(Environment.GetEnvironmentVariable("CONVERTAPI_TOKEN")); + + // Sample file from Examples/TestFiles, copied next to the program when it builds + var wordFile = Path.Combine(AppContext.BaseDirectory, "TestFiles", "test.docx"); + + Console.WriteLine("Converting the Word document to PDF..."); + var result = await convertApi.ConvertAsync("docx", "pdf", + new ConvertApiFileParam(wordFile)); + + var pdf = await result.Files[0].SaveFileAsync(Path.Combine(Path.GetTempPath(), "word-to-pdf.pdf")); + Console.WriteLine("The PDF saved to " + pdf.FullName); +} +catch (ConvertApiException e) +{ + Console.WriteLine("Status Code: " + e.StatusCode); + Console.WriteLine("Response: " + e.Response); +} + +Console.ReadLine(); diff --git a/Examples/ConvertExcelToPdf/ConvertExcelToPdf.csproj b/Examples/ConvertExcelToPdf/ConvertExcelToPdf.csproj new file mode 100644 index 0000000..24b9944 --- /dev/null +++ b/Examples/ConvertExcelToPdf/ConvertExcelToPdf.csproj @@ -0,0 +1,18 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + diff --git a/Examples/ConvertExcelToPdf/Program.cs b/Examples/ConvertExcelToPdf/Program.cs new file mode 100644 index 0000000..c9ab81d --- /dev/null +++ b/Examples/ConvertExcelToPdf/Program.cs @@ -0,0 +1,27 @@ +// Converts an Excel workbook (XLSX or XLS) to PDF. +// https://www.convertapi.com/xlsx-to-pdf +using ConvertApiDotNet; +using ConvertApiDotNet.Exceptions; + +try +{ + // Get your API token at https://www.convertapi.com/a/authentication + var convertApi = new ConvertApi(Environment.GetEnvironmentVariable("CONVERTAPI_TOKEN")); + + // Sample file from Examples/TestFiles, copied next to the program when it builds + var workbook = Path.Combine(AppContext.BaseDirectory, "TestFiles", "test.xlsx"); + + Console.WriteLine("Converting the Excel workbook to PDF..."); + var result = await convertApi.ConvertAsync("xlsx", "pdf", + new ConvertApiFileParam(workbook)); + + var pdf = await result.Files[0].SaveFileAsync(Path.Combine(Path.GetTempPath(), "excel-to-pdf.pdf")); + Console.WriteLine("The PDF saved to " + pdf.FullName); +} +catch (ConvertApiException e) +{ + Console.WriteLine("Status Code: " + e.StatusCode); + Console.WriteLine("Response: " + e.Response); +} + +Console.ReadLine(); diff --git a/Examples/ConvertHtmlToDocx/ConvertHtmlToDocx.csproj b/Examples/ConvertHtmlToDocx/ConvertHtmlToDocx.csproj new file mode 100644 index 0000000..6feb1ad --- /dev/null +++ b/Examples/ConvertHtmlToDocx/ConvertHtmlToDocx.csproj @@ -0,0 +1,18 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + diff --git a/Examples/ConvertHtmlToDocx/Program.cs b/Examples/ConvertHtmlToDocx/Program.cs new file mode 100644 index 0000000..f9793c1 --- /dev/null +++ b/Examples/ConvertHtmlToDocx/Program.cs @@ -0,0 +1,27 @@ +// Converts an HTML file to an editable Word document (DOCX). +// https://www.convertapi.com/html-to-docx +using ConvertApiDotNet; +using ConvertApiDotNet.Exceptions; + +try +{ + // Get your API token at https://www.convertapi.com/a/authentication + var convertApi = new ConvertApi(Environment.GetEnvironmentVariable("CONVERTAPI_TOKEN")); + + // Sample file from Examples/TestFiles, copied next to the program when it builds + var htmlFile = Path.Combine(AppContext.BaseDirectory, "TestFiles", "test.html"); + + Console.WriteLine("Converting the HTML file to a Word document..."); + var result = await convertApi.ConvertAsync("html", "docx", + new ConvertApiFileParam(htmlFile)); + + var docx = await result.Files[0].SaveFileAsync(Path.Combine(Path.GetTempPath(), "html-to-word.docx")); + Console.WriteLine("The Word document saved to " + docx.FullName); +} +catch (ConvertApiException e) +{ + Console.WriteLine("Status Code: " + e.StatusCode); + Console.WriteLine("Response: " + e.Response); +} + +Console.ReadLine(); diff --git a/Examples/ConvertHtmlToPdf/ConvertHtmlToPdf.csproj b/Examples/ConvertHtmlToPdf/ConvertHtmlToPdf.csproj new file mode 100644 index 0000000..6feb1ad --- /dev/null +++ b/Examples/ConvertHtmlToPdf/ConvertHtmlToPdf.csproj @@ -0,0 +1,18 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + diff --git a/Examples/ConvertHtmlToPdf/Program.cs b/Examples/ConvertHtmlToPdf/Program.cs new file mode 100644 index 0000000..0014ef0 --- /dev/null +++ b/Examples/ConvertHtmlToPdf/Program.cs @@ -0,0 +1,41 @@ +// Converts an HTML file, and an HTML string such as an invoice your app builds, to PDF files. +// To convert a web page by its URL, see the ConvertUrlToPdf example. +// https://www.convertapi.com/html-to-pdf +using System.Text; +using ConvertApiDotNet; +using ConvertApiDotNet.Exceptions; + +try +{ + // Get your API token at https://www.convertapi.com/a/authentication + var convertApi = new ConvertApi(Environment.GetEnvironmentVariable("CONVERTAPI_TOKEN")); + + // Sample file from Examples/TestFiles, copied next to the program when it builds. Only the HTML file + // is uploaded, so link images and stylesheets by absolute URL or put them inline. + var htmlFile = Path.Combine(AppContext.BaseDirectory, "TestFiles", "test.html"); + + Console.WriteLine("Converting the HTML file to PDF..."); + var fromFile = await convertApi.ConvertAsync("html", "pdf", + new ConvertApiFileParam(htmlFile), + new ConvertApiParam("PageSize", "a4")); + + var filePdf = await fromFile.Files[0].SaveFileAsync(Path.Combine(Path.GetTempPath(), "html-file.pdf")); + Console.WriteLine("The PDF of the HTML file saved to " + filePdf.FullName); + + // An HTML string is uploaded from memory, under a file name that ends in .html + var html = "

Invoice 1001

Total: 99.00 USD

"; + + Console.WriteLine("Converting the HTML string to PDF..."); + var fromString = await convertApi.ConvertAsync("html", "pdf", + new ConvertApiFileParam(new MemoryStream(Encoding.UTF8.GetBytes(html)), "invoice.html")); + + var stringPdf = await fromString.Files[0].SaveFileAsync(Path.Combine(Path.GetTempPath(), "html-string.pdf")); + Console.WriteLine("The PDF of the HTML string saved to " + stringPdf.FullName); +} +catch (ConvertApiException e) +{ + Console.WriteLine("Status Code: " + e.StatusCode); + Console.WriteLine("Response: " + e.Response); +} + +Console.ReadLine(); diff --git a/Examples/ExtractTextFromPdf/ExtractTextFromPdf.csproj b/Examples/ExtractTextFromPdf/ExtractTextFromPdf.csproj new file mode 100644 index 0000000..5365d39 --- /dev/null +++ b/Examples/ExtractTextFromPdf/ExtractTextFromPdf.csproj @@ -0,0 +1,18 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + diff --git a/Examples/ExtractTextFromPdf/Program.cs b/Examples/ExtractTextFromPdf/Program.cs new file mode 100644 index 0000000..430cde3 --- /dev/null +++ b/Examples/ExtractTextFromPdf/Program.cs @@ -0,0 +1,31 @@ +// Extracts the text of a PDF into a string. Scanned pages are read with OCR when needed. +// https://www.convertapi.com/pdf-to-txt +using ConvertApiDotNet; +using ConvertApiDotNet.Exceptions; + +try +{ + // Get your API token at https://www.convertapi.com/a/authentication + var convertApi = new ConvertApi(Environment.GetEnvironmentVariable("CONVERTAPI_TOKEN")); + + // Sample file from Examples/TestFiles, copied next to the program when it builds + var pdfFile = Path.Combine(AppContext.BaseDirectory, "TestFiles", "test.pdf"); + + Console.WriteLine("Extracting the text of the PDF..."); + var result = await convertApi.ConvertAsync("pdf", "txt", + new ConvertApiFileParam(pdfFile)); + + // Read the text file from the server as a stream, without saving it to disk + using var reader = new StreamReader(await result.Files[0].FileStreamAsync()); + var text = await reader.ReadToEndAsync(); + + Console.WriteLine($"The PDF holds {text.Length} characters of text:"); + Console.WriteLine(text); +} +catch (ConvertApiException e) +{ + Console.WriteLine("Status Code: " + e.StatusCode); + Console.WriteLine("Response: " + e.Response); +} + +Console.ReadLine(); diff --git a/Examples/OcrPdf/OcrPdf.csproj b/Examples/OcrPdf/OcrPdf.csproj new file mode 100644 index 0000000..e24fd58 --- /dev/null +++ b/Examples/OcrPdf/OcrPdf.csproj @@ -0,0 +1,18 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + diff --git a/Examples/OcrPdf/Program.cs b/Examples/OcrPdf/Program.cs new file mode 100644 index 0000000..be37ca5 --- /dev/null +++ b/Examples/OcrPdf/Program.cs @@ -0,0 +1,31 @@ +// Makes a scanned PDF searchable: OCR adds an invisible text layer, so the text can be found, +// selected and copied. Pages that already have text are skipped. +// https://www.convertapi.com/pdf-to-ocr +using ConvertApiDotNet; +using ConvertApiDotNet.Exceptions; + +try +{ + // Get your API token at https://www.convertapi.com/a/authentication + var convertApi = new ConvertApi(Environment.GetEnvironmentVariable("CONVERTAPI_TOKEN")); + + // Sample scan from Examples/TestFiles, copied next to the program when it builds + var scannedPdf = Path.Combine(AppContext.BaseDirectory, "TestFiles", "scanned.pdf"); + + Console.WriteLine("Running OCR on the scanned PDF..."); + var result = await convertApi.ConvertAsync("pdf", "ocr", + new ConvertApiFileParam(scannedPdf), + // The language of the text, such as "de" or "es". If text is missed, for example in tables or + // low-quality scans, also pass new ConvertApiParam("OcrQuality", "enhanced"): slower, but it reads more. + new ConvertApiParam("OcrLanguage", "en")); + + var searchable = await result.Files[0].SaveFileAsync(Path.Combine(Path.GetTempPath(), "searchable.pdf")); + Console.WriteLine("The searchable PDF saved to " + searchable.FullName); +} +catch (ConvertApiException e) +{ + Console.WriteLine("Status Code: " + e.StatusCode); + Console.WriteLine("Response: " + e.Response); +} + +Console.ReadLine(); diff --git a/Examples/TestFiles/scanned.pdf b/Examples/TestFiles/scanned.pdf new file mode 100644 index 0000000..62f4736 Binary files /dev/null and b/Examples/TestFiles/scanned.pdf differ diff --git a/README.md b/README.md index 82a89c4..a171716 100644 --- a/README.md +++ b/README.md @@ -69,15 +69,15 @@ Each task links to its C# code in this README and, where there is one, to a comp | Task | Example project | |---|---| -| [Convert Word (DOCX) to PDF](#convert-word-docx-to-pdf-in-c) | [ConvertWordToPdfAndPng](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertWordToPdfAndPng/Program.cs) | -| [Convert HTML to PDF: a file, a string or a web page](#convert-html-to-pdf-in-c) | [FromStreamToStream](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/FromStreamToStream/Program.cs), [ConvertUrlToPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertUrlToPdf/Program.cs) | -| [Convert Excel (XLSX) to PDF](#convert-excel-to-pdf-in-c) | | +| [Convert Word (DOCX) to PDF](#convert-word-docx-to-pdf-in-c) | [ConvertDocxToPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertDocxToPdf/Program.cs), [ConvertWordToPdfAndPng](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertWordToPdfAndPng/Program.cs) | +| [Convert HTML to PDF: a file, a string or a web page](#convert-html-to-pdf-in-c) | [ConvertHtmlToPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertHtmlToPdf/Program.cs), [FromStreamToStream](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/FromStreamToStream/Program.cs), [ConvertUrlToPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertUrlToPdf/Program.cs) | +| [Convert Excel (XLSX) to PDF](#convert-excel-to-pdf-in-c) | [ConvertExcelToPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertExcelToPdf/Program.cs) | | [Convert PDF to Word (DOCX)](#convert-pdf-to-word-in-c) | [ConvertPdfToDocx](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertPdfToDocx/Program.cs) | | [Convert PDF to JPG or PNG](#convert-pdf-to-jpg-or-png-in-c) | [CreatePdfThumbnail](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/CreatePdfThumbnail/Program.cs) | -| [Extract text from PDF](#extract-text-from-pdf-in-c) | | -| [OCR a scanned PDF to make it searchable](#ocr-a-scanned-pdf-in-c) | | -| [Compress PDF](#compress-pdf-in-c) | | -| [Convert HTML to Word (DOCX)](#convert-html-to-docx-in-c) | | +| [Extract text from PDF](#extract-text-from-pdf-in-c) | [ExtractTextFromPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ExtractTextFromPdf/Program.cs) | +| [OCR a scanned PDF to make it searchable](#ocr-a-scanned-pdf-in-c) | [OcrPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/OcrPdf/Program.cs) | +| [Compress PDF](#compress-pdf-in-c) | [CompressPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/CompressPdf/Program.cs) | +| [Convert HTML to Word (DOCX)](#convert-html-to-docx-in-c) | [ConvertHtmlToDocx](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertHtmlToDocx/Program.cs) | | [Convert PowerPoint (PPTX) to PDF](#powerpoint-to-pdf) | [ConvertRemoteFile](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertRemoteFile/Program.cs) | | [Convert an image to PDF](#image-to-pdf) | | | [Combine images into one PDF](#combine-images-into-one-pdf) | | @@ -157,6 +157,8 @@ await result.SaveFilesAsync("output"); The PDF is saved as `output/document.pdf`. For plain text or HTML, use `"txt"` or `"html"` in place of `"pdf"`. +Example project: [ConvertDocxToPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertDocxToPdf/Program.cs) + ### Convert HTML to PDF in C# Convert an HTML file to PDF. Only the HTML file is uploaded, so link images and stylesheets by absolute URL or put them inline. @@ -198,6 +200,8 @@ Directory.CreateDirectory("output"); await result.SaveFilesAsync("output"); ``` +Example projects: [ConvertHtmlToPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertHtmlToPdf/Program.cs) for an HTML file and an HTML string, [ConvertUrlToPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertUrlToPdf/Program.cs) for a web page + ### Convert Excel to PDF in C# Convert an Excel workbook (XLSX or XLS) to PDF: @@ -214,6 +218,8 @@ await result.SaveFilesAsync("output"); To save each worksheet as a CSV file, use `"csv"` in place of `"pdf"`. +Example project: [ConvertExcelToPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertExcelToPdf/Program.cs) + ### Convert PDF to Word in C# Convert a PDF to an editable Word document (DOCX): @@ -260,6 +266,8 @@ var text = await reader.ReadToEndAsync(); Console.WriteLine(text); ``` +Example project: [ExtractTextFromPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ExtractTextFromPdf/Program.cs) + ### OCR a scanned PDF in C# Make a scanned PDF searchable. OCR adds an invisible text layer, so the text can be found, selected and copied; pages that already have text are skipped. `OcrLanguage` is the language of the text, such as `de` or `es`. The [PDF OCR page](https://www.convertapi.com/pdf-to-ocr) lists all languages. @@ -277,6 +285,8 @@ await result.SaveFilesAsync("output"); The searchable PDF is saved as `output/scanned.pdf`. If text is missed, for example in tables, low-quality scans, photos or small print, add `new ConvertApiParam("OcrQuality", "enhanced")`: it is slower but reads more. +Example project: [OcrPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/OcrPdf/Program.cs) + ### Compress PDF in C# Make a PDF smaller. The `Preset` parameter accepts `lossless`, `text`, `archive`, `web`, `ebook` and `printer`. @@ -292,6 +302,8 @@ Directory.CreateDirectory("output"); await result.SaveFilesAsync("output"); ``` +Example project: [CompressPdf](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/CompressPdf/Program.cs) + ### Convert HTML to DOCX in C# Convert an HTML file to an editable Word document: @@ -306,6 +318,8 @@ Directory.CreateDirectory("output"); await result.SaveFilesAsync("output"); ``` +Example project: [ConvertHtmlToDocx](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertHtmlToDocx/Program.cs) + ### More conversions and PDF tools Every other format pair works the same way: pass its source and target format to `ConvertAsync`. All formats and conversions are listed in the [API reference](https://www.convertapi.com/api). @@ -964,6 +978,11 @@ Console.WriteLine($"Conversions used: {user.ConversionsConsumed} of {user.Conver Each example is a complete console project in the `Examples` folder of this repository. To run one, set the `CONVERTAPI_TOKEN` environment variable and follow the steps in [Examples/README.md](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/README.md). +- [CompressPdf/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/CompressPdf/Program.cs) - Compress a PDF and print its size before and after +- [ConvertDocxToPdf/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertDocxToPdf/Program.cs) - Convert a Word DOCX document to PDF +- [ConvertExcelToPdf/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertExcelToPdf/Program.cs) - Convert an Excel XLSX workbook to PDF +- [ConvertHtmlToDocx/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertHtmlToDocx/Program.cs) - Convert an HTML file to an editable Word DOCX document +- [ConvertHtmlToPdf/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertHtmlToPdf/Program.cs) - Convert an HTML file and an HTML string to PDF - [ConvertPdfToDocx/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertPdfToDocx/Program.cs) - Convert a PDF to an editable Word DOCX document - [ConvertPdfToPdfA/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertPdfToPdfA/Program.cs) - Convert a PDF to PDF/A with an embedded invoice XML - [ConvertPdfToPptx/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ConvertPdfToPptx/Program.cs) - Convert a PDF to a PowerPoint PPTX presentation @@ -975,10 +994,12 @@ Each example is a complete console project in the `Examples` folder of this repo - [CreatePdfThumbnail/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/CreatePdfThumbnail/Program.cs) - Turn the first page of a PDF into a JPG thumbnail - [DeleteFiles/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/DeleteFiles/Program.cs) - Delete the uploaded and result files from the server after a conversion - [ExceptionHandling/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ExceptionHandling/Program.cs) - Catch a ConvertAPI exception and print its status code and response +- [ExtractTextFromPdf/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/ExtractTextFromPdf/Program.cs) - Extract the text of a PDF into a string - [FromStreamToStream/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/FromStreamToStream/Program.cs) - Convert HTML from a string stream and get the PDF back as a stream - [GetConverterInfoDemo/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/GetConverterInfoDemo/Program.cs) - Read a converter's accepted formats and parameters, for example to build a dynamic UI - [HandleRetry/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/HandleRetry/Program.cs) - Retry a conversion when the service returns 503 (service unavailable) - [MergeWordDocsToPdf/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/MergeWordDocsToPdf/Program.cs) - Convert Word and PowerPoint files to PDF and merge them into one PDF +- [OcrPdf/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/OcrPdf/Program.cs) - Make a scanned PDF searchable with OCR - [RetrieveUserInformation/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/RetrieveUserInformation/Program.cs) - Retrieve your ConvertAPI account information - [SplitAndMergePdf/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/SplitAndMergePdf/Program.cs) - Split a PDF and merge its first and last pages into a new PDF - [SplitPDF/Program.cs](https://github.com/ConvertAPI/convertapi-library-dotnet/blob/main/Examples/SplitPDF/Program.cs) - Split a PDF by bookmarks, page patterns, text and page ranges