Skip to main content

Aspose PDF Python via C++

Project description

Product Page | Docs | Demos | API Reference | Examples | Blog | Search | Free Support | Temporary License

Aspose.PDF for Python is a robust on-premise library designed to handle a wide range of document processing tasks. This powerful tool empowers developers to enrich their applications by incorporating functionalities like document generation, modification, conversion, rendering, and printing, all without depending on external software.

PDF API Features

Aspose.PDF for Python offers a comprehensive set of features for working with PDF documents. Here are some popular features provided by the library:

  1. PDF Document Handling: Aspose.PDF for Python enables developers to create, open, modify, and save PDF documents using the associated PDF document handle. This includes tasks such as creating new PDF files, opening existing ones, and performing various operations on them.

  2. Document Page Manipulation: The library allows basic manipulation of document pages, such as adding or removing pages from the PDF document. This functionality provides flexibility in managing the structure and content of the PDF document.

  3. Advanced Page Manipulation: With Aspose.PDF for Python, developers can perform advanced manipulations on individual pages. This includes operations like rotating pages to different orientations, changing the content of pages, and adding elements like stamps or images to enhance the visual representation of the document.

  4. Export to Graphics Formats: The library provides the capability to export PDF document pages to various graphics formats. This allows developers to extract pages from PDF documents and save them as separate image files in formats like JPEG, PNG, or TIFF. This feature is particularly useful when integrating PDF content into other applications or systems that require graphics-based representations.

These features collectively empower developers to efficiently work with PDF documents in Python, offering extensive control over document creation, manipulation, and conversion to meet diverse application requirements.

Platform Independence

Aspose.PDF for Python is a versatile library that supports the development of applications across various operating systems, including Windows and Linux, as long as Python 3.5 or a later version is installed.

Get Started

Are you interested in trying out Aspose.PDF for Python?

To get started, simply run the following command in your console: pip install <insert alias here>. This will fetch the package for you. If you already have Aspose.PDF for Python and would like to upgrade to the latest version, you can use the command pip install --upgrade <insert alias here>.

To see Aspose.PDF in action, you can run the code snippets provided below in your own environment. Alternatively, you can explore the GitHub Repository or refer to the Aspose.PDF for Python Documentation for more information on common use cases.

Using Python to create blank PDF document

Aspose.PDF for Python allows you to create a new blank document:

from AsposePDFPythonWrappers import *

doc = Document()
doc.save("blank_pdf_document.pdf")

or direct with a module API:

from AsposePdfPython import *

doc = document_create()
document_save(doc, "blank_pdf_document.pdf")
close_handle(doc)

Using Python to Extract text from PDF file

Aspose.PDF for Python allows you to extract text from PDF files:

from AsposePDFPythonWrappers import *

def install_license(license_file):  
    lic = License()  
    lic.set_license(license_file)

def extract_text(pdf_file_name, save_file_name):  
    ext = PdfExtractor()  
    ext.bind_pdf(pdf_file_name)  
    ext.extract_text()  
    ext.get_text(save_file_name)

install_license("Aspose.PDF.PythonviaCPP.lic")
extract_text("pdf_file_name.pdf", "text_file_name.txt")

or direct with a module API:

from AsposePdfPython import *

def install_license(license_file):
    lic = license_create()
    license_set(lic, "Aspose.PDF.C++.lic")

def extract_text(pdf_file_name, save_file_name):
    ext = extractor_create()
    extractor_bind_pdf(ext, pdf_file_name)
    text = extractor_extract_text(ext)
    with open(save_file_name, 'w') as f:
    f.write(text)
    close_handle(ext)

install_license("Aspose.PDF.PythonviaCPP.lic")
extract_text("pdf_file_name.pdf", "text_file_name.txt")

Encrypt and Decrypt PDF document

Aspose.PDF for Python allows you to encrypt and decrypt PDF documents:

from AsposePDFPythonWrappers import *

def pdf_encrypt(pdf_file_source, user_password, owner_password, permissions:AsposePDFPython.Permissions, crypto_algorithm:AsposePDFPython.CryptoAlgorithm, pdf_file_result):  
    try:  
        doc = Document(pdf_file_source)  
        doc.encrypt(user_password, owner_password, permissions, crypto_algorithm)  
        doc.save(pdf_file_result)  
    except Exception as e:  
        print(e)  
  
