1. Produits
  2.   Aspose.PDF
  3.   Aspose.PDF FOSS for .NET

Aspose.PDF FOSS pour .NET

Créer et manipuler des documents PDF à partir de .NET — avec des annotations, des champs de formulaire, l’extraction de texte, la gestion des pages, le chiffrement et l’importation HTML/SVG/Markdown. Sous licence MIT.

Bibliothèque .NET gratuite sous licence MIT pour la création et la manipulation de PDF

Aspose.PDF FOSS for .NET est une bibliothèque sous licence MIT pour créer et travailler avec des documents PDF en C# et .NET. Le point d’entrée central est la classe Document, qui prend en charge la construction à partir d’un chemin de fichier, d’un tableau d’octets, d’un flux ou de sources protégées par mot de passe, et expose les opérations Open, Save, Merge, Encrypt, Decrypt et Convert sur l’ensemble de la spécification PDF.

La bibliothèque expose 805 classes couvrant la structure du document via Document, Page et PageCollection ; des annotations riches via AnnotationCollection (incluant AddTextAnnotation, AddLinkAnnotation, AddHighlightAnnotation, AddWatermarkAnnotation et AddRedactAnnotation) ; des formulaires interactifs avec Form, ButtonField, CheckboxField, RadioButtonField et ChoiceField ; l’extraction de texte et la recherche via TextFragmentAbsorber et TextFragment ; la détection de tables avec AbsorbedTable, AbsorbedRow et AbsorbedCell ; et la sécurité du document via Document.Encrypt et Document.Decrypt. La conversion de format prend en charge l’importation HTML, SVG et Markdown ainsi que l’exportation PDF.

Installez Aspose.PDF FOSS for .NET depuis NuGet : dotnet add package Aspose.Pdf.Foss --version 0.1.0-alpha. La bibliothèque est entièrement sous licence MIT sans frais d’exécution ni restrictions d’utilisation. Pour les fonctionnalités et le support d’entreprise, consultez Aspose.PDF for .NET — Enterprise Product.

Document Structure and Page Management

  • Document API: Create new PDFs with Document() or open existing files via Document.Open(path), Document.Open(data), or Document.Open(stream).
  • Page management: Add, access, and reorder pages via PageCollection. Each Page exposes Width, Height, MediaBox, rotation, and Annotations.
  • Merge and split: Combine multiple files with Document.Merge(documents) or Document.MergeDocuments(files). Import specific pages with Document.ImportPage and Document.ImportPages.
  • Metadata: Read and write document metadata via DocumentInfo and Document.GetOrCreateMetadata().
  • Serialization: Persist documents with Document.Save(filename), Document.Save(stream, format), or Document.ToArray().

Common Document Processing Scenarios

  • PDF generation: Build documents programmatically by creating a Document instance and populating pages with content.
  • Document analysis: Open existing files for metadata inspection, page dimension measurement, or form field enumeration.
  • Page manipulation: Resize, rotate, or reorder pages using Document.ImportPage and the Page API.
  • Batch merging: Assemble report sections or invoice pages into a single PDF using Document.MergeDocuments.

Annotations and Form Fields

  • Rich annotation API: AnnotationCollection exposes methods for text, link, highlight, underline, strikeout, square, circle, line, ink, stamp, caret, redact, watermark, polygon, and polyline annotations.
  • Link actions: Add URI links with AddLinkAnnotation(rect, uri) or internal page-jump links with AddLinkAnnotation(rect, destinationPage, destRect).
  • Interactive forms: Access the document form via Document.Form to enumerate or create ButtonField, CheckboxField, RadioButtonField, and ChoiceField instances.
  • Annotation selection: Filter annotations by type across pages using AnnotationSelector with per-type Visit overloads.
  • Annotation flags: Control visibility, print, and lock behaviour via AnnotationFlags.

Document Review and Collaboration Scenarios

  • Markup review: Add highlight, underline, or free-text annotations for document review workflows.
  • Redaction: Permanently remove sensitive content regions using AddRedactAnnotation.
  • Watermarking: Stamp CONFIDENTIAL or APPROVED text onto pages with AddWatermarkAnnotation and AddStampAnnotation.
  • Interactive forms: Build fillable documents with radio buttons, checkboxes, and choice lists for data capture pipelines.

