-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ilovepdf/feature/signature/add-signature-…
…form-methods Updated signature tool with PDF Forms
- Loading branch information
Showing
10 changed files
with
191 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Ilovepdf | ||
module ExtraUploadParams | ||
class Base | ||
attr_accessor :extra_params | ||
|
||
def set_value(key,value) | ||
self.extra_params||= {} | ||
self.extra_params[key] = value | ||
end | ||
|
||
def get_values() | ||
self.extra_params | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'ilovepdf/extra_upload_params/base' | ||
module Ilovepdf | ||
module ExtraUploadParams | ||
|
||
class Signature < Base | ||
|
||
def set_pdf_info(activate = true) | ||
self.set_value(:pdfinfo,!!activate ? "1" : "0") | ||
self | ||
end | ||
|
||
def set_pdf_forms(activate = true) | ||
is_active = !!activate | ||
self.set_value(:pdfforms,is_active ? "1" : "0") | ||
if is_active | ||
self.set_pdf_info(true) | ||
end | ||
self | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Ilovepdf | ||
class PdfPage | ||
attr_accessor :width,:height | ||
|
||
def initialize(width, height) | ||
self.width = width | ||
self.height = height | ||
end | ||
|
||
def self.initialize_from_string(string) | ||
width, height = string.split("x").map(&:to_f) | ||
PdfPage.new(width, height) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Ilovepdf | ||
VERSION = "1.3.4" | ||
VERSION = "1.4.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ | |
priv_key = "YOUR_PRIVATE_KEY" | ||
|
||
my_task = Ilovepdf::Tool::Signature.new(pub_key, priv_key) | ||
my_task.add_brand(name: "my company name",logo: "/path/to/logo/logo.png") | ||
# Upload brand logo | ||
brand_logo = my_task.upload_brand_logo_file("/path/to/logo/logo.png") | ||
my_task.add_brand(name: "my company name",logo: brand_logo) | ||
my_task.language = "es" | ||
my_task.lock_order = false # if false, allows receivers of signer type to sign in parallel. | ||
# if true receivers of signer type must sign sequentially in order. | ||
|
@@ -23,7 +25,6 @@ | |
|
||
signer = Ilovepdf::Signature::Receiver.new(:signer,'name','[email protected]') | ||
signer.phone = "34677231431" #Phone number with the country prefix at the beginning => "+34677231431", make sure you have enough credits. | ||
signer.phone = "34677231431" #Phone number with the country prefix at the beginning => "+34677231431", make sure you have enough credits. | ||
|
||
signature_element = Ilovepdf::Signature::SignatureElement.new(file1) | ||
signature_element.set_position(x: 20,y: -20) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require "bundler/setup" | ||
require 'ilovepdf' | ||
|
||
# You can call task class directly | ||
pub_key = "YOUR_PUBLIC_KEY" | ||
priv_key = "YOUR_PRIVATE_KEY" | ||
my_task = Ilovepdf::Tool::Signature.new(pub_key, priv_key) | ||
|
||
# Send additional parameters to obtain the information about the PDF and the information about the form elements | ||
extra_params = Ilovepdf::ExtraUploadParams::Signature.new | ||
extra_params.set_pdf_forms(true).set_pdf_info(true) | ||
file = my_task.add_file('/path/to/file/sample.pdf',extra_params) | ||
|
||
# Define the signer | ||
signer = Ilovepdf::Signature::Receiver.new(:signer,'name','[email protected]') | ||
|
||
# Get number of pages | ||
file.pdf_page_number | ||
# get specific pdf page | ||
pdf_page = file.pdf_page_info(1) | ||
puts pdf_page.width | ||
puts pdf_page.height | ||
|
||
# Now we can loop over all of the form elements on the PDF | ||
file.each_pdf_form_element do |form_element, pdf_page_info| | ||
type_of_field = form_element["typeOfField"] | ||
next unless ["textbox", "signature"].include?(type_of_field) | ||
|
||
field_id = form_element["fieldId"] | ||
widgets = form_element["widgetsInformation"] | ||
position = widgets[0] | ||
current_page = position["page"] | ||
|
||
left_pos = position["left"] | ||
top_position = position["top"] - pdf_page_info["height"] | ||
size = (position["left"] - position["bottom"]).floor | ||
|
||
if type_of_field == "textbox" | ||
if form_element["multilineFlag"] || form_element["passwordFlag"] | ||
next | ||
end | ||
|
||
text_value = form_element["textValue"] | ||
# For instance, we want to create an input element if the label of the form contains the word "Input". | ||
if field_id.include?('_input') | ||
input_element = ElementInput.new | ||
input_element.set_position(left_pos, top_position) | ||
.set_size(size) | ||
.set_label(text_value) | ||
.set_pages(current_page.to_s) | ||
elements << input_element | ||
else | ||
text_element = ElementText.new | ||
text_element.set_position(left_pos, top_position) | ||
.set_size(size) | ||
.set_text(text_value) | ||
.set_pages(current_page.to_s) | ||
elements << text_element | ||
end | ||
elsif type_of_field == "signature" | ||
signature_element = ElementSignature.new | ||
signature_element.set_position(left_pos, top_position) | ||
.set_size(size) | ||
elements << signature_element | ||
end | ||
end | ||
|
||
|