Closed waterfallmouse closed 1 year ago
Yes, rotating the annotations is not yet implemented. Annotations have several flags that need to be taken into account when rotating them or the page they are on. It also depends on how you rotate the page.
Could you provide a sample PDF and what you would expect when rotating a page?
@gettalong Thank you for your reply.
I cannot provide it because it is a PDF file that has an NDA with the customer.
What I want to do is rotate the position of the annotation as well. Please refer to the following countermeasures.
pdf_page.rotate(0, flatten: true)
if (annots = pdf_page[:Annots])
annots.each do |annot|
box = annot[:Rect]
matrix, llx, lly, urx, ury = \
case angle
when 90
[HexaPDF::Content::TransformationMatrix.new(0, -1, 1, 0), box.right, box.bottom, box.left, box.top]
when 180
[HexaPDF::Content::TransformationMatrix.new(-1, 0, 0, -1), box.right, box.top, box.left, box.bottom]
when 270
[HexaPDF::Content::TransformationMatrix.new(0, 1, -1, 0), box.left, box.top, box.right, box.bottom]
end
end
box.value = matrix.evaluate(llx, lly).concat(matrix.evaluate(urx, ury))
end
@waterfallmouse That might work in some cases but not all. As I said, rotation of annotations also depends on certain annotation flags.
@waterfallmouse Could you create a sample PDF that shows what is going wrong and share that?
@waterfallmouse Rotating a page when using flattening now works for annotations, too. So with the next release of HexaPDF you won't need the work-around anymore. Also see https://github.com/gettalong/hexapdf/issues/215#issuecomment-1356826310
@gettalong Thank you for your response! When is the next release scheduled?
Some time this week before the new year.
After rotating a PDF with annotations, the annotations are not highlighted when viewing the PDF.
The cause is that annotations cannot be taken into account during rotation. https://github.com/gettalong/hexapdf/blob/b9e194418b3b1bf89d6842e264dbff1c348c1332/lib/hexapdf/type/page.rb#L287
Wouldn't it be better to put
[:Annots]
in this array? For:Annots
, I think it's necessary to specify, so I know it's not easy.