seanpedrickcase commited on
Commit
928b1e9
·
1 Parent(s): 23f8ca3

Can now toggle colour change for boxes. Large boxes now remove text correctly

Browse files
Files changed (1) hide show
  1. tools/file_redaction.py +12 -8
tools/file_redaction.py CHANGED
@@ -578,7 +578,7 @@ def move_page_info(file_path: str) -> str:
578
 
579
  return new_file_path
580
 
581
- def redact_page_with_pymupdf(page:Page, annotations_on_page, image = None):
582
 
583
  mediabox_height = page.mediabox[3] - page.mediabox[1]
584
  mediabox_width = page.mediabox[2] - page.mediabox[0]
@@ -671,8 +671,8 @@ def redact_page_with_pymupdf(page:Page, annotations_on_page, image = None):
671
 
672
  # Calculate the middle y value and set a small height (not used)
673
  #print("Rect:", rect)
674
- middle_y = (pymupdf_y1 + pymupdf_y2) / 2
675
- rect_small_pixel_height = Rect(pymupdf_x1, middle_y - 2, pymupdf_x2, middle_y + 2) # Small height in middle of line
676
 
677
  # Add the annotation to the middle of the character line, so that it doesn't delete text from adjacent lines
678
  #page.add_redact_annot(rect)#rect_small_pixel_height)
@@ -682,13 +682,17 @@ def redact_page_with_pymupdf(page:Page, annotations_on_page, image = None):
682
  shape = page.new_shape()
683
  shape.draw_rect(rect)
684
 
685
- def convert_color_to_range_0_1(color):
686
- return tuple(component / 255 for component in color)
687
 
688
- if img_annotation_box["color"][0] > 1:
689
- out_colour = convert_color_to_range_0_1(img_annotation_box["color"])
 
 
 
 
 
690
  else:
691
- out_colour = img_annotation_box["color"]
692
 
693
  shape.finish(color=out_colour, fill=out_colour) # Black fill for the rectangle
694
  #shape.finish(color=(0, 0, 0)) # Black fill for the rectangle
 
578
 
579
  return new_file_path
580
 
581
+ def redact_page_with_pymupdf(page:Page, annotations_on_page, image = None, custom_colours=False):
582
 
583
  mediabox_height = page.mediabox[3] - page.mediabox[1]
584
  mediabox_width = page.mediabox[2] - page.mediabox[0]
 
671
 
672
  # Calculate the middle y value and set a small height (not used)
673
  #print("Rect:", rect)
674
+ #middle_y = (pymupdf_y1 + pymupdf_y2) / 2
675
+ rect_small_pixel_height = Rect(pymupdf_x1, pymupdf_y1 + 2, pymupdf_x2, pymupdf_y2 - 2) # Slightly smaller than outside box
676
 
677
  # Add the annotation to the middle of the character line, so that it doesn't delete text from adjacent lines
678
  #page.add_redact_annot(rect)#rect_small_pixel_height)
 
682
  shape = page.new_shape()
683
  shape.draw_rect(rect)
684
 
685
+ if custom_colours == True:
 
686
 
687
+ def convert_color_to_range_0_1(color):
688
+ return tuple(component / 255 for component in color)
689
+
690
+ if img_annotation_box["color"][0] > 1:
691
+ out_colour = convert_color_to_range_0_1(img_annotation_box["color"])
692
+ else:
693
+ out_colour = img_annotation_box["color"]
694
  else:
695
+ out_colour = (0,0,0)
696
 
697
  shape.finish(color=out_colour, fill=out_colour) # Black fill for the rectangle
698
  #shape.finish(color=(0, 0, 0)) # Black fill for the rectangle