rotate pdf
This commit is contained in:
@@ -17,6 +17,7 @@ module Submissions
|
|||||||
|
|
||||||
TEXT_LEFT_MARGIN = 1
|
TEXT_LEFT_MARGIN = 1
|
||||||
TEXT_TOP_MARGIN = 1
|
TEXT_TOP_MARGIN = 1
|
||||||
|
MAX_PAGE_ROTATE = 20
|
||||||
|
|
||||||
A4_SIZE = [595, 842].freeze
|
A4_SIZE = [595, 842].freeze
|
||||||
SUPPORTED_IMAGE_TYPES = ['image/png', 'image/jpeg'].freeze
|
SUPPORTED_IMAGE_TYPES = ['image/png', 'image/jpeg'].freeze
|
||||||
@@ -350,6 +351,8 @@ module Submissions
|
|||||||
HexaPDF::Document.new(io: StringIO.new(attachment.download))
|
HexaPDF::Document.new(io: StringIO.new(attachment.download))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pdf = maybe_rotate_pdf(pdf)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
pdf.acro_form&.flatten
|
pdf.acro_form&.flatten
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
@@ -362,6 +365,26 @@ module Submissions
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def maybe_rotate_pdf(pdf)
|
||||||
|
return pdf if pdf.pages.size > MAX_PAGE_ROTATE
|
||||||
|
|
||||||
|
is_rotated = pdf.pages.filter_map do |page|
|
||||||
|
page.rotate(0, flatten: true) if page[:Rotate] != 0
|
||||||
|
end.present?
|
||||||
|
|
||||||
|
return pdf unless is_rotated
|
||||||
|
|
||||||
|
io = StringIO.new
|
||||||
|
|
||||||
|
pdf.write(io, incremental: false, validate: false)
|
||||||
|
|
||||||
|
HexaPDF::Document.new(io:)
|
||||||
|
rescue StandardError => e
|
||||||
|
Rollbar.error(e) if defined?(Rollbar)
|
||||||
|
|
||||||
|
pdf
|
||||||
|
end
|
||||||
|
|
||||||
def on_missing_glyph(character, font_wrapper)
|
def on_missing_glyph(character, font_wrapper)
|
||||||
Rollbar.error("Missing glyph: #{character}") if character.present? && defined?(Rollbar)
|
Rollbar.error("Missing glyph: #{character}") if character.present? && defined?(Rollbar)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user