I'm extracting all the characters and their coordinates from an existing document and trying to duplicate it. I am inserting these characters according to their coordinates in a new document, however, they are slightly out of place. They are shifted slightly up (and sometimes down) and partially to the right, which leads to the gluing of words.
If I use the standard method with Rectangle, then all characters are shifted slightly up (or down) by 1-2 absolute coordinates.
for i, s in enumerate(symb_arr[p]):
r: Rectangle = Rectangle(
Decimal(s.x_coord), # x
Decimal(s.y_coord), # y
Decimal(s.width), # width
Decimal(s.height), # height
)
Paragraph(s.symbol, font_size=Decimal(s.font_size), font=custom_font).paint(page, r)
if i == 0:
page.add_annotation(SquareAnnotation(r, stroke_color=HexColor("#ff0000")))
Where symb_arr
it is an array of characters. With this method, all characters are shifted up or down (I don't understand what it depends on).
The picture shows a fragment of a PDF file in which I drew a Rectangle object with the coordinates where the symbol 'B' should be and the symbol 'B' itself, which is located below. I have tried various types of alignment, but none gives the result that the symbol is in its place.
It seems to me that this is due to the fact that the symbol has its coordinates inside a Rectangle or Paragraph, but after digging into the files where they are defined, I couldn't really figure it out.
However, if you use the Tj operator, this problem disappears, but another one remains - the horizontal displacement of characters. This can be seen in the picture below:
This shift occurs in both character insertion methods and on each line of text at about 45-55 characters. I do not do any manipulations with changing the coordinates of the symbols, I insert them where they were originally. What could be the reason for such a problem?