Spire.PDF for .NET

Written by

in

Spire.PDF for .NET is a standalone, commercial .NET PDF library developed by E-iceblue that allows developers to create, read, edit, convert, and manipulate PDF documents programmatically without any dependencies on Adobe Acrobat. It supports multiple frameworks including .NET Framework, .NET Core, .NET Standard, and newer environments like .NET 8.0, 9.0, and 10.0.

Below is a guide explaining how to install the library, generate new documents from scratch, and modify existing files. 🚀 Getting Started and Installation

You can easily integrate the library into your project using the NuGet Package Manager within Visual Studio. Run the following command in your Package Manager Console: Install-Package Spire.PDF Use code with caution.

(Alternatively, you can opt for the free tier package named FreeSpire.PDF, which contains structural page limits). 📄 How to Generate a PDF from Scratch

To create a new PDF document, you initialize a PdfDocument instance, append a page, draw elements onto its graphics canvas, and save the output.

using Spire.Pdf; using Spire.Pdf.Graphics; using System.Drawing; class Program { static void Main() { // 1. Initialize a new PDF document object PdfDocument doc = new PdfDocument(); // 2. Add an empty page PdfPageBase page = doc.Pages.Add(); // 3. Define your font family, size, style, and brush color PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 14f, PdfFontStyle.Bold); PdfBrush brush = PdfBrushes.DarkBlue; // 4. Draw a text string onto the page’s Canvas page.Canvas.DrawString(“Hello World! Generated via Spire.PDF.”, font, brush, 50, 50); // 5. Save the output to your local filesystem doc.SaveToFile(“GeneratedDocument.pdf”); doc.Dispose(); } } Use code with caution. ✏️ How to Edit Existing PDF Files

Editing a PDF involves loading a previously created file through LoadFromFile(), selecting a target page index, and updating its components. 1. Inserting Images into a PDF Page

You can render visual assets dynamically onto coordinates by converting local image files into a PdfImage element.

// Load an existing file PdfDocument doc = new PdfDocument(); doc.LoadFromFile(“GeneratedDocument.pdf”); // Target the first page (Index 0) PdfPageBase page = doc.Pages[0]; // Load your graphic element PdfImage image = PdfImage.FromFile(“logo.png”); // Define position (X, Y) and structural scale dimensions (Width, Height) float x = 50; float y = 100; float width = image.Width0.5f; float height = image.Height * 0.5f; // Draw image onto the canvas layer page.Canvas.DrawImage(image, x, y, width, height); doc.SaveToFile(“ModifiedDocument.pdf”); doc.Dispose(); Use code with caution. 2. Creating and Appending Fillable Form Fields

You can interact with data inputs by appending interactive components such as textboxes, checkboxes, and radio buttons.

PdfDocument doc = new PdfDocument(); doc.LoadFromFile(“ModifiedDocument.pdf”); PdfPageBase page = doc.Pages[0]; // Instantiate a fillable text box field PdfTextBoxField textBox = new PdfTextBoxField(page, “TxtUserName”); textBox.Bounds = new RectangleF(50, 250, 200, 20); textBox.Text = “Enter Username Here”; // Register the form field object into the document’s form collection doc.Form.Fields.Add(textBox); doc.SaveToFile(“FormDocument.pdf”); doc.Dispose(); Use code with caution. 🛠️ Key Capabilities Overview

Beyond simple creation and editing, the E-iceblue Spire.PDF Program Guide highlights advanced capabilities: Spire.PDF by E-ICEBLUE – SoftwareOne Marketplace

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *