HtmlToPdf.AspNetCore
1.1.0
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 HtmlToPdf.AspNetCore --version 1.1.0
NuGet\Install-Package HtmlToPdf.AspNetCore -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="HtmlToPdf.AspNetCore" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HtmlToPdf.AspNetCore" Version="1.1.0" />
<PackageReference Include="HtmlToPdf.AspNetCore" />
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 HtmlToPdf.AspNetCore --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HtmlToPdf.AspNetCore, 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 HtmlToPdf.AspNetCore@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=HtmlToPdf.AspNetCore&version=1.1.0
#tool nuget:?package=HtmlToPdf.AspNetCore&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HtmlToPdf.AspNetCore
A fast, accurate HTML to PDF conversion library for .NET with perfect RTL (Right-to-Left) language support. Built on Chromium for pixel-perfect rendering with full Arabic, Urdu, Persian, and Hebrew text support.
✨ Features
- 🌍 Perfect RTL Support - Native support for Arabic, Urdu, Persian, Hebrew and other RTL languages
- ⚡ Fast Performance - Optimized for high-throughput PDF generation
- 🎯 Pixel-Perfect Rendering - Chromium-based rendering with full CSS3, JavaScript, and web font support
- 🔧 Simple API - Easy to use with just one line of code
- 🚀 Automatic Browser Management - Auto-downloads Chromium if not installed
- 📱 Cross-Platform - Works on Windows, Linux, and macOS
- 🔒 Thread-Safe - Safe for concurrent use in web applications
- ✍️ Document Signing - Add signatures, stamps, and watermarks to your PDFs
- 🖼️ Image Signatures - Support for image-based signatures (PNG, JPG, etc.)
- 🔏 Digital Stamps - Create official-looking stamps and seals
- 💧 Watermarks - Add transparent watermarks (DRAFT, CONFIDENTIAL, etc.)
📦 Installation
Using .NET CLI
dotnet add package HtmlToPdf.AspNetCore
Using Package Manager
Install-Package HtmlToPdf.AspNetCore
🚀 Quick Start
Basic Usage
using HtmlToPdf.AspNetCore;
var html = "<h1>Hello World</h1><p>This is a simple PDF document.</p>";
byte[] pdf = Pdf.Render(html);
File.WriteAllBytes("output.pdf", pdf);
ASP.NET Core Controller Example
using HtmlToPdf.AspNetCore;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("api/pdf")]
public class PdfController : ControllerBase
{
[HttpPost]
public IActionResult GeneratePdf([FromBody] string html)
{
byte[] pdfBytes = Pdf.Render(html);
return File(pdfBytes, "application/pdf", "document.pdf");
}
}
🌍 RTL Language Support
Arabic Example
var arabicHtml = @"
<div dir='rtl' style='font-family: Arial, sans-serif; text-align: right;'>
<h1>التقرير الشهري</h1>
<p>هذا تقرير يحتوي على نص باللغة العربية مع دعم كامل للتشكيل والاتجاه من اليمين لليسار.</p>
</div>";
byte[] arabicPdf = Pdf.Render(arabicHtml, new PdfOptions
{
Language = PdfLanguage.Arabic,
MarginMm = 20
});
Urdu Example
var urduHtml = @"
<div dir='rtl' style='font-family: Jameel Noori Nastaleeq;'>
<h1>رپورٹ</h1>
<p>یہ اردو زبان میں لکھی گئی ایک رپورٹ ہے جو کامل طور پر دائیں سے بائیں کی طرف چلتی ہے۔</p>
</div>";
byte[] urduPdf = Pdf.Render(urduHtml, new PdfOptions
{
Language = PdfLanguage.Urdu,
PageSize = PageSize.A5
});
Hebrew Example
var hebrewHtml = @"
<div dir='rtl' style='font-family: David, Arial Hebrew;'>
<h1>דוח חודשי</h1>
<p>זהו דוח בעברית המדגים תמיכה מלאה בכתיבה מימין לשמאל.</p>
</div>";
byte[] hebrewPdf = Pdf.Render(hebrewHtml, new PdfOptions
{
Language = PdfLanguage.Hebrew,
MarginMm = 15
});
🔀 Mixed RTL / LTR Content
var mixedHtml = @"
<div>
<p><span dir='rtl'>هذا النص بالعربية</span> contains
<span dir='ltr'>English text</span> and
<span dir='rtl'>المزيد من العربية</span></p>
<p><span dir='ltr'>Product Code: INV-2024-001</span> -
<span dir='rtl'>رمز المنتج</span></p>
</div>";
byte[] mixedPdf = Pdf.Render(mixedHtml);
✍️ Document Signing
Text Signatures
string html = @"
<div class='signature-box'>
<p><strong>Signed by:</strong> John Doe</p>
<p><strong>Date:</strong> " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>
<div class='signature-line'>John Doe</div>
</div>";
byte[] pdf = Pdf.Render(html);
Image Signatures
byte[] signatureImageBytes = File.ReadAllBytes("signature.png");
string signatureBase64 = Convert.ToBase64String(signatureImageBytes);
string html = $@"
<img src='data:image/png;base64,{signatureBase64}' style='max-width:200px;'/>";
byte[] pdf = Pdf.Render(html);
Multiple Signatures
byte[] sig1 = File.ReadAllBytes("signature1.png");
byte[] sig2 = File.ReadAllBytes("signature2.png");
string html = $@"
<img src='data:image/png;base64,{Convert.ToBase64String(sig1)}'/>
<img src='data:image/png;base64,{Convert.ToBase64String(sig2)}'/>
";
byte[] pdf = Pdf.Render(html);
🔏 Stamps and Seals
<div class="stamp">
APPROVED
<br/>
2026-03-12
</div>
.stamp {
border:3px solid red;
border-radius:50%;
width:150px;
height:150px;
text-align:center;
font-weight:bold;
transform:rotate(-15deg);
}
💧 Watermarks
<div class="watermark">CONFIDENTIAL</div>
.watermark{
position:fixed;
top:50%;
left:50%;
transform:translate(-50%,-50%) rotate(-45deg);
font-size:72px;
opacity:0.2;
}
⚙️ Configuration Options
var options = new PdfOptions
{
PageSize = PageSize.A4,
Landscape = false,
MarginMm = 15,
Language = PdfLanguage.Auto,
Scale = 1.0f,
PrintBackground = true,
TimeoutMs = 7000
};
📄 Page Size Options
public enum PageSize
{
A4,
Letter,
Legal,
A3,
A5
}
🌐 Language Options
public enum PdfLanguage
{
Auto,
Arabic,
Urdu,
English,
Hebrew
}
📋 Requirements
Runtime
- .NET 10.0
Supported Browsers
One of the following must be available:
- Google Chrome
- Microsoft Edge
- Chromium
If no browser is detected, the library will automatically download Chromium (~200MB).
🎯 Performance Tips
- Cache generated PDFs for identical HTML
- Use inline CSS instead of external stylesheets
- Compress large images before embedding
- Increase TimeoutMs for complex JavaScript pages
🔒 Error Handling
try
{
byte[] pdf = Pdf.Render(html);
}
catch (HtmlToPdfException ex)
{
Console.WriteLine($"PDF generation failed: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}
🐛 Troubleshooting
Browser not found
- Install Chrome / Edge / Chromium
- Allow internet access for auto download
RTL text issues
- Use
dir="rtl" - Set proper fonts
- Specify
LanguageinPdfOptions
Watermarks not visible
- Use
position: fixed - Increase
z-index
📝 License
MIT License
❤️ Author
Muammar Siddiqui
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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.
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.