def fix_rotation
      return self if self[:Rotate].to_f == 0.0 || mediabox.nil?
      # calculate the rotation
      r = (360.0 - self[:Rotate].to_f) * Math::PI / 180
      s = Math.sin(r).round 6
      c = Math.cos(r).round 6
      ctm = [c, s, -s, c]
      # calculate the translation (move the origin of x,y to the new origin).
      x = mediabox[2] - mediabox[0]
      y = mediabox[3] - mediabox[1]
      ctm.push(((x * c).abs - x * c + (y * s).abs + y * s) / 2, ((x * s).abs - x * s + (y * c).abs - y * c) / 2)

      # insert the rotation stream into the current content stream
      insert_content "q\n#{ctm.join ' '} cm\n", 0
      # close the rotation stream
      insert_content CONTENT_CONTAINER_END
      # reset the mediabox and cropbox values - THIS IS ONLY FOR ORIENTATION CHANGE...
      if (self[:Rotate].to_f / 90).to_i.odd?
        self[:MediaBox] = self[:MediaBox].values_at(1, 0, 3, 2)
        self[:CropBox] = self[:CropBox].values_at(1, 0, 3, 2) if self[:CropBox]
      end
      # reset the Rotate property
      delete :Rotate
      # disconnect the content stream, so that future inserts aren't rotated
      @contents = false # init_contents

      # always return self, for chaining.
      self
    end
def fix_rotation
      return self if self[:Rotate].to_f == 0.0 || mediabox.nil?
      # calculate the rotation
      r = (360.0 - self[:Rotate].to_f) * Math::PI / 180
      s = Math.sin(r).round 6
      c = Math.cos(r).round 6
      ctm = [c, s, -s, c]
      # calculate the translation (move the origin of x,y to the new origin).
      x = mediabox[2] - mediabox[0]
      y = mediabox[3] - mediabox[1]
      ctm.push(((x * c).abs - x * c + (y * s).abs + y * s) / 2, ((x * s).abs - x * s + (y * c).abs - y * c) / 2)

      # insert the rotation stream into the current content stream
      insert_content "q\n#{ctm.join ' '} cm\n", 0
      # close the rotation stream
      insert_content CONTENT_CONTAINER_END
      # reset the mediabox and cropbox values - THIS IS ONLY FOR ORIENTATION CHANGE...
      if (self[:Rotate].to_f / 90).to_i.odd?
        self[:MediaBox] = self[:MediaBox].values_at(1, 0, 3, 2)
        self[:CropBox] = self[:CropBox].values_at(1, 0, 3, 2) if self[:CropBox]
      end
      # reset the Rotate property
      delete :Rotate
      # disconnect the content stream, so that future inserts aren't rotated
      @contents = false # init_contents

      # always return self, for chaining.
      self
    end
This method moves the Page[:Rotate] property into the page's data stream, so that
 "what you see is what you get".

 After using thie method, {#orientation} should return the absolute orientation rather than only the data's orientation (unless `:Rotate` is changed).

 This is usful in cases where there might be less control over the source PDF files,
 and the user assums that the PDF page's data is the same as the PDF's pages
 on screen display (Rotate rotates a page but leaves the data in the original orientation).

 The method returns the page object, thus allowing method chaining (i.e. `page[:Rotate] = 90; page.textbox('hello!').fix_rotation.textbox('hello!')`)