def pdf_decrypt(pdf_file_source, password, pdf_file_result):  
    try:  
        doc = Document(pdf_file_source, password)  
        doc.decrypt()  
        doc.save(pdf_file_result)  
    except Exception as e:  
        print(e)

pdf_encrypt("pdf_file_name.pdf", "user_password", "owner_password", Permissions(Permissions.ExtractContent|ModifyContent), CryptoAlgorithm.AESx256, "pdf_file_result.pdf")
pdf_decrypt("pdf_file_source.pdf", "password", "pdf_file_result.pdf")

or direct with a module API:

from AsposePdfPython import *

def pdf_encrypt(pdf_file_source, user_password, owner_password, permissions:AsposePDFPython.Permissions, crypto_algorithm:AsposePDFPython.CryptoAlgorithm, pdf_file_result): 
	try:
	    doc = document_open(pdf_file_source)
	    document_encrypt_1(doc, user_password, owner_password
	    , Permissions(Permissions.ExtractContent|ModifyContent), CryptoAlgorithm.AESx256)
	    document_save(doc, pdf_file_result)
	except Exception as e:
	    print(e)

def pdf_decrypt(pdf_file_source, password, pdf_file_result):  
	try:
	    doc = document_open_encrypted(pdf_file_source, password)
	    document_decrypt(doc)
	    document_save(doc, pdf_file_result)
	except Exception as e:
	    print(e)

pdf_encrypt("pdf_file_name.pdf", "user_password", "owner_password", Permissions(Permissions.ExtractContent|ModifyContent), CryptoAlgorithm.AESx256, "pdf_file_result.pdf")
pdf_decrypt("pdf_file_source.pdf", "password", "pdf_file_result.pdf")

Merge two PDF files

Aspose.PDF for Python allows you to merge or split PDF files:

from AsposePDFPythonWrappers import *

def merge_files(pdf_file_1, pdf_file_2, result_pdf_file):  
    doc1 = Document(pdf_file_1)  
    doc2 = Document(pdf_file_2)  
    pages1 = doc1.pages  
    pages2 = doc2.pages  
    pages1.add(pages2)  
    doc1.save(result_pdf_file)

merge_files("pdf_file_1.pdf", "pdf_file_2.pdf", "result_pdf_file.pdf")

or direct with a module API:

from AsposePdfPython import *

def merge_files(pdf_file_1, pdf_file_2, result_pdf_file):  
	doc1 = document_open(pdf_file_1)
	doc2 = document_open(pdf_file_2)
	pages1 = document_get_pages(doc1)
	pages2 = document_get_pages(doc2)
	page_collection_add_pages(pages1, pages2)
	document_save(doc1, result_pdf_file)
	close_handle(doc1)
	close_handle(doc2)

merge_files("pdf_file_1.pdf", "pdf_file_2.pdf", "result_pdf_file.pdf")

Product Page | Docs | Demos | API Reference | Examples | Blog | Search | Free Support | Temporary License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

aspose_pdf_cpp_for_python-25.9.4-py3-none-macosx_11_0_arm64.whl (164.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

aspose_pdf_cpp_for_python-25.9.4-py3-none-macosx_10_14_x86_64.whl (183.9 MB view details)

Uploaded Python 3macOS 10.14+ x86-64

File details

Details for the file aspose_pdf_cpp_for_python-25.9.4-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for aspose_pdf_cpp_for_python-25.9.4-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4daa6e472fe8fc2d6a216b0fd3b3ffcc3a61cd2771cdd108efb5c50949e04b1e
MD5 654601f8efc680c6a65c33729e981a8a
BLAKE2b-256 f336f42095fc98859228ec1d3c450a850aa4344bd8158abff4b2f33e687ecbd5

See more details on using hashes here.

File details

Details for the file aspose_pdf_cpp_for_python-25.9.4-py3-none-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for aspose_pdf_cpp_for_python-25.9.4-py3-none-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d99f2ff6a78d3b9d4743436050772cc142e7bfc8c59ea0acd4ddb2a25b0b4e63
MD5 9dbe2d3705ad14ab7369b7ee7975f025
BLAKE2b-256 b9c0cc58060147a4dbb47662c3b3f4c6c2f636d298c34a02870b68a4ca06e81c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page