rdvojmoc/DinkToPdf
소개
WebKit 엔진을 사용해 HTML 페이지를 PDF로 변환하는 wkhtmltopdf 라이브러리의 C# .NET Core 래퍼입니다.
웹 및 앱 개발측정된 스타 증가
- in 24h
- -1
- in 7 days
- -2
- in 15 days
- -3
- in 1 month
- -6
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalDinkToPdf
.NET Core P/Invoke wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
Install
Library can be installed through Nuget. Run command bellow from the package manager console:
PM> Install-Package DinkToPdf
Copy native library to root folder of your project. From there .NET Core loads native library when native method is called with P/Invoke. You can find latest version of native library here. Select appropriate library for your OS and platform (64 or 32 bit).
IMPORTANT
Library was NOT tested with IIS. Library was tested in console applications and with Kestrel web server both for Web Application and Web API .
Basic converter
Use this converter in single threaded applications.
Create converter:
var converter = new BasicConverter(new PdfTools());
Synchronized converter
Use this converter in multi threaded applications and web servers. Conversion tasks are saved to blocking collection and executed on a single thread.
var converter = new SynchronizedConverter(new PdfTools());
Define document to convert
var doc = new HtmlToPdfDocument()
{
GlobalSettings = {
ColorMode = ColorMode.Color,
Orientation = Orientation.Landscape,
PaperSize = PaperKind.A4Plus,
},
Objects = {
new ObjectSettings() {
PagesCount = true,
HtmlContent = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consectetur mauris eget ultrices iaculis. Ut odio viverra, molestie lectus nec, venenatis turpis.",
WebSettings = { DefaultEncoding = "utf-8" },
HeaderSettings = { FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 }
}
}
};
Convert
If Out property is empty string (defined in GlobalSettings) result is saved in byte array.
byte[] pdf = converter.Convert(doc);
If Out property is defined in document then file is saved to disk:
var doc = new HtmlToPdfDocument()
{
GlobalSettings = {
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Margins = new MarginSettings() { Top = 10 },
Out = @"C:\DinkToPdf\src\DinkToPdf.TestThreadSafe\test.pdf",
},
Objects = {
new ObjectSettings()
{
Page = "http://google.com/",
},
}
};
converter.Convert(doc);
Dependency injection
Converter must be registered as singleton.
public void ConfigureServices(IServiceCollection services)
{
// Add converter to DI
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
}
관련 프로젝트 살펴보기
불러오는 중…