PdfFileSanitization

PdfFileSanitization

Overview

PdfFileSanitization is a class in Aspose.PDF FOSS for .NET. Inherits from: IDisposable.

Repairs damaged PDF files at the byte level so they open again: trims waste bytes before the %PDF- header and after the final %%EOF, and rebuilds a broken cross-reference table / trailer by re-scanning the file for its indirect objects.

This class declares 11 methods for PdfFileSanitization objects in .NET programs. Available methods include: BindPdf, Close, Dispose, RebuildXrefAndTrailer, Recover, Save, TrimBottom, TrimTop. Public members are accessible to any .NET application after installing the Aspose.PDF FOSS for .NET package. Properties: Log, UseRebuildXrefAndTrailer, UseTrimBottom, UseTrimTop.

Properties

NameTypeAccessDescription
LogList<string>ReadLog of the recovery actions performed, one line per action.
UseTrimTopboolRead/WriteWhether Recover trims waste bytes before the %PDF- header.
UseTrimBottomboolRead/WriteWhether Recover trims waste bytes after the last %%EOF.
UseRebuildXrefAndTrailerboolRead/WriteWhether Recover also rebuilds the cross-reference table and trailer.

Methods

SignatureDescription
BindPdf(inputFile: string)Bind the PDF file to sanitize.
BindPdf(inputStream: Stream)Bind the PDF content to sanitize.
BindPdf(srcDoc: Document)Bind an already-loaded document: its current serialized form is captured as the bytes to sanitize.
Recover()Run the recovery steps selected by UseTrimTop, UseTrimBottom and UseRebuildXrefAndTrailer.
TrimTop()Remove every byte before the first %PDF- header.
TrimBottom()Remove every byte after the last %%EOF (one end-of-line sequence after the marker is kept).
RebuildXrefAndTrailer()Rebuild the cross-reference table and trailer: the file is scanned for its N G obj headers (skipping stream payloads, so binary data can’t fake an object start) and a fresh classic xref + trailer is appended after the existing content.
Save(outputFile: string)Write the sanitized file.
Save(outputStream: Stream)Write the sanitized content to a stream.
Close()Release the bound input.
Dispose()Release the bound input.

See Also