Spaces:
Sleeping
Sleeping
Update Counting_Columns_2_1.py
Browse files- Counting_Columns_2_1.py +31 -1
Counting_Columns_2_1.py
CHANGED
|
@@ -168,7 +168,7 @@ def generate_legend(found_tuple):
|
|
| 168 |
df = pd.DataFrame(data.items(), columns=['Column Type', 'Count'])
|
| 169 |
return df
|
| 170 |
|
| 171 |
-
def add_annotations_to_pdf(image, pdf_name, slctd_clm, columns_types_v):
|
| 172 |
image_width = image.shape[1]
|
| 173 |
image_height = image.shape[0]
|
| 174 |
# Create a new PDF document
|
|
@@ -189,6 +189,36 @@ def add_annotations_to_pdf(image, pdf_name, slctd_clm, columns_types_v):
|
|
| 189 |
annot.set_colors(stroke=(1, 0, 0), fill=None) # Set the stroke color to red
|
| 190 |
annot.update()
|
| 191 |
page.set_rotation(rotationOld)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
return pdf_document
|
| 193 |
|
| 194 |
def mainfun(pdf_name,pdfpath,planname):
|
|
|
|
| 168 |
df = pd.DataFrame(data.items(), columns=['Column Type', 'Count'])
|
| 169 |
return df
|
| 170 |
|
| 171 |
+
'''def add_annotations_to_pdf(image, pdf_name, slctd_clm, columns_types_v):
|
| 172 |
image_width = image.shape[1]
|
| 173 |
image_height = image.shape[0]
|
| 174 |
# Create a new PDF document
|
|
|
|
| 189 |
annot.set_colors(stroke=(1, 0, 0), fill=None) # Set the stroke color to red
|
| 190 |
annot.update()
|
| 191 |
page.set_rotation(rotationOld)
|
| 192 |
+
return pdf_document'''
|
| 193 |
+
|
| 194 |
+
def add_annotations_to_pdf(image, pdf_name, slctd_clm, columns_types_v):
|
| 195 |
+
image_width = image.shape[1]
|
| 196 |
+
image_height = image.shape[0]
|
| 197 |
+
# Create a new PDF document
|
| 198 |
+
pdf_document = fitz.open('pdf',pdf_name)
|
| 199 |
+
page=pdf_document[0]
|
| 200 |
+
rotationOld=page.rotation
|
| 201 |
+
derotationMatrix=page.derotation_matrix
|
| 202 |
+
if page.rotation!=0:
|
| 203 |
+
rotationangle = page.rotation
|
| 204 |
+
page.set_rotation(0)
|
| 205 |
+
for i in range(len(slctd_clm)):
|
| 206 |
+
x, y = slctd_clm[i]
|
| 207 |
+
p_midpoint = fitz.Point(x, y) * derotationMatrix
|
| 208 |
+
annot = page.add_circle_annot(
|
| 209 |
+
fitz.Rect(x - 10, y - 10, x + 10,y + 10) # Small circle
|
| 210 |
+
)
|
| 211 |
+
# ✅ Assign required Bluebeam metadata
|
| 212 |
+
annot.set_colors(stroke=(1, 0, 0), fill=(1, 1, 1)) # Set stroke color and fill white
|
| 213 |
+
annot.set_border(width=2) # Border thickness
|
| 214 |
+
annot.set_opacity(1) # Fully visible
|
| 215 |
+
text = columns_types_v[i]
|
| 216 |
+
# ✅ Set annotation properties for Bluebeam Count detection
|
| 217 |
+
annot.set_info("name", text) # Unique name for each count
|
| 218 |
+
annot.set_info("subject", "Count") # ✅ Bluebeam uses "Count" for Count markups
|
| 219 |
+
annot.set_info("title", text) # Optional
|
| 220 |
+
annot.update() # Apply changes
|
| 221 |
+
page.set_rotation(rotationOld)
|
| 222 |
return pdf_document
|
| 223 |
|
| 224 |
def mainfun(pdf_name,pdfpath,planname):
|