HTML JPG PDF XML DOCX
  Product Family
PDF

Work with stamps in PDF in Python SDK

Manipulate stamps in PDF Document using server-side Python API.

Get Started

Most popular actions with Stamps in Python

How to work with Stamps via Cloud Python SDK

In order to work with Stamps in PDF via Cloud Python SDK , we’ll use Aspose.PDF Cloud Python SDK. This Cloud SDK assists Python programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Python programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Python SDK. If the python package is hosted on Github, you can install directly from Github:

Installation from Github


     
    pip install git+https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python.git

Package Manager Console Command

     
    pip install asposepdfcloud

Steps to create a Stamps via Python SDK

Aspose.PDF Cloud developers can easily load & create Stamps in PDF in just a few lines of code.

  1. Install Python SDK
  2. Upload a PDF document to the Aspose Cloud server
  3. Upload Image file to the Aspose Cloud server
  4. Call API to insert Stamps
  5. Download the processed PDF document from the Aspose Cloud server
 

This sample code shows adding Stamps in PDF documents


    from asposepdfcloud import PdfApi, ApiClient, Stamp, StampType, HorizontalAlignment, AsposeResponse
    import shutil
    import os
    import json
    from pathlib import Path
    import logging

    # Configure logging
    logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

    class PdfAddStamps:
        """Class for inserting Stamps to PDF using Aspose PDF Cloud API."""
        def insert(self):
            """Add Stamps to PDF document."""
            localFolder = "C:\Samples"
            storagePDFName = "sample.pdf"
            storageTempFolder = "TempPdfCloud"
            outputFileName = "output_add_stamps.pdf"
            imageStampFile ="sample.png"

            # Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
            self.pdf_api = PdfApi(ApiClient(AppSecret, AppSid))

            if self.pdf_api:
                file_path = localFolder + "/" + storagePDFName
                self.pdf_api.upload_file(os.path.join(storageTempFolder, storagePDFName), file_path)

                self.pdf_api.upload_file(os.path.join(storageTempFolder, imageStampFile), os.path.join(localFolder, imageStampFile))

                text_stamp: Stamp = Stamp(
                    type = StampType.TEXT,
                    background = True,
                    horizontal_alignment = HorizontalAlignment.CENTER,
                    text_alignment = HorizontalAlignment.CENTER,
                    value="Your TEXT Stamp Value here"
                )

                image_stamp: Stamp = Stamp(
                    type = StampType.IMAGE,
                    background = True,
                    horizontal_alignment = HorizontalAlignment.CENTER,
                    text_alignment = HorizontalAlignment.CENTER,
                    value = "Your IMAGE Stamp Description here",
                    file_name = os.path.join(storageTempFolder, imageStampFile),
                    y_indent = 400,
                    width = 64,
                    height = 64
                )
                
                opts = { "folder": storageTempFolder }

                try:
                    responseTextStamp: AsposeResponse = self.pdf_api.post_document_text_stamps(storagePDFName, [ text_stamp ], **opts)
                    responseImageStamp: AsposeResponse = self.pdf_api.post_document_image_stamps(storagePDFName, [ image_stamp ], **opts)

                    if responseTextStamp.code == 200 and responseImageStamp.code == 200:
                        temp_file = self.pdf_api.download_file(storageTempFolder + '/' + storagePDFName)
                        local_path = localFolder + '/' + outputFileName
                        shutil.move(temp_file, local_path)
                        logging.info(f"PdfAddStamps(): Stamps inserted successfully to PDF: '{outputFileName}'.")
                    else:
                        logging.error(f"PdfAddStamps(): Failed to insert Stamps to PDF. Response code:test = {responseTextStamp.code}, image = {responseImageStamp}")
                except Exception as e:
                    logging.error(f"PdfAddStamps(): Error while converting image: {e}")
 

With our Python SDK you can

  • Add PDF document’s header & footer in text or image format.
  • Add tables & text or image stamps to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free App to replace the images in PDF files online and test the functionality.

  •