PdfQrApiSharp 1.1.0

dotnet add package PdfQrApiSharp --version 1.1.0
                    
NuGet\Install-Package PdfQrApiSharp -Version 1.1.0
                    
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="PdfQrApiSharp" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PdfQrApiSharp" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="PdfQrApiSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PdfQrApiSharp --version 1.1.0
                    
#r "nuget: PdfQrApiSharp, 1.1.0"
                    
#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.
#:package PdfQrApiSharp@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PdfQrApiSharp&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=PdfQrApiSharp&version=1.1.0
                    
Install as a Cake Tool

PdfQrApiSharp

A .NET library for communicating with the PDF QR Code API. This library provides a simple interface to add QR codes to PDF documents through an API service. The API project source code is available at: https://github.com/bdnowicki/pdf_qr_api

Features

  • Simple API for adding QR codes to PDF documents
  • Configurable API endpoint and settings
  • Async operations support
  • Proper resource management with IDisposable
  • Error handling and validation

Installation

The library is available as a NuGet package. You can install it using the Package Manager Console:

Install-Package PdfQrApiSharp

Or using the .NET CLI:

dotnet add package PdfQrApiSharp

Usage

Basic Usage

using System.IO;
using PdfQrApiSharp.Models;
using PdfQrApiSharp.Services;

// Create a request
var request = new PdfQrRequest
{
    PdfContent = File.ReadAllBytes("input.pdf"),
    QrContent = "https://example.com"
};

// Use the service
using var service = new PdfQrService();
var response = await service.AddQrToPdfAsync(request);

if (response.Success)
{
    // Save the modified PDF
    File.WriteAllBytes("output.pdf", response.ModifiedPdf);
}
else
{
    Console.WriteLine($"Error: {response.ErrorMessage}");
}

Custom Configuration

// Create custom configuration
var config = new PdfQrApiConfig
{
    BaseUrl = "https://your-api-url.com",
    ApiVersion = "v1",
    Endpoint = "add-qr-to-pdf",
    Timeout = TimeSpan.FromMinutes(1)
};

// Use the service with custom configuration
using var service = new PdfQrService(config);
var response = await service.AddQrToPdfAsync(request);

API Configuration

The PdfQrApiConfig class allows you to configure the following settings:

Property Default Value Description
BaseUrl "http://127.0.0.1:8000" The base URL of the API service
ApiVersion "v1" The API version to use
Endpoint "add-qr-to-pdf" The API endpoint for adding QR codes
Timeout 30 seconds The timeout for API requests

Error Handling

The library provides comprehensive error handling:

  • Input validation (PDF content and QR content are required)
  • API communication errors
  • HTTP status code handling
  • Exception handling

All errors are returned in the PdfQrResponse object with:

  • Success flag indicating if the operation was successful
  • ErrorMessage containing details about any errors that occurred
  • ModifiedPdf containing the modified PDF when successful

Resource Management

The PdfQrService class implements IDisposable to properly manage HTTP client resources. It's recommended to use the service within a using statement or explicitly call Dispose() when you're done with it:

using var service = new PdfQrService();
// Use the service...

Dependencies

  • System.Net.Http
  • Newtonsoft.Json

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 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
1.1.0 284 4/14/2025
1.0.1 265 4/14/2025
1.0.0 265 4/14/2025