Spaces:
Sleeping
Sleeping
Update Counting_Columns_2_1.py
Browse files- Counting_Columns_2_1.py +7 -2
Counting_Columns_2_1.py
CHANGED
|
@@ -171,19 +171,24 @@ def generate_legend(found_tuple):
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
# Create a new PDF document
|
| 176 |
pdf_document = fitz.open('pdf',pdf_name)
|
| 177 |
page=pdf_document[0]
|
| 178 |
for i in range(len(slctd_clm)):
|
| 179 |
x, y = slctd_clm[i]
|
|
|
|
| 180 |
text = columns_types_v[i]
|
| 181 |
# Create an annotation (sticky note)
|
| 182 |
annot = page.add_text_annot((x, y), text)
|
| 183 |
annot.set_border(width=0.2, dashes=(1, 2)) # Optional border styling
|
| 184 |
annot.set_colors(stroke=(1, 0, 0), fill=None) # Set the stroke color to red
|
| 185 |
annot.update()
|
| 186 |
-
page.set_rotation(
|
| 187 |
return pdf_document
|
| 188 |
|
| 189 |
def mainfun(pdf_name,pdfpath,planname):
|
|
|
|
| 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 |
+
rotationOld=page.rotation
|
| 175 |
+
derotationMatrix=page.derotation_matrix
|
| 176 |
+
if page.rotation!=0:
|
| 177 |
+
rotationangle = page.rotation
|
| 178 |
+
page.set_rotation(0)
|
| 179 |
# Create a new PDF document
|
| 180 |
pdf_document = fitz.open('pdf',pdf_name)
|
| 181 |
page=pdf_document[0]
|
| 182 |
for i in range(len(slctd_clm)):
|
| 183 |
x, y = slctd_clm[i]
|
| 184 |
+
p_midpoint = fitz.Point(x, y) * derotationMatrix
|
| 185 |
text = columns_types_v[i]
|
| 186 |
# Create an annotation (sticky note)
|
| 187 |
annot = page.add_text_annot((x, y), text)
|
| 188 |
annot.set_border(width=0.2, dashes=(1, 2)) # Optional border styling
|
| 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):
|