Text Extraction and Search

  • Text search: Use TextFragmentAbsorber to locate all text fragments on a page or across a document, with optional phrase matching.
  • Fragment properties: Each TextFragment exposes Text, Position, TextState (font, size, colour), and bounding rectangle.
  • Text state control: TextFragmentState provides access to Font, FontSize, ForegroundColor, BackgroundColor, and rendering mode.
  • Table detection: Identify and extract tabular content via AbsorbedTable, AbsorbedRow, and AbsorbedCell, each providing Rect and TextFragments.

Text and Data Extraction Scenarios

  • Content indexing: Extract all page text for full-text search pipelines.
  • Form data extraction: Read submitted field values for server-side processing.
  • Invoice parsing: Use AbsorbedTable to parse tabular row-and-column data from financial PDFs.
  • Redline comparison: Locate specific text fragments for precise position-based annotation or replacement.

Security and Encryption

  • AES and RC4 encryption: Encrypt documents with Document.Encrypt(userPassword, ownerPassword, permissions, algorithm) using Algorithm.AESx128, AESx256, or RC4x128.
  • Permission control: Restrict print, copy, and accessibility via DocumentPrivilege.
  • Password management: Change user and owner passwords with Document.ChangePasswords.
  • Decryption: Remove protection with Document.Decrypt().
  • Digital signatures: Access signature fields and PKCS#7 data through the Signature and Algorithm types.

Document Security Scenarios

  • Confidential distribution: Encrypt PDFs with per-recipient passwords before delivery.
  • Print-only contracts: Apply owner passwords with print-only DocumentPrivilege to prevent copying.
  • Compliance archiving: Strip encryption from internal archives after security review.
  • Signature verification: Inspect embedded digital signatures in received PDFs for authenticity checks.

Open a PDF, Add a Link Annotation, and Save

Open an existing PDF, attach a URI link annotation to page 1, and persist the result.

using Aspose.Pdf;

var data = System.IO.File.ReadAllBytes("input.pdf");
using var doc = Document.Open(data);
var page = doc.Pages[1];
var action = PdfAction.CreateUri("https://aspose.com");
page.Annotations.AddLinkAnnotation(
    new Rectangle(50, 700, 200, 720), action);
using var ms = new System.IO.MemoryStream();
doc.Save(ms);
System.IO.File.WriteAllBytes("output.pdf", ms.ToArray());

Add a Watermark Annotation

Stamp a watermark onto page 1 of an existing document and round-trip through serialization.

using Aspose.Pdf;
var input = System.IO.File.ReadAllBytes("report.pdf");
using var doc = Document.Open(input);
doc.Pages[1].Annotations.AddWatermarkAnnotation(
    new Rectangle(0, 0, 612, 792), "CONFIDENTIAL");
var saved = doc.ToArray();
System.IO.File.WriteAllBytes("watermarked.pdf", saved);

Extract Text Fragments from a Page

Use TextFragmentAbsorber to enumerate all text fragments on the first page.

using Aspose.Pdf;
using Aspose.Pdf.Text;

var data = System.IO.File.ReadAllBytes("document.pdf");
using var doc = Document.Open(data);
var absorber = new TextFragmentAbsorber();
absorber.Visit(doc.Pages[1]);
foreach (var fragment in absorber.TextFragments)
{
    Console.WriteLine(fragment.Text);
}

Foire aux questions

What is the licensing model for Aspose.PDF FOSS for .NET?

Aspose.PDF FOSS for .NET is released under the MIT License, allowing free use in commercial products with no runtime fees. The source code is publicly available on GitHub.

How do I install Aspose.PDF FOSS for .NET?

Install from NuGet using dotnet add package Aspose.Pdf.Foss --version 0.1.0-alpha. The library targets .NET 8 and later with no native dependencies.

Which file formats does Aspose.PDF FOSS for .NET support?

The library reads and writes PDF and supports import of HTML, SVG, and Markdown. Raster export is also available — PDF pages can be rendered to BMP, JPEG, PNG, and TIFF.

How do I create a new PDF document?

Use Document.Create() to produce an empty document, then add pages and save with Document.Save(stream) or Document.ToArray().

Is a license key required to use Aspose.PDF FOSS for .NET?

No license key or activation step is required. The library runs fully unlicensed at no cost under the MIT License.

  

Ressources de support et d'apprentissage

 Français