Redocmx 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Redocmx --version 0.0.1                
NuGet\Install-Package Redocmx -Version 0.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Redocmx" Version="0.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Redocmx --version 0.0.1                
#r "nuget: Redocmx, 0.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Redocmx as a Cake Addin
#addin nuget:?package=Redocmx&version=0.0.1

// Install Redocmx as a Cake Tool
#tool nuget:?package=Redocmx&version=0.0.1                

Converting CFDI to PDF with Redocmx for C#

Introduction

The Redocmx library is a C# client designed to interact with the redoc.mx REST API for converting CFDIs (Comprobante Fiscal Digital por Internet) into PDFs. This library simplifies the process of sending XML data to the redoc.mx service and retrieving the converted PDF, along with transaction details and metadata, making it easy to integrate into .NET projects.

Installation

To install the Redocmx library, you can use NuGet Package Manager. Run the following command in the Package Manager Console:

Install-Package Redocmx -Version <VERSION>

Replace <VERSION> with the specific version of the Redocmx library you wish to install.

Usage

Start by including Redocmx in your project:

using Redocmx;

Then, instantiate the Redoc class with your API token:

class Program
{
    static async Task Main(string[] args)
    {
        var redoc = new Redoc("api_token");

You can load the CFDI data from a file or directly from a string. Below is an example of loading from a file and converting it to PDF:

        try
        {
            var cfdi = redoc.Cfdi.FromFile("./test.xml");

            var pdf = await cfdi.ToPdfAsync();

            await File.WriteAllBytesAsync("./result.pdf", pdf.Buffer);

            Console.WriteLine($"Transaction ID: {pdf.TransactionId}");
            Console.WriteLine($"Total time MS: {pdf.TotalTimeMs}");
            Console.WriteLine($"Total pages: {pdf.TotalPages}");
            Console.WriteLine($"Metadata:");

            foreach (var pair in pdf.Metadata)
            {
                Console.WriteLine($"    {pair.Key}: {pair.Value}");
            }
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine($"An error occurred during the conversion: {ex.Message}");
        }
    }
}

Examples

For more detailed examples on how to use the library, please refer to the following resources:

API Reference

Redoc

Instantiate the Redoc class to interact with the API. The constructor requires your API token.

Methods

  • Cfdi.FromFile(string path): Loads CFDI data from a file.
  • Cfdi.FromString(string xmlContent): Loads CFDI data directly from a string.
  • ToPdfAsync(): Converts the loaded CFDI to a PDF and returns metadata about the conversion.

Contributing

We welcome contributions! Feel free to submit pull requests or open issues for bugs, features, or improvements.

License

This project is licensed under the MIT License. See the LICENSE file in the repository for more information.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.2 122 4/9/2024
0.0.1 131 3/27/2024

Initial release of the Redocmx C# client.