Create PDF Portfolios in Python

Creating a PDF portfolio allows consolidating and archiving different types of files into a single, consistent document. Such a document could include text files, images, spreadsheets, presentations, and other materials, and ensure that all relevant material is stored and organized in one place.

The PDF portfolio will help to show your presentation in a high-quality way, wherever you use it. In general, creating a PDF portfolio is a very current and modern task.

Use a PDF portfolio when you want to distribute a collection of related files together while keeping each file in its original format inside one PDF container.

How to Create a PDF Portfolio

Aspose.PDF for Python via .NET allows creating PDF Portfolio documents using the Document class. Add a file into a document.collection object after getting it with the FileSpecification class. When the files have been added, use the Document class’ save() method to save the portfolio document.

The following example uses a Microsoft Excel File, a Word document and an image file to create a PDF Portfolio.

The code below results in the following portfolio.

A PDF Portfolio created with Aspose.PDF for Python

A PDF Portfolio created with Aspose.PDF for Python

import aspose.pdf as ap

def create_pdf_portfolio(input_files, outfile):
    # Instantiate Document Object
    document = ap.Document()

    # Instantiate document Collection object
    document.collection = ap.Collection()

    # Get Files to add to Portfolio
    excel = ap.FileSpecification(input_files[0])
    word = ap.FileSpecification(input_files[1])
    image = ap.FileSpecification(input_files[2])

    # Provide description of the files
    excel.description = "Excel File"
    word.description = "Word File"
    image.description = "Image File"

    # Add files to document collection
    document.collection.append(excel)
    document.collection.append(word)
    document.collection.append(image)

    # Save Portfolio document
    document.save(outfile)

Remove Files from PDF Portfolio

In order to delete/remove files from PDF portfolio, try using the following code lines.

import aspose.pdf as ap

def remove_files_from_pdf_portfolio(infile, outfile):
    # Open document
    document = ap.Document(infile)
    document.collection.delete()

    # Save updated file
    document.save(outfile)