PNG JPG BMP TIFF PDF
Aspose.PDF  for Python

Add Strikeout text annotations to PDF documents via Python SDK

API for adding strikeout annotations to PDF documents using Aspose.PDF Cloud Python SDK.

Get Started

How to insert strikeout annotations to PDF documents via Aspose.PDF Cloud Python SDK

To add annotations into PDF, 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 add Strikeout annotations to PDF via Python

Aspose.PDF Cloud developers can easily load & add annotations to PDF in just a few lines of code.

  1. Install Python SDK.
  2. Uploads the input PDF.
  3. Creates a new StrikeOutAnnotation with properties like position, color, and text.
  4. Post Annotation to PDF.
  5. Validates the response.
  6. Download Annotated Document.
 

Add Strikeout Annotations to PDF using Python


    from asposepdfcloud import PdfApi, ApiClient, StrikeOutAnnotation, Rectangle, Color, AnnotationFlags, HorizontalAlignment, Point, VerticalAlignment
    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 PdfAddStrikeoutAnnotations:
        """Class for managing PDF annotations using Aspose PDF Cloud API."""
        def append_strikeout_annotation(self):
            """Append a new strikeout text annotation to the PDF document."""
            localFolder = "C:\Samples"
            storageDocumentName = "sample.pdf"
            storageTempFolder = "TempPdfCloud"
            outputFileName = "output_add_strikeout_annotation.pdf"

            # 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 + "/" + storageDocumentName
                self.pdf_api.upload_file(os.path.join(storageTempFolder, storageDocumentName), file_path)
                    
                args = {
                    "folder": storageTempFolder
                }
                
                new_annotation = StrikeOutAnnotation(
                    rect = Rectangle(llx=100, lly=100, urx=200, ury=200),
                    name = 'Strikeout_Text_Annotation',
                    flags = [AnnotationFlags.DEFAULT],
                    horizontal_alignment = HorizontalAlignment.LEFT,
                    vertical_alignment = VerticalAlignment.TOP,
                    rich_text = "Your annotation text here",
                    subject = "Your annotation subject here",
                    contents = "Your annotation contents here",
                    title = "Your annotation title here",
                    z_index = 1,
                    color= Color(a=0xFF, r=0, g=0xFF, b=0),
                    quad_points = [
                        Point(10, 10),
                        Point(20, 10),
                        Point(10, 20),
                        Point(10, 10)
                    ],
                    modified = '02/02/2026 00:00:00.000 AM',
                )
                try:
                    response = self.pdf_api.post_page_strike_out_annotations(storageDocumentName, page_number=1, annotations=[new_annotation], **args)

                    if response.code == 200:
                        temp_file = self.pdf_api.download_file(storageTempFolder + '/' + storageDocumentName)
                        local_path = localFolder + '/' + outputFileName
                        shutil.move(temp_file, local_path)
                        logging.info(f"append_strikeout_annotation(): annotation added to the document '{outputFileName}'.")
                    else:
                        logging.error(f"append_strikeout_annotation(): Failed to add annotation to the document. Response code: {response.code}")
                except Exception as e:
                    logging.error(f"append_strikeout_annotation(): Error while adding annotation: {e}")