UmaySDK 1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package UmaySDK --version 1.0.1
NuGet\Install-Package UmaySDK -Version 1.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="UmaySDK" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UmaySDK" Version="1.0.1" />
<PackageReference Include="UmaySDK" />
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 UmaySDK --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: UmaySDK, 1.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.
#:package UmaySDK@1.0.1
#: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=UmaySDK&version=1.0.1
#tool nuget:?package=UmaySDK&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Umay Render SDK
Free, high-performance HTML to PDF and HTML to Image conversion SDK for .NET applications.
Core Features
- ✅ Cross-Platform: Works on Windows, macOS, and Linux.
- ✅ Multi-Target: Supports .NET 6.0, 7.0, and 8.0.
- ✅ PDF & Image: Convert HTML or URLs to PDF, PNG, JPEG, or WebP formats.
- ✅ Flexible Input: Accepts raw HTML content or a web page URL.
- ✅ Simple & Powerful: Easy to get started, yet offers deep customization options.
- ✅ Lightweight: Minimal dependencies keep the package small.
- ✅ Free & Open Source: No hidden costs or usage limits.
Installation
dotnet add package UmaySDK
Quick Start (Simple Usage)
Get started quickly with the most basic scenarios. The SDK handles most settings by default.
using UmaySDK;
using UmaySDK.Models;
// Initialize the SDK
var client = new UmayClient();
// --- Generate PDF from HTML ---
async Task CreatePdfFromHtml()
{
var htmlContent = "<html><body><h1>Hello PDF!</h1></body></html>";
var request = new ConversionRequest
{
Html = htmlContent,
OutputFormat = "pdf" // Specify PDF output format
};
try
{
// Save directly to file
await client.SaveToFileAsync(request, "simple.pdf");
Console.WriteLine("PDF generated successfully!");
// Or get the bytes directly
byte[] pdfBytes = await client.RenderAsync(request);
Console.WriteLine("PDF generated successfully (buffer)!");
}
catch (UmayException ex)
{
Console.WriteLine($"Error generating PDF: {ex.Message}");
}
}
// --- Generate PNG Image from URL ---
async Task CreateImageFromUrl()
{
var websiteUrl = "https://example.com";
var request = new ConversionRequest
{
Url = websiteUrl,
OutputFormat = "png" // Specify PNG output format
};
try
{
await client.SaveToFileAsync(request, "simple.png");
Console.WriteLine("Image generated successfully!");
}
catch (UmayException ex)
{
Console.WriteLine($"Error generating image: {ex.Message}");
}
}
// Call the functions
await CreatePdfFromHtml();
await CreateImageFromUrl();
Advanced Usage (Customization)
When you need more control, use the optional properties within the ConversionRequest
object:
PageSetupOptions
: Configures the browser environment (viewport, cookies, wait conditions, etc.) before rendering starts.PdfOptions
: Settings specific to PDF output (page format, margins, headers/footers, etc.).ScreenshotOptions
: Settings specific to image output (quality, full page capture, clipping, etc.).
using UmaySDK;
using UmaySDK.Models;
// Initialize SDK with custom settings
var client = new UmayClient("https://your-umay-server:3000");
// --- Advanced PDF Generation (From URL, with Cookies, Custom Settings) ---
async Task CreateAdvancedPdf()
{
var loginProtectedUrl = "https://portal.example.com/report/123";
var request = new ConversionRequest
{
Url = loginProtectedUrl,
OutputFormat = "pdf",
Filename = "monthly_report.pdf", // Suggested filename
PageSetupOptions = new PageSetupOptions
{
// Set cookies before page load (e.g., session info)
Cookies = new List<Cookie>
{
new Cookie
{
Name = "sessionid",
Value = "secretSessionValue",
Url = loginProtectedUrl
}
},
// Wait for a specific element to appear
WaitForSelector = "#report-data-ready",
// Wait for network traffic to settle
WaitUntil = "networkidle0",
// Set the viewport
Viewport = new Viewport
{
Width = 1200,
Height = 900
}
},
PdfOptions = new PdfOptions
{
Format = "A4",
Landscape = false, // Portrait page
PrintBackground = true, // Print backgrounds
Margin = new Margin
{
// Custom margins
Top = "2cm",
Bottom = "1.5cm",
Left = "1cm",
Right = "1cm"
},
DisplayHeaderFooter = true, // Display header and footer
// Simple header/footer templates (HTML supported)
HeaderTemplate = "<div style=\"font-size: 9px; width: 100%; text-align: center;\">Page <span class=\"pageNumber\"></span> / <span class=\"totalPages\"></span></div>",
FooterTemplate = "<div style=\"font-size: 9px; width: 100%; text-align: right; padding-right: 1cm;\">Report Date: <span class=\"date\"></span></div>"
}
};
try
{
await client.SaveToFileAsync(request, request.Filename ?? "advanced.pdf");
Console.WriteLine($"Advanced PDF saved: {request.Filename ?? "advanced.pdf"}");
}
catch (UmayException ex)
{
Console.WriteLine($"Error generating advanced PDF: {ex.Message}");
}
}
// --- Advanced Image Generation (From HTML, JPEG) ---
async Task CreateAdvancedImage()
{
var complexHtml = @"
<html>
<head><style>body { margin: 0; } .container { background: #eee; padding: 50px; } .highlight { border: 2px solid red; padding: 10px; display: inline-block; }</style></head>
<body>
<div class=""container"">
<h1>A Complex Section</h1>
<p>Other content...</p>
<div class=""highlight"" id=""target-element"">Clip Just This Part</div>
<p>More content...</p>
</div>
</body>
</html>";
var request = new ConversionRequest
{
Html = complexHtml,
OutputFormat = "jpeg",
PageSetupOptions = new PageSetupOptions
{
// Set the viewport for the screenshot
Viewport = new Viewport { Width = 800, Height = 600 }
},
ScreenshotOptions = new ScreenshotOptions
{
Quality = 85, // JPEG quality (0-100)
FullPage = false, // Capture only the viewport or clipped area, not the full page
// Clip only a specific area (the div with the highlight class)
Clip = new Clip
{
X = 50, // x-coordinate of the top-left corner of the clip area (approximate)
Y = 100, // y-coordinate of the top-left corner of the clip area (approximate)
Width = 180, // Width of the area to clip (approximate)
Height = 50 // Height of the area to clip (approximate)
// Note: Clip coordinates are often found through trial-and-error or browser dev tools.
},
OmitBackground = true // Make background transparent (becomes white for JPEG)
}
};
try
{
await client.SaveToFileAsync(request, "clipped_image.jpeg");
Console.WriteLine("Clipped JPEG saved: clipped_image.jpeg");
}
catch (UmayException ex)
{
Console.WriteLine($"Error generating advanced image: {ex.Message}");
}
}
// Call the functions
await CreateAdvancedPdf();
await CreateAdvancedImage();
API Reference
UmayClient
Class
constructor(baseUrl?: string)
: Initializes the SDK client with an optional custom API endpoint.RenderAsync(request: ConversionRequest): Task<byte[]>
: The main conversion method. Returns a byte array on success. May throwUmayException
on failure.SaveToFileAsync(request: ConversionRequest, filePath: string): Task
: Convenience method to render and save directly to a file. May throwUmayException
on failure.
ConversionRequest
Class (Core Properties)
Property | Type | Required | Description |
---|---|---|---|
Html |
string |
Yes¹ | The HTML content to render. |
Url |
string |
Yes¹ | The URL of the page to render. |
OutputFormat |
string |
Yes | The desired output format ("pdf" , "png" , "jpeg" , or "webp" ). |
Filename |
string |
No | Suggested filename for downloads. |
PageSetupOptions |
PageSetupOptions |
No | Page setup options applied before rendering. |
PdfOptions |
PdfOptions |
No | PDF-specific output options (if OutputFormat is "pdf" ). |
ScreenshotOptions |
ScreenshotOptions |
No | Image-specific output options (if OutputFormat is an image format). |
¹ Exactly one of Html
or Url
must be provided.
For a complete list of all available properties for PageSetupOptions
, PdfOptions
, and ScreenshotOptions
, please refer to the model classes in the source code.
Product | Versions 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 is compatible. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 7.0.0)
-
net7.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 7.0.0)
-
net8.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.