Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions ConvertApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
18 changes: 18 additions & 0 deletions Examples/CompressPdf/CompressPdf.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\ConvertApi\ConvertApi.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\TestFiles\test.pdf" Link="TestFiles\test.pdf" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
32 changes: 32 additions & 0 deletions Examples/CompressPdf/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
18 changes: 18 additions & 0 deletions Examples/ConvertDocxToPdf/ConvertDocxToPdf.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\ConvertApi\ConvertApi.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\TestFiles\test.docx" Link="TestFiles\test.docx" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions Examples/ConvertDocxToPdf/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
18 changes: 18 additions & 0 deletions Examples/ConvertExcelToPdf/ConvertExcelToPdf.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\ConvertApi\ConvertApi.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\TestFiles\test.xlsx" Link="TestFiles\test.xlsx" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions Examples/ConvertExcelToPdf/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
18 changes: 18 additions & 0 deletions Examples/ConvertHtmlToDocx/ConvertHtmlToDocx.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\ConvertApi\ConvertApi.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\TestFiles\test.html" Link="TestFiles\test.html" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions Examples/ConvertHtmlToDocx/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
18 changes: 18 additions & 0 deletions Examples/ConvertHtmlToPdf/ConvertHtmlToPdf.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\ConvertApi\ConvertApi.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\TestFiles\test.html" Link="TestFiles\test.html" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions Examples/ConvertHtmlToPdf/Program.cs
Original file line number Diff line number Diff line change
@@ -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 = "<h1>Invoice 1001</h1><p>Total: 99.00 USD</p>";

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();
18 changes: 18 additions & 0 deletions Examples/ExtractTextFromPdf/ExtractTextFromPdf.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\ConvertApi\ConvertApi.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\TestFiles\test.pdf" Link="TestFiles\test.pdf" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Examples/ExtractTextFromPdf/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
18 changes: 18 additions & 0 deletions Examples/OcrPdf/OcrPdf.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\ConvertApi\ConvertApi.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\TestFiles\scanned.pdf" Link="TestFiles\scanned.pdf" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Loading
Loading