PDF Editor Component

Edit PDFs with
Powerful Precision

Create, modify, and manipulate PDF documents programmatically. Add text, images, watermarks, merge documents, and fill forms with ease.

document.pdf - PDF Editor
New text here
DRAFT
1 var pdf = PdfReader.Open("doc.pdf");
2 gfx.DrawString("Hello", font, pos);
Create new PDF documents from scratch
Edit text, fonts, and add comments
Insert, delete, and rotate pages
Set PDF security and permissions
Fill in PDF forms programmatically
Export PDF to other formats

Code Examples

Learn how to manipulate PDF documents with simple, clean code

Create New PDF Document

Create a new PDF document from scratch and add text, images, and graphics with full control.

C#
PdfDocument pdfDocument = new PdfDocument();
var page = pdfDocument.AddPage();
page.Size = PdfEdit.PageSize.A4;

XGraphics gfx = XGraphics.FromPdfPage(page);

// Draw text
gfx.DrawString("Hello, PDF World!",
    new XFont("Arial", 10),
    XBrushes.Blue,
    new PointF(100, 100));

// Draw image
XImage image = XImage.FromFile(@"c:\images\logo.jpg");
gfx.DrawImage(image, new Point(300, 300));

gfx.Dispose();
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\output.pdf");

Add Pages to Existing PDF

Open an existing PDF document and append additional blank pages for further content.

C#
PdfDocument pdfDocument = PdfReader.Open(
    @"c:\test\test.pdf",
    PdfDocumentOpenMode.Modify);

// Add new blank pages
var newPage = pdfDocument.AddPage();
var newPage2 = pdfDocument.AddPage();

// Configure page size if needed
newPage.Size = PdfEdit.PageSize.Letter;

pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

Edit Existing PDF

Open an existing document and add watermarks, text, or images to every page.

C#
PdfDocument pdfDocument = PdfReader.Open(
    @"c:\test\test.pdf",
    PdfDocumentOpenMode.Modify);

// Add watermark to every page
foreach(var page in pdfDocument.Pages)
{
    XGraphics gfx = XGraphics.FromPdfPage(page);

    // Draw text watermark
    gfx.DrawString("CONFIDENTIAL",
        new XFont("Arial", 10),
        XBrushes.Red,
        new PointF(50, 50));

    // Add logo image
    XImage image = XImage.FromFile(@"c:\images\logo.bmp");
    gfx.DrawImage(image, new Point(150, 150));

    gfx.Dispose();
}

pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

Remove Pages from PDF

Open a PDF document and remove specific pages by their index.

C#
PdfDocument pdfDocument = PdfReader.Open(
    @"c:\test\test.pdf",
    PdfDocumentOpenMode.Modify);

// Check if document has enough pages
if (pdfDocument.Pages.Count > 1)
{
    // Remove second page (0-indexed)
    pdfDocument.Pages.RemoveAt(1);
}

// Remove multiple pages (from end to avoid index shift)
for (int i = pdfDocument.Pages.Count - 1; i >= 5; i--)
{
    pdfDocument.Pages.RemoveAt(i);
}

pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

Extract Pages from PDF

Create a new document from selected pages of an existing PDF without modifying the original.

C#
// Open in Import mode (read-only)
PdfDocument pdfDocument = PdfReader.Open(
    @"c:\test\test.pdf",
    PdfDocumentOpenMode.Import);

PdfDocument newPdfDocument = new PdfDocument();

// Extract every second page
for (int i = 0; i < pdfDocument.Pages.Count; i++)
{
    if ((i + 1) % 2 == 0)
        newPdfDocument.AddPage(pdfDocument.Pages[i]);
}

newPdfDocument.SetLicenseInfo("companyName", "licenseKey");
newPdfDocument.Save(@"c:\test\extracted.pdf");

Protect PDF & Set Permissions

Encrypt your PDF with AES-256 and configure granular user access permissions.

C#
PdfDocument pdfDocument = PdfReader.Open(
    @"c:\test\test.pdf",
    PdfDocumentOpenMode.Modify);

// Set encryption algorithm
pdfDocument.SecuritySettings.PdfDocumentEncryptionAlgorithm =
    new EncryptionAlgorithmInfo();
pdfDocument.SecuritySettings.PdfDocumentEncryptionAlgorithm.Type =
    PdfDocumentSecurityLevel.AES_256;

// Set passwords
pdfDocument.SecuritySettings.OwnerPassword = "ownerPass";
pdfDocument.SecuritySettings.UserPassword = "userPass";

// Configure permissions
pdfDocument.SecuritySettings.PermitPrint = true;
pdfDocument.SecuritySettings.PermitFullQualityPrint = false;
pdfDocument.SecuritySettings.PermitModifyDocument = true;
pdfDocument.SecuritySettings.PermitFormsFill = false;
pdfDocument.SecuritySettings.PermitExtractContent = true;

pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\protected.pdf");

Fill in a PDF Form

Programmatically fill text fields in PDF forms and save to a new document.

C#
PdfDocument pdfDocument = PdfReader.Open(
    @"c:\test\form.pdf",
    PdfDocumentOpenMode.Modify);

// Get field by name
var textField = pdfDocument.AcroForm.Fields["FieldSubjectType"]
    as PdfTextField;

// Check if field is editable
if (!textField.ReadOnly)
{
    textField.Text = "Top Secret";
}

// Fill multiple fields
var nameField = pdfDocument.AcroForm.Fields["Name"] as PdfTextField;
nameField.Text = "John Doe";

var dateField = pdfDocument.AcroForm.Fields["Date"] as PdfTextField;
dateField.Text = DateTime.Now.ToShortDateString();

pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\filled-form.pdf");
Create New PDF Document

Create a new PDF document from scratch.

C#
PdfDocument pdf = new PdfDocument();
var page = pdf.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawString("Hello!", new XFont("Arial", 10),
    XBrushes.Blue, new PointF(100, 100));
pdf.Save(@"c:\output.pdf");
Add Pages to Existing PDF

Append new pages to an existing document.

C#
PdfDocument pdf = PdfReader.Open("test.pdf",
    PdfDocumentOpenMode.Modify);
pdf.AddPage();
pdf.Save("test.pdf");
Edit Existing PDF Document

Add watermarks or content to existing pages.

C#
foreach(var page in pdfDocument.Pages)
{
    XGraphics gfx = XGraphics.FromPdfPage(page);
    gfx.DrawString("DRAFT", font, XBrushes.Red, pos);
}
Remove Pages from PDF

Delete specific pages from a document.

C#
if (pdfDocument.Pages.Count > 1)
    pdfDocument.Pages.RemoveAt(1);
Extract Pages from PDF

Create a new document from selected pages.

C#
PdfDocument newPdf = new PdfDocument();
newPdf.AddPage(sourcePdf.Pages[0]);
newPdf.Save("extracted.pdf");
Protect PDF & Set Permissions

Encrypt and set access permissions.

C#
pdf.SecuritySettings.OwnerPassword = "owner";
pdf.SecuritySettings.UserPassword = "user";
pdf.SecuritySettings.PermitPrint = true;
Fill in a PDF Form

Fill form fields programmatically.

C#
var field = pdf.AcroForm.Fields["Name"] as PdfTextField;
field.Text = "John Doe";

Ready to Edit PDFs?

Download the free demo and start creating and editing PDF documents in your .NET applications today.

Download Free Demo