@@ -478,7 +478,8 @@ def optimize_pdf(
478478 grayscale_annotations: Convert annotations to grayscale (default: False).
479479 disable_images: Remove all images from the PDF (default: False).
480480 mrc_compression: MCR compression (default: False).
481- image_optimization_quality: Image optimization quality from 1 (least optimized) to 4 (most optimized) (default: 2).
481+ image_optimization_quality: Image optimization quality from 1 (least optimized)
482+ to 4 (most optimized) (default: 2).
482483 linearize: Linearize (optimize for web viewing) the PDF (default: False).
483484
484485 Returns:
@@ -487,7 +488,8 @@ def optimize_pdf(
487488 Raises:
488489 AuthenticationError: If API key is missing or invalid.
489490 APIError: For other API errors.
490- ValueError: If image_optimization_quality is not between 1-4 or no optimization is enabled
491+ ValueError: If image_optimization_quality is not between 1-4
492+ or no optimization is enabled
491493
492494 Example:
493495 # Aggressive optimization for minimum file size
@@ -709,7 +711,11 @@ def split_pdf(
709711 output_paths=["part1.pdf", "part2.pdf"]
710712 )
711713 """
712- from nutrient_dws .file_handler import prepare_file_for_upload , save_file_output , get_pdf_page_count
714+ from nutrient_dws .file_handler import (
715+ get_pdf_page_count ,
716+ prepare_file_for_upload ,
717+ save_file_output ,
718+ )
713719
714720 # Validate inputs
715721 if not page_ranges :
@@ -731,15 +737,21 @@ def split_pdf(
731737
732738 # Validate start is within document bounds
733739 if start < 0 or start >= num_of_pages :
734- raise ValueError (f"Page range { i } : start index { start } is out of bounds (0-{ num_of_pages - 1 } )" )
740+ raise ValueError (
741+ f"Page range { i } : start index { start } is out of bounds (0-{ num_of_pages - 1 } )"
742+ )
735743
736744 # If end is specified, validate it's within document bounds
737745 if "end" in page_range :
738746 end = page_range ["end" ]
739747 if end < 0 or end >= num_of_pages :
740- raise ValueError (f"Page range { i } : end index { end } is out of bounds (0-{ num_of_pages - 1 } )" )
748+ raise ValueError (
749+ f"Page range { i } : end index { end } is out of bounds (0-{ num_of_pages - 1 } )"
750+ )
741751 if end < start :
742- raise ValueError (f"Page range { i } : end index { end } cannot be less than start index { start } " )
752+ raise ValueError (
753+ f"Page range { i } : end index { end } cannot be less than start index { start } "
754+ )
743755
744756 results = []
745757
@@ -814,7 +826,11 @@ def duplicate_pdf_pages(
814826 output_path="reordered.pdf"
815827 )
816828 """
817- from nutrient_dws .file_handler import prepare_file_for_upload , save_file_output , get_pdf_page_count
829+ from nutrient_dws .file_handler import (
830+ get_pdf_page_count ,
831+ prepare_file_for_upload ,
832+ save_file_output ,
833+ )
818834
819835 # Validate inputs
820836 if not page_indexes :
@@ -837,7 +853,9 @@ def duplicate_pdf_pages(
837853 else :
838854 # Validate positive indexes are within bounds
839855 if page_index >= num_of_pages :
840- raise ValueError (f"Page index { page_index } is out of bounds (0-{ num_of_pages - 1 } )" )
856+ raise ValueError (
857+ f"Page index { page_index } is out of bounds (0-{ num_of_pages - 1 } )"
858+ )
841859 # For positive indexes, create single-page range
842860 parts .append ({"file" : "file" , "pages" : {"start" : page_index , "end" : page_index }})
843861
@@ -905,7 +923,11 @@ def delete_pdf_pages(
905923 output_path="pages_deleted.pdf"
906924 )
907925 """
908- from nutrient_dws .file_handler import prepare_file_for_upload , save_file_output , get_pdf_page_count
926+ from nutrient_dws .file_handler import (
927+ get_pdf_page_count ,
928+ prepare_file_for_upload ,
929+ save_file_output ,
930+ )
909931
910932 # Validate inputs
911933 if not page_indexes :
@@ -924,7 +946,7 @@ def delete_pdf_pages(
924946 # Validate page indexes are within bounds
925947 for idx in page_indexes :
926948 if idx >= num_of_pages :
927- raise ValueError (f"Page index { idx } is out of bounds (0-{ num_of_pages - 1 } )" )
949+ raise ValueError (f"Page index { idx } is out of bounds (0-{ num_of_pages - 1 } )" )
928950
929951 # Prepare file for upload
930952 file_field , file_data = prepare_file_for_upload (input_file , "file" )
@@ -952,7 +974,9 @@ def delete_pdf_pages(
952974
953975 # Add remaining pages after the last deleted page
954976 num_of_pages = get_pdf_page_count (input_file )
955- if (current_page > 0 or (current_page == 0 and len (sorted_indexes ) == 0 )) and current_page < num_of_pages :
977+ if (
978+ current_page > 0 or (current_page == 0 and len (sorted_indexes ) == 0 )
979+ ) and current_page < num_of_pages :
956980 # Add all remaining pages from current_page onwards
957981 parts .append ({"file" : "file" , "pages" : {"start" : current_page }})
958982
@@ -1098,7 +1122,11 @@ def add_page(
10981122 output_path="with_blank_pages.pdf"
10991123 )
11001124 """
1101- from nutrient_dws .file_handler import prepare_file_for_upload , save_file_output , get_pdf_page_count
1125+ from nutrient_dws .file_handler import (
1126+ get_pdf_page_count ,
1127+ prepare_file_for_upload ,
1128+ save_file_output ,
1129+ )
11021130
11031131 # Validate inputs
11041132 if page_count < 1 :
@@ -1394,7 +1422,11 @@ def set_page_label(
13941422 labels=[{"pages": {"start": 0, "end": 0}, "label": "Cover Page"}]
13951423 )
13961424 """
1397- from nutrient_dws .file_handler import prepare_file_for_upload , save_file_output , get_pdf_page_count
1425+ from nutrient_dws .file_handler import (
1426+ get_pdf_page_count ,
1427+ prepare_file_for_upload ,
1428+ save_file_output ,
1429+ )
13981430
13991431 # Validate inputs
14001432 if not labels :
@@ -1422,18 +1454,27 @@ def set_page_label(
14221454 # Validate start is within document bounds
14231455 start = pages ["start" ]
14241456 if start < 0 or start >= num_of_pages :
1425- raise ValueError (f"Label configuration { i } : start index { start } is out of bounds (0-{ num_of_pages - 1 } )" )
1457+ raise ValueError (
1458+ f"Label configuration { i } : start index { start } "
1459+ f" is out of bounds (0-{ num_of_pages - 1 } )"
1460+ )
14261461
14271462 # Normalize pages - only include 'end' if explicitly provided
14281463 normalized_pages = {"start" : start }
14291464 if "end" in pages :
14301465 end = pages ["end" ]
14311466 # Validate end is within document bounds
14321467 if end < 0 or end >= num_of_pages :
1433- raise ValueError (f"Label configuration { i } : end index { end } is out of bounds (0-{ num_of_pages - 1 } )" )
1468+ raise ValueError (
1469+ f"Label configuration { i } : end index { end } "
1470+ f" is out of bounds (0-{ num_of_pages - 1 } )"
1471+ )
14341472 # Validate end is not less than start
14351473 if end < start :
1436- raise ValueError (f"Label configuration { i } : end index { end } cannot be less than start index { start } " )
1474+ raise ValueError (
1475+ f"Label configuration { i } : end index { end } "
1476+ f" cannot be less than start index { start } "
1477+ )
14371478 normalized_pages ["end" ] = end
14381479 # If no end is specified, leave it out (meaning "to end of document")
14391480
0 commit comments