PdfQrApiSharp 1.1.0
dotnet add package PdfQrApiSharp --version 1.1.0
NuGet\Install-Package PdfQrApiSharp -Version 1.1.0
<PackageReference Include="PdfQrApiSharp" Version="1.1.0" />
<PackageVersion Include="PdfQrApiSharp" Version="1.1.0" />
<PackageReference Include="PdfQrApiSharp" />
paket add PdfQrApiSharp --version 1.1.0
#r "nuget: PdfQrApiSharp, 1.1.0"
#:package PdfQrApiSharp@1.1.0
#addin nuget:?package=PdfQrApiSharp&version=1.1.0
#tool nuget:?package=PdfQrApiSharp&version=1.1.0
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:
Successflag indicating if the operation was successfulErrorMessagecontaining details about any errors that occurredModifiedPdfcontaining 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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- Newtonsoft.Json (>= 13.0.3)
- System.Net.Http (>= 4.3.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.