mirror of
https://github.com/docusealco/docuseal
synced 2026-11-04 06:42:32 -05:00
raw page size
This commit is contained in:
1 parent
9ad281d457
commit
887d80f6d7
2 files changed
+29
-4
No files matched your search
@@ -105,6 +105,7 @@ class Pdfium
|
||||
attach_function :FPDF_LoadCustomDocument, %i[pointer FPDF_STRING], :FPDF_DOCUMENT
|
||||
attach_function :FPDF_CloseDocument, [:FPDF_DOCUMENT], :void
|
||||
attach_function :FPDF_GetPageCount, [:FPDF_DOCUMENT], :int
|
||||
attach_function :FPDF_GetPageSizeByIndexF, %i[FPDF_DOCUMENT int pointer], :int
|
||||
attach_function :FPDF_GetLastError, [], :ulong
|
||||
attach_function :FPDF_GetTrailerEnds, %i[FPDF_DOCUMENT pointer ulong], :ulong
|
||||
attach_function :FPDF_DocumentHasValidCrossReferenceTable, [:FPDF_DOCUMENT], :int
|
||||
@@ -282,6 +283,7 @@ class Pdfium
|
||||
attach_function :FPDFPage_GetAnnotCount, [:FPDF_PAGE], :int
|
||||
|
||||
attach_function :FPDFPage_GetAnnotCountRaw, %i[FPDF_DOCUMENT int], :int
|
||||
attach_function :FPDFPage_GetRotationRaw, %i[FPDF_DOCUMENT int], :int
|
||||
attach_function :FPDFPage_GetAnnot, %i[FPDF_PAGE int], :FPDF_ANNOTATION
|
||||
attach_function :FPDFPage_CloseAnnot, [:FPDF_ANNOTATION], :void
|
||||
attach_function :FPDFAnnot_GetSubtype, [:FPDF_ANNOTATION], :int
|
||||
@@ -368,6 +370,11 @@ class Pdfium
|
||||
:bottom, :float
|
||||
end
|
||||
|
||||
class FS_SIZEF < FFI::Struct
|
||||
layout :width, :float,
|
||||
:height, :float
|
||||
end
|
||||
|
||||
class FS_MATRIX < FFI::Struct
|
||||
layout :a, :float,
|
||||
:b, :float,
|
||||
@@ -531,6 +538,8 @@ class Pdfium
|
||||
|
||||
@pages = {}
|
||||
@annot_counts = {}
|
||||
@page_sizes = {}
|
||||
@page_rotations = {}
|
||||
@closed = false
|
||||
@source_buffer = source_buffer
|
||||
@form_handle = FFI::Pointer::NULL
|
||||
@@ -555,6 +564,23 @@ class Pdfium
|
||||
@page_count ||= Pdfium.FPDF_GetPageCount(@document_ptr)
|
||||
end
|
||||
|
||||
def page_size(page_index)
|
||||
@page_sizes[page_index] ||=
|
||||
begin
|
||||
size = Pdfium::FS_SIZEF.new
|
||||
|
||||
[size[:width], size[:height]] if Pdfium.FPDF_GetPageSizeByIndexF(@document_ptr, page_index, size) == 1
|
||||
end
|
||||
end
|
||||
|
||||
def reset_page_size(page_index)
|
||||
@page_sizes.delete(page_index)
|
||||
end
|
||||
|
||||
def page_rotation(page_index)
|
||||
@page_rotations[page_index] ||= Pdfium.FPDFPage_GetRotationRaw(@document_ptr, page_index)
|
||||
end
|
||||
|
||||
def encrypted?
|
||||
Pdfium.FPDF_GetSecurityHandlerRevision(@document_ptr) >= 0
|
||||
end
|
||||
@@ -983,6 +1009,8 @@ class Pdfium
|
||||
def rotation=(value)
|
||||
Pdfium.FPDFPage_SetRotation(@page_ptr, value)
|
||||
|
||||
@document.reset_page_size(@page_index)
|
||||
|
||||
@rotation = value
|
||||
end
|
||||
|
||||
|
||||
@@ -345,10 +345,7 @@ module Templates
|
||||
|
||||
uuid = pdf_ref['attachment_uuid']
|
||||
source = sources[[uuid, nil]] ||= open_or_build_pdf(attachments_index[uuid])
|
||||
page = source.get_page(pdf_ref['page'])
|
||||
|
||||
width = page.width
|
||||
height = page.height
|
||||
width, height = source.page_size(pdf_ref['page'])
|
||||
|
||||
width, height = height, width unless (pdf_ref['rotate'].to_i % 180).zero?
|
||||
|
||||
|
||||
Reference in new issue
Block a user