PNG JPG BMP TIFF PDF
Aspose.PDF  for Python

通过 Python SDK 向 PDF 添加删除线文本注释

使用云端 Python SDK 向 PDF 文档添加注释的 API。

Get Started

如何通过云端 Python SDK 向 PDF 添加删除线注释

要向 PDF 添加注释,我们将使用 Aspose.PDF Cloud Python SDK。该云 SDK 帮助 Python 程序员使用 Aspose.PDF REST API 开发基于云的 PDF 创建、注释、编辑和转换应用程序。只需在 Aspose for Cloud 创建一个帐户并获取您的应用程序信息。一旦您拥有 App SID 和密钥,就可以使用 Aspose.PDF Cloud Python SDK。如果 python 包托管在 Github 上,您可以直接从 Github 安装:

从 Github 安装


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

包管理器控制台命令

     
    pip install asposepdfcloud

通过 Python 向 PDF 添加删除线注释的步骤

Aspose.PDF Cloud 开发人员可以轻松地在几行代码中加载并向 PDF 添加注释。

  1. 安装 Python SDK
  2. 上传输入 PDF。
  3. 创建一个具有位置、颜色和文本等属性的新删除线注释。
  4. 将注释发布到 PDF。
  5. 验证响应。
  6. 下载已注释的文档。
 

使用 Python 向 PDF 添加删除线注释


    from annotations_helper import Config, PdfAnnotationsHelper, logging
    from asposepdfcloud import PdfApi, StrikeOutAnnotation, Rectangle, Color, Point, AnnotationFlags, HorizontalAlignment, VerticalAlignment

    class PdfAddStrikeoutAnnotations:
        """Class for managing PDF annotations using Aspose PDF Cloud API."""
        def __init__(self, pdf_api: PdfApi, helper: PdfAnnotationsHelper):
            self.pdfApi = pdf_api
            self.helper = helper

        def append_strikeout_annotation(self):
            """Append a new strikeout text annotation to the PDF document."""
            if self.pdfApi:
                self.helper.uploadFile(Config.PDF_DOCUMENT_NAME, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER)
                
                args = {
                    "folder": Config.REMOTE_FOLDER
                }
                
                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 = Config.NEW_SO_ANNOTATION_TEXT,
                    subject = Config.NEW_SO_ANNOTATION_SUBJECT,
                    title = Config.NEW_SO_ANNOTATION_DESCRIPTION,
                    contents= Config.NEW_SO_ANNOTATION_CONTENTS,
                    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 = '03/27/2025 00:00:00.000 AM',
                )
                try:
                    response = self.pdfApi.post_page_strike_out_annotations(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER, [new_annotation], **args)
                    if response.code == 200:
                        logging.info(f"append_strikeout_annotation(): annotation '{Config.NEW_SO_ANNOTATION_TEXT}' added to the document '{Config.PDF_DOCUMENT_NAME}'.")
                        self.helper.downloadFile(Config.PDF_DOCUMENT_NAME, Config.LOCAL_RESULT_DOCUMENT_NAME, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER, "add_strikeout_")
                    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}")