Spaces:
Sleeping
Sleeping
Update Counting_Columns_2_1.py
Browse files- Counting_Columns_2_1.py +20 -1
Counting_Columns_2_1.py
CHANGED
|
@@ -167,6 +167,23 @@ def generate_legend(found_tuple):
|
|
| 167 |
df = pd.DataFrame(data.items(), columns=['Column Type', 'Count'])
|
| 168 |
return df
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
def mainfun(plan):
|
| 171 |
pdf_document = fitz.open(plan)
|
| 172 |
page = pdf_document[0]
|
|
@@ -199,7 +216,9 @@ def mainfun(plan):
|
|
| 199 |
nearby, slctd_clm = getNearestText(text_points, column_points)
|
| 200 |
columns_types_v = getColumnsTypesKeyValue(nearby, txtpts_ky_vlu)
|
| 201 |
legend = generate_legend(columns_types_v)
|
| 202 |
-
|
|
|
|
|
|
|
| 203 |
|
| 204 |
'''def mainfun(plan):
|
| 205 |
texts_from_pdf = get_text_from_pdf(plan)
|
|
|
|
| 167 |
df = pd.DataFrame(data.items(), columns=['Column Type', 'Count'])
|
| 168 |
return df
|
| 169 |
|
| 170 |
+
def add_annotations_to_pdf(image, pdf_name, slctd_clm, columns_types_v):
|
| 171 |
+
image_width, image_height = image.size
|
| 172 |
+
|
| 173 |
+
# Create a new PDF document
|
| 174 |
+
pdf_document = fitz.open('pdf',pdf_name)
|
| 175 |
+
page=pdf_document[0]
|
| 176 |
+
for i in range(len(slctd_clm)):
|
| 177 |
+
x, y = slctd_clm[i]
|
| 178 |
+
text = columns_types_v[i]
|
| 179 |
+
# Create an annotation (sticky note)
|
| 180 |
+
annot = page.add_text_annot((x, y), text)
|
| 181 |
+
annot.set_border(width=0.2, dashes=(1, 2)) # Optional border styling
|
| 182 |
+
annot.set_colors(stroke=(1, 0, 0), fill=None) # Set the stroke color to red
|
| 183 |
+
annot.update()
|
| 184 |
+
page.set_rotation(rotationOld)
|
| 185 |
+
return pdf_document
|
| 186 |
+
|
| 187 |
def mainfun(plan):
|
| 188 |
pdf_document = fitz.open(plan)
|
| 189 |
page = pdf_document[0]
|
|
|
|
| 216 |
nearby, slctd_clm = getNearestText(text_points, column_points)
|
| 217 |
columns_types_v = getColumnsTypesKeyValue(nearby, txtpts_ky_vlu)
|
| 218 |
legend = generate_legend(columns_types_v)
|
| 219 |
+
pdf_document = add_annotations_to_pdf(image, pdf_name, slctd_clm, columns_types_v)
|
| 220 |
+
|
| 221 |
+
return legend
|
| 222 |
|
| 223 |
'''def mainfun(plan):
|
| 224 |
texts_from_pdf = get_text_from_pdf(plan)
|