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

aspose_pdf_cpp_for_python-2.0-py3-none-win_amd64.whl (144.9 MB view hashes)

Uploaded Python 3 Windows x86-64

aspose_pdf_cpp_for_python-2.0-py3-none-macosx_11_0_arm64.whl (122.2 MB view hashes)

Uploaded Python 3 macOS 11.0+ ARM64

aspose_pdf_cpp_for_python-2.0-py3-none-macosx_10_14_x86_64.whl (134.8 MB view hashes)

Uploaded Python 3 macOS 10.14+ x86-64

Supported by

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