44for supported document processing operations.
55"""
66
7- from typing import TYPE_CHECKING , Any , Protocol
7+ from typing import TYPE_CHECKING , Any , Protocol , Optional , Union
88
99from nutrient_dws .file_handler import FileInput
1010
@@ -40,17 +40,17 @@ def _process_file(
4040 self ,
4141 tool : str ,
4242 input_file : FileInput ,
43- output_path : str | None = None ,
43+ output_path : Optional [ str ] = None ,
4444 ** options : Any ,
45- ) -> bytes | None :
45+ ) -> Optional [ bytes ] :
4646 """Process file method that will be provided by NutrientClient."""
4747 raise NotImplementedError ("This method is provided by NutrientClient" )
4848
4949 def convert_to_pdf (
5050 self ,
5151 input_file : FileInput ,
52- output_path : str | None = None ,
53- ) -> bytes | None :
52+ output_path : Optional [ str ] = None ,
53+ ) -> Optional [ bytes ] :
5454 """Convert a document to PDF.
5555
5656 Converts Office documents (DOCX, XLSX, PPTX) to PDF format.
@@ -76,8 +76,8 @@ def convert_to_pdf(
7676 return self .build (input_file ).execute (output_path ) # type: ignore[attr-defined,no-any-return]
7777
7878 def flatten_annotations (
79- self , input_file : FileInput , output_path : str | None = None
80- ) -> bytes | None :
79+ self , input_file : FileInput , output_path : Optional [ str ] = None
80+ ) -> Optional [ bytes ] :
8181 """Flatten annotations and form fields in a PDF.
8282
8383 Converts all annotations and form fields into static page content.
@@ -99,10 +99,10 @@ def flatten_annotations(
9999 def rotate_pages (
100100 self ,
101101 input_file : FileInput ,
102- output_path : str | None = None ,
102+ output_path : Optional [ str ] = None ,
103103 degrees : int = 0 ,
104- page_indexes : list [int ] | None = None ,
105- ) -> bytes | None :
104+ page_indexes : Optional [ list [int ]] = None ,
105+ ) -> Optional [ bytes ] :
106106 """Rotate pages in a PDF.
107107
108108 Rotate all pages or specific pages by the specified degrees.
@@ -129,9 +129,9 @@ def rotate_pages(
129129 def ocr_pdf (
130130 self ,
131131 input_file : FileInput ,
132- output_path : str | None = None ,
132+ output_path : Optional [ str ] = None ,
133133 language : str = "english" ,
134- ) -> bytes | None :
134+ ) -> Optional [ bytes ] :
135135 """Apply OCR to a PDF to make it searchable.
136136
137137 Performs optical character recognition on the PDF to extract text
@@ -156,15 +156,15 @@ def ocr_pdf(
156156 def watermark_pdf (
157157 self ,
158158 input_file : FileInput ,
159- output_path : str | None = None ,
160- text : str | None = None ,
161- image_url : str | None = None ,
162- image_file : FileInput | None = None ,
159+ output_path : Optional [ str ] = None ,
160+ text : Optional [ str ] = None ,
161+ image_url : Optional [ str ] = None ,
162+ image_file : Optional [ FileInput ] = None ,
163163 width : int = 200 ,
164164 height : int = 100 ,
165165 opacity : float = 1.0 ,
166166 position : str = "center" ,
167- ) -> bytes | None :
167+ ) -> Optional [ bytes ] :
168168 """Add a watermark to a PDF.
169169
170170 Adds a text or image watermark to all pages of the PDF.
@@ -255,8 +255,8 @@ def watermark_pdf(
255255 def apply_redactions (
256256 self ,
257257 input_file : FileInput ,
258- output_path : str | None = None ,
259- ) -> bytes | None :
258+ output_path : Optional [ str ] = None ,
259+ ) -> Optional [ bytes ] :
260260 """Apply redaction annotations to permanently remove content.
261261
262262 Applies any redaction annotations in the PDF to permanently remove
@@ -280,13 +280,13 @@ def create_redactions_preset(
280280 self ,
281281 input_file : FileInput ,
282282 preset : str ,
283- output_path : str | None = None ,
283+ output_path : Optional [ str ] = None ,
284284 include_annotations : bool = False ,
285285 include_text : bool = True ,
286- appearance_fill_color : str | None = None ,
287- appearance_stroke_color : str | None = None ,
288- appearance_stroke_width : int | None = None ,
289- ) -> bytes | None :
286+ appearance_fill_color : Optional [ str ] = None ,
287+ appearance_stroke_color : Optional [ str ] = None ,
288+ appearance_stroke_width : Optional [ int ] = None ,
289+ ) -> Optional [ bytes ] :
290290 """Create redaction annotations using a preset pattern.
291291
292292 Creates redaction annotations for common sensitive data patterns
@@ -345,14 +345,14 @@ def create_redactions_regex(
345345 self ,
346346 input_file : FileInput ,
347347 pattern : str ,
348- output_path : str | None = None ,
348+ output_path : Optional [ str ] = None ,
349349 case_sensitive : bool = False ,
350350 include_annotations : bool = False ,
351351 include_text : bool = True ,
352- appearance_fill_color : str | None = None ,
353- appearance_stroke_color : str | None = None ,
354- appearance_stroke_width : int | None = None ,
355- ) -> bytes | None :
352+ appearance_fill_color : Optional [ str ] = None ,
353+ appearance_stroke_color : Optional [ str ] = None ,
354+ appearance_stroke_width : Optional [ int ] = None ,
355+ ) -> Optional [ bytes ] :
356356 """Create redaction annotations using a regex pattern.
357357
358358 Creates redaction annotations for text matching a regular expression.
@@ -406,15 +406,15 @@ def create_redactions_text(
406406 self ,
407407 input_file : FileInput ,
408408 text : str ,
409- output_path : str | None = None ,
409+ output_path : Optional [ str ] = None ,
410410 case_sensitive : bool = True ,
411411 whole_words_only : bool = False ,
412412 include_annotations : bool = False ,
413413 include_text : bool = True ,
414- appearance_fill_color : str | None = None ,
415- appearance_stroke_color : str | None = None ,
416- appearance_stroke_width : int | None = None ,
417- ) -> bytes | None :
414+ appearance_fill_color : Optional [ str ] = None ,
415+ appearance_stroke_color : Optional [ str ] = None ,
416+ appearance_stroke_width : Optional [ int ] = None ,
417+ ) -> Optional [ bytes ] :
418418 """Create redaction annotations for exact text matches.
419419
420420 Creates redaction annotations for all occurrences of specific text.
@@ -469,14 +469,14 @@ def create_redactions_text(
469469 def optimize_pdf (
470470 self ,
471471 input_file : FileInput ,
472- output_path : str | None = None ,
472+ output_path : Optional [ str ] = None ,
473473 grayscale_text : bool = False ,
474474 grayscale_graphics : bool = False ,
475475 grayscale_images : bool = False ,
476476 disable_images : bool = False ,
477- reduce_image_quality : int | None = None ,
477+ reduce_image_quality : Optional [ int ] = None ,
478478 linearize : bool = False ,
479- ) -> bytes | None :
479+ ) -> Optional [ bytes ] :
480480 """Optimize a PDF to reduce file size.
481481
482482 Applies various optimization techniques to reduce the file size of a PDF
@@ -538,11 +538,11 @@ def optimize_pdf(
538538 def password_protect_pdf (
539539 self ,
540540 input_file : FileInput ,
541- output_path : str | None = None ,
542- user_password : str | None = None ,
543- owner_password : str | None = None ,
544- permissions : dict [str , bool ] | None = None ,
545- ) -> bytes | None :
541+ output_path : Optional [ str ] = None ,
542+ user_password : Optional [ str ] = None ,
543+ owner_password : Optional [ str ] = None ,
544+ permissions : Optional [ dict [str , bool ]] = None ,
545+ ) -> Optional [ bytes ] :
546546 """Add password protection and permissions to a PDF.
547547
548548 Secures a PDF with password protection and optional permission restrictions.
@@ -609,14 +609,14 @@ def password_protect_pdf(
609609 def set_pdf_metadata (
610610 self ,
611611 input_file : FileInput ,
612- output_path : str | None = None ,
613- title : str | None = None ,
614- author : str | None = None ,
615- subject : str | None = None ,
616- keywords : str | None = None ,
617- creator : str | None = None ,
618- producer : str | None = None ,
619- ) -> bytes | None :
612+ output_path : Optional [ str ] = None ,
613+ title : Optional [ str ] = None ,
614+ author : Optional [ str ] = None ,
615+ subject : Optional [ str ] = None ,
616+ keywords : Optional [ str ] = None ,
617+ creator : Optional [ str ] = None ,
618+ producer : Optional [ str ] = None ,
619+ ) -> Optional [ bytes ] :
620620 """Set metadata properties of a PDF.
621621
622622 Updates the metadata/document properties of a PDF file.
@@ -674,8 +674,8 @@ def set_pdf_metadata(
674674 def split_pdf (
675675 self ,
676676 input_file : FileInput ,
677- page_ranges : list [dict [str , int ]] | None = None ,
678- output_paths : list [str ] | None = None ,
677+ page_ranges : Optional [ list [dict [str , int ]]] = None ,
678+ output_paths : Optional [ list [str ]] = None ,
679679 ) -> list [bytes ]:
680680 """Split a PDF into multiple documents by page ranges.
681681
@@ -764,8 +764,8 @@ def duplicate_pdf_pages(
764764 self ,
765765 input_file : FileInput ,
766766 page_indexes : list [int ],
767- output_path : str | None = None ,
768- ) -> bytes | None :
767+ output_path : Optional [ str ] = None ,
768+ ) -> Optional [ bytes ] :
769769 """Duplicate specific pages within a PDF document.
770770
771771 Creates a new PDF containing the specified pages in the order provided.
@@ -855,8 +855,8 @@ def delete_pdf_pages(
855855 self ,
856856 input_file : FileInput ,
857857 page_indexes : list [int ],
858- output_path : str | None = None ,
859- ) -> bytes | None :
858+ output_path : Optional [ str ] = None ,
859+ ) -> Optional [ bytes ] :
860860 """Delete specific pages from a PDF document.
861861
862862 Creates a new PDF with the specified pages removed. The API approach
@@ -966,8 +966,8 @@ def delete_pdf_pages(
966966 def merge_pdfs (
967967 self ,
968968 input_files : list [FileInput ],
969- output_path : str | None = None ,
970- ) -> bytes | None :
969+ output_path : Optional [ str ] = None ,
970+ ) -> Optional [ bytes ] :
971971 """Merge multiple PDF files into one.
972972
973973 Combines multiple files into a single PDF in the order provided.
@@ -1034,8 +1034,8 @@ def add_page(
10341034 page_count : int = 1 ,
10351035 page_size : str = "A4" ,
10361036 orientation : str = "portrait" ,
1037- output_path : str | None = None ,
1038- ) -> bytes | None :
1037+ output_path : Optional [ str ] = None ,
1038+ ) -> Optional [ bytes ] :
10391039 """Add blank pages to a PDF document.
10401040
10411041 Inserts blank pages at the specified insertion index in the document.
@@ -1150,9 +1150,9 @@ def add_page(
11501150 def apply_instant_json (
11511151 self ,
11521152 input_file : FileInput ,
1153- instant_json : FileInput | str ,
1154- output_path : str | None = None ,
1155- ) -> bytes | None :
1153+ instant_json : Union [ FileInput , str ] ,
1154+ output_path : Optional [ str ] = None ,
1155+ ) -> Optional [ bytes ] :
11561156 """Apply Nutrient Instant JSON annotations to a PDF.
11571157
11581158 Applies annotations from a Nutrient Instant JSON file or URL to a PDF.
@@ -1242,9 +1242,9 @@ def apply_instant_json(
12421242 def apply_xfdf (
12431243 self ,
12441244 input_file : FileInput ,
1245- xfdf : FileInput | str ,
1246- output_path : str | None = None ,
1247- ) -> bytes | None :
1245+ xfdf : Union [ FileInput , str ] ,
1246+ output_path : Optional [ str ] = None ,
1247+ ) -> Optional [ bytes ] :
12481248 """Apply XFDF annotations to a PDF.
12491249
12501250 Applies annotations from an XFDF (XML Forms Data Format) file or URL
@@ -1332,8 +1332,8 @@ def set_page_label(
13321332 self ,
13331333 input_file : FileInput ,
13341334 labels : list [dict [str , Any ]],
1335- output_path : str | None = None ,
1336- ) -> bytes | None :
1335+ output_path : Optional [ str ] = None ,
1336+ ) -> Optional [ bytes ] :
13371337 """Set labels for specific pages in a PDF.
13381338
13391339 Assigns custom labels/numbering to specific page ranges in a PDF document.
0 commit comments