Document

Overview

Document is a class in Aspose.PDF FOSS for Python.

Pythonic wrapper for PDF document lifecycle and core operations.

This class provides 16 methods for working with Document objects in Python programs. Available methods include: __init__, change_passwords, check, close, decrypt, dispose, encrypt, flatten, free_memory, load_from, merge, optimize, and 4 additional methods. All public members are accessible to any Python application after installing the Aspose.PDF FOSS for Python package. Properties: file_name, form, id, info, is_disposed, is_encrypted, and 10 more.

Properties

NameTypeAccessDescription
load_limitsPdfLoadLimitsReadReturn the resource limits used for loading this document.
is_disposedboolReadExpose the disposal state of the document.
page_countintReadNumber of pages currently in the document.
file_nameAnyReadGets the file name.
infoAnyReadGets the info.
metadataAnyReadGets the metadata.
idAnyReadGets the id.
versionAnyReadGets the version.
pagesAnyReadGets the pages.
outlinesAnyReadGets the outlines.
named_destinationsAnyReadGets the named destinations.
formAnyReadGets the form.
is_encryptedAnyReadGets the is encrypted.
permissionsAnyReadGets the permissions.
is_pdfa_compliantAnyReadGets the is pdfa compliant.
is_pdfua_compliantAnyReadGets the is pdfua compliant.

Methods

SignatureDescription
__init__(source: str | Path | bytes | bytearray | BinaryIO | None, options: Any, password: str | None, limits: PdfLoadLimits | None)Create a new :class:Document instance.
load_from(source: str | bytes | bytearray | Path | BinaryIO, password: str | None, limits: PdfLoadLimits | None)DocumentLoad a document from source using native engine.
save(destination: Any, save_format: Any, overwrite: bool)DocumentSave the document to destination using native engine.
close()Alias of :meth:dispose.
dispose()Release resources associated with this document.
merge()DocumentMerge the supplied documents into the current one.
optimize(compress_images: bool)DocumentPerform generic optimizations on the document.
optimize_resources(remove_unused: bool)DocumentOptimize shared resources such as fonts and images.
repair()DocumentAttempt to repair the document’s structure via the engine.
flatten()DocumentFlatten form fields and annotations via the engine.
free_memory()Clear any cached data that might hold onto memory.
encrypt(password: str)DocumentEncrypt the document with the given password.
decrypt(password: str)DocumentDecrypt the document if password matches the stored one.
change_passwords(old_password: str, new_password: str)DocumentChange the document’s password from old_password to new_password.
validate()boolReturn True if the document is structurally valid.
check()boolAlias for :meth:validate kept for API compatibility.

See Also