Getting Started
Installation
To integrate SlapKit.PDF into your project, simply install the NuGet package by running the following command:
dotnet add package SlapKit.PDF
And that's it—you're ready to get started!
Examples
Explore our documentation, featuring practical examples inspired by real-world scenarios. These examples cover a variety of specific use cases that you may find really useful.
using SlapKit.PDF.Content;
using SlapKit.PDF.Core;
using SlapKit.PDF.Fonts.Standard14Fonts;
using SlapKit.PDF.Options;
using SlapKit.PDF.Writer;
// Initialize a document with empty page
PdfDocumentBuilder builder = new PdfDocumentBuilder();
PdfPageBuilder page = builder.AddPage(PageSize.A4);
// Register the fonts to be used
PdfDocumentBuilder.AddedFont font = builder.AddStandard14Font(Standard14Font.TimesRoman);
PdfDocumentBuilder.AddedFont fontBold = builder.AddStandard14Font(Standard14Font.TimesBold);
// Add text with color
page.SetTextAndFillColor(r: 39, g: 82, b: 145);
page.AddText(text: "Introducing SlapKit: the .NET document processing suite", fontSize: 14, position: new PdfPoint(125, 800), fontBold);
page.ResetColor();
// The multi-line text API will allow you to adjust lines of text in flow-like manner
const string LongText = "Introducing SlapKit.PDF, the .NET library crafted to cater to your PDF requirements. Effortlessly create new PDF files, modify existing ones, or extract data with precision. SlapKit.PDF provides a smooth and robust PDF handling experience, whithout any third-party dependencies. Embrace the simplicity and strength of SlapKit.PDF for your PDF tasks.";
page.AddMultiLineText(LongText, boundingRectangle: new PdfRectangle(new PdfPoint(25, 600), new PdfPoint(325, 730)), options: new MultiLineTextOptions(fontSize: 10, lineHeight: 14, font));
// Add image at a position
page.AddPng(pngBytes: File.ReadAllBytes("point.png"), placementRectangle: new PdfRectangle(new PdfPoint(25, 630), new PdfPoint(40, 640)));
// Add URL link with text
page.AddHyperlink(uri: "https://docs.slapkit.com/pdf/", text: "Get Started Now", fontSize: 10, position: new PdfPoint(45, 630), font);
page.AddPng(pngBytes: File.ReadAllBytes("abstract-workspace.png"), placementRectangle: new PdfRectangle(new PdfPoint(300, 500), new PdfPoint(600, 750)));
byte[] bytes = builder.Build();
File.WriteAllBytes("document.pdf", bytes);
Tip
If you have any questions, feel free to reach out to us at support@slapkit.com.
* NuGet is a trademark of the Microsoft group of companies.