dynamicpdf_api 1.0.0.pre.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ruby_client/Action.rb +15 -0
- data/lib/ruby_client/AdditionalResource.rb +113 -0
- data/lib/ruby_client/AdditionalResourceType.rb +27 -0
- data/lib/ruby_client/Aes128Security.rb +70 -0
- data/lib/ruby_client/Aes256Security.rb +70 -0
- data/lib/ruby_client/Align.rb +21 -0
- data/lib/ruby_client/ButtonFieldInformation.rb +48 -0
- data/lib/ruby_client/ButtonFieldType.rb +16 -0
- data/lib/ruby_client/ChoiceFieldInformation.rb +52 -0
- data/lib/ruby_client/ChoiceFieldType.rb +16 -0
- data/lib/ruby_client/CmykColor.rb +47 -0
- data/lib/ruby_client/Color.rb +12 -0
- data/lib/ruby_client/ColorSpaceType.rb +36 -0
- data/lib/ruby_client/ConverterInput.rb +100 -0
- data/lib/ruby_client/DlexInput.rb +61 -0
- data/lib/ruby_client/DlexLayout.rb +135 -0
- data/lib/ruby_client/DlexResource.rb +40 -0
- data/lib/ruby_client/Elements/AztecBarcodeElement.rb +113 -0
- data/lib/ruby_client/Elements/AztecSymbolSize.rb +206 -0
- data/lib/ruby_client/Elements/BarcodeElement.rb +37 -0
- data/lib/ruby_client/Elements/Code11BarcodeElement.rb +77 -0
- data/lib/ruby_client/Elements/Code128BarcodeElement.rb +105 -0
- data/lib/ruby_client/Elements/Code25BarcodeElement.rb +75 -0
- data/lib/ruby_client/Elements/Code39BarcodeElement.rb +75 -0
- data/lib/ruby_client/Elements/Code93BarcodeElement.rb +75 -0
- data/lib/ruby_client/Elements/Compaction.rb +26 -0
- data/lib/ruby_client/Elements/DataMatrixBarcodeElement.rb +95 -0
- data/lib/ruby_client/Elements/DataMatrixEncodingType.rb +56 -0
- data/lib/ruby_client/Elements/DataMatrixFunctionCharacter.rb +31 -0
- data/lib/ruby_client/Elements/DataMatrixSymbolSize.rb +161 -0
- data/lib/ruby_client/Elements/Dim2BarcodeElement.rb +28 -0
- data/lib/ruby_client/Elements/Element.rb +46 -0
- data/lib/ruby_client/Elements/ElementPlacement.rb +36 -0
- data/lib/ruby_client/Elements/ElementType.rb +96 -0
- data/lib/ruby_client/Elements/ErrorCorrection.rb +56 -0
- data/lib/ruby_client/Elements/Gs1DataBarBarcodeElement.rb +76 -0
- data/lib/ruby_client/Elements/Gs1DataBarType.rb +22 -0
- data/lib/ruby_client/Elements/Iata25BarcodeElement.rb +83 -0
- data/lib/ruby_client/Elements/ImageElement.rb +108 -0
- data/lib/ruby_client/Elements/LineElement.rb +92 -0
- data/lib/ruby_client/Elements/MsiBarcodeCheckDigitMode.rb +31 -0
- data/lib/ruby_client/Elements/MsiBarcodeElement.rb +79 -0
- data/lib/ruby_client/Elements/PageNumberingElement.rb +91 -0
- data/lib/ruby_client/Elements/Pdf417BarcodeElement.rb +112 -0
- data/lib/ruby_client/Elements/QrCodeElement.rb +77 -0
- data/lib/ruby_client/Elements/QrCodeFnc1.rb +22 -0
- data/lib/ruby_client/Elements/RectangleElement.rb +109 -0
- data/lib/ruby_client/Elements/StackedGs1DataBarBarcodeElement.rb +90 -0
- data/lib/ruby_client/Elements/StackedGs1DataBarType.rb +23 -0
- data/lib/ruby_client/Elements/TextBarcodeElement.rb +48 -0
- data/lib/ruby_client/Elements/TextElement.rb +83 -0
- data/lib/ruby_client/Elements/ValueType.rb +16 -0
- data/lib/ruby_client/EncryptDocumentComponents.rb +16 -0
- data/lib/ruby_client/EndPointException.rb +7 -0
- data/lib/ruby_client/Endpoint.rb +38 -0
- data/lib/ruby_client/EndpointResource.rb +7 -0
- data/lib/ruby_client/ExcelInput.rb +49 -0
- data/lib/ruby_client/ExcelResource.rb +79 -0
- data/lib/ruby_client/Font.rb +276 -0
- data/lib/ruby_client/FontInformation.rb +9 -0
- data/lib/ruby_client/FontResource.rb +35 -0
- data/lib/ruby_client/FormField.rb +62 -0
- data/lib/ruby_client/FormFieldInformation.rb +45 -0
- data/lib/ruby_client/GoToAction.rb +53 -0
- data/lib/ruby_client/Grayscale.rb +41 -0
- data/lib/ruby_client/HtmlInput.rb +60 -0
- data/lib/ruby_client/HtmlResource.rb +34 -0
- data/lib/ruby_client/ImageInfo.rb +69 -0
- data/lib/ruby_client/ImageInformation.rb +57 -0
- data/lib/ruby_client/ImageInput.rb +150 -0
- data/lib/ruby_client/ImageResource.rb +89 -0
- data/lib/ruby_client/ImageResponse.rb +24 -0
- data/lib/ruby_client/Input.rb +53 -0
- data/lib/ruby_client/InputType.rb +41 -0
- data/lib/ruby_client/JsonResponse.rb +18 -0
- data/lib/ruby_client/LayoutDataResource.rb +48 -0
- data/lib/ruby_client/LineStyle.rb +79 -0
- data/lib/ruby_client/MergeOptions.rb +135 -0
- data/lib/ruby_client/MultiSelectListBoxInformation.rb +45 -0
- data/lib/ruby_client/Outline.rb +113 -0
- data/lib/ruby_client/OutlineList.rb +57 -0
- data/lib/ruby_client/OutlineStyle.rb +28 -0
- data/lib/ruby_client/OutputSize.rb +10 -0
- data/lib/ruby_client/PageInformation.rb +27 -0
- data/lib/ruby_client/PageInput.rb +152 -0
- data/lib/ruby_client/PageOrientation.rb +17 -0
- data/lib/ruby_client/PageSize.rb +127 -0
- data/lib/ruby_client/PageZoom.rb +33 -0
- data/lib/ruby_client/Pdf.rb +417 -0
- data/lib/ruby_client/PdfContent.rb +21 -0
- data/lib/ruby_client/PdfInfo.rb +68 -0
- data/lib/ruby_client/PdfInfoResponse.rb +27 -0
- data/lib/ruby_client/PdfInformation.rb +81 -0
- data/lib/ruby_client/PdfInput.rb +66 -0
- data/lib/ruby_client/PdfInstructions.rb +97 -0
- data/lib/ruby_client/PdfResource.rb +36 -0
- data/lib/ruby_client/PdfResponse.rb +23 -0
- data/lib/ruby_client/PdfText.rb +85 -0
- data/lib/ruby_client/PdfTextResponse.rb +27 -0
- data/lib/ruby_client/PdfXmp.rb +67 -0
- data/lib/ruby_client/PushButtonInformation.rb +21 -0
- data/lib/ruby_client/RC4128Security.rb +62 -0
- data/lib/ruby_client/Resource.rb +51 -0
- data/lib/ruby_client/ResourceType.rb +48 -0
- data/lib/ruby_client/Response.rb +39 -0
- data/lib/ruby_client/RgbColor.rb +1048 -0
- data/lib/ruby_client/Security.rb +73 -0
- data/lib/ruby_client/SecurityType.rb +23 -0
- data/lib/ruby_client/SignatureFieldInformation.rb +21 -0
- data/lib/ruby_client/Template.rb +46 -0
- data/lib/ruby_client/TextFieldInformation.rb +27 -0
- data/lib/ruby_client/TextReplace.rb +43 -0
- data/lib/ruby_client/UnitConverter.rb +111 -0
- data/lib/ruby_client/UrlAction.rb +31 -0
- data/lib/ruby_client/VAlign.rb +21 -0
- data/lib/ruby_client/WebColor.rb +18 -0
- data/lib/ruby_client/WordInput.rb +65 -0
- data/lib/ruby_client/WordResource.rb +82 -0
- data/lib/ruby_client/XmlResponse.rb +23 -0
- data/lib/ruby_client/version.rb +5 -0
- data/lib/ruby_client.rb +123 -0
- metadata +169 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative "Element"
|
3
|
+
require_relative "ElementType"
|
4
|
+
|
5
|
+
#
|
6
|
+
# Represents a text element.
|
7
|
+
#
|
8
|
+
# This class can be used to place text on a page.
|
9
|
+
#
|
10
|
+
class TextElement < Element
|
11
|
+
#
|
12
|
+
# Initializes a new instance of the TextElement class.
|
13
|
+
#
|
14
|
+
# @param value [String] Text to display in the text element.
|
15
|
+
# @param placement [String] The placement of the text element on the page.
|
16
|
+
# @param x_offset [float] X coordinate of the text element.
|
17
|
+
# @param y_offset [float] Y coordinate of the text element.
|
18
|
+
#
|
19
|
+
def initialize(value, placement = ElementPlacement::TOP_LEFT, x_offset = 0, y_offset = 0)
|
20
|
+
@_resource = nil
|
21
|
+
@_text_font = nil
|
22
|
+
@_font_name = nil
|
23
|
+
|
24
|
+
@color = nil
|
25
|
+
@font_size = nil
|
26
|
+
@_type = ElementType::TEXT
|
27
|
+
super(value, placement, x_offset, y_offset)
|
28
|
+
@text = value
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Gets or sets the Color object to use for the text of the text element.
|
33
|
+
#
|
34
|
+
attr_accessor :color
|
35
|
+
|
36
|
+
#
|
37
|
+
# Gets or sets the font size for the text of the text element.
|
38
|
+
#
|
39
|
+
attr_accessor :font_size
|
40
|
+
|
41
|
+
#
|
42
|
+
# Gets or sets the text to display in the text element.
|
43
|
+
#
|
44
|
+
attr_accessor :text
|
45
|
+
|
46
|
+
#
|
47
|
+
# Gets or sets the Font object used to specify the font of the text for the text element.
|
48
|
+
#
|
49
|
+
def font(value)
|
50
|
+
@_text_font = value
|
51
|
+
@_font_name = @_text_font._name
|
52
|
+
@_resource = @_text_font._resource
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_json(_options = {})
|
56
|
+
json_array = {}
|
57
|
+
|
58
|
+
json_array["type"] = "text"
|
59
|
+
|
60
|
+
json_array["font"] = @_font_name unless @_font_name.nil?
|
61
|
+
|
62
|
+
json_array["text"] = @text
|
63
|
+
|
64
|
+
json_array["color"] = @color._color_string if !@color.nil? && !@color._color_string.nil?
|
65
|
+
|
66
|
+
json_array["fontSize"] = @font_size unless @font_size.nil?
|
67
|
+
|
68
|
+
# ---------------------------------
|
69
|
+
|
70
|
+
json_array["placement"] = @placement unless @placement.nil?
|
71
|
+
|
72
|
+
json_array["xOffset"] = @x_offset unless @x_offset.nil?
|
73
|
+
|
74
|
+
json_array["yOffset"] = @y_offset unless @y_offset.nil?
|
75
|
+
|
76
|
+
json_array["evenPages"] = @even_pages unless @even_pages.nil?
|
77
|
+
|
78
|
+
json_array["oddPages"] = @odd_pages unless @odd_pages.nil?
|
79
|
+
|
80
|
+
JSON.pretty_generate(json_array)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
#
|
3
|
+
# Specifies the document components to be encrypted.
|
4
|
+
#
|
5
|
+
class EncryptDocumentComponents
|
6
|
+
#
|
7
|
+
# Encrypts all document contents.
|
8
|
+
#
|
9
|
+
ALL = 'all'
|
10
|
+
|
11
|
+
#
|
12
|
+
# Encrypts all document contents except metadata.
|
13
|
+
#
|
14
|
+
ALL_EXCEPT_METADATA = 'allExceptMetadata'
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
#
|
3
|
+
# Represents the base class for endpoint and has settings for base url, api key and creates a rest request
|
4
|
+
# object.
|
5
|
+
#
|
6
|
+
class Endpoint
|
7
|
+
def initialize
|
8
|
+
@_client = nil
|
9
|
+
@enable_logging = false
|
10
|
+
@api_key = @@default_api_key
|
11
|
+
@base_url = @@default_base_url
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :_endpoint_name
|
15
|
+
|
16
|
+
#
|
17
|
+
# Gets or sets default base url.
|
18
|
+
#
|
19
|
+
@@default_base_url = 'https://api.dynamicpdf.com'
|
20
|
+
|
21
|
+
#
|
22
|
+
# Gets or sets default api key.
|
23
|
+
#
|
24
|
+
@@default_api_key = nil
|
25
|
+
|
26
|
+
#
|
27
|
+
# Gets or sets base url for the api.
|
28
|
+
#
|
29
|
+
attr_accessor :base_url
|
30
|
+
|
31
|
+
#
|
32
|
+
# Gets or sets api key.
|
33
|
+
#
|
34
|
+
attr_accessor :api_key
|
35
|
+
|
36
|
+
def init; end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative "PageSize"
|
3
|
+
require_relative "PageOrientation"
|
4
|
+
require_relative "InputType"
|
5
|
+
#
|
6
|
+
# Represents a Excel input.
|
7
|
+
#
|
8
|
+
class ExcelInput < ConverterInput
|
9
|
+
|
10
|
+
#
|
11
|
+
# Initializes a new instance of the ExcelInput"/> class.
|
12
|
+
#
|
13
|
+
# @param name="resource">The resource of type ExcelResource.
|
14
|
+
# @param name="size">The page size of the output PDF.
|
15
|
+
# @param name="orientation">The page orientation of the output PDF.
|
16
|
+
# @param name="margins">The page margins of the output PDF.
|
17
|
+
def initialize(resource, size = PageSize::LETTER, orientation = PageOrientation::PORTRAIT, margins = nil)
|
18
|
+
super(resource, size, orientation, margins)
|
19
|
+
@_type = InputType::EXCEL
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_json(_options = {})
|
24
|
+
json_array = {}
|
25
|
+
|
26
|
+
json_array["type"] = "excel"
|
27
|
+
|
28
|
+
json_array["topMargin"] = @top_margin unless @top_margin.nil?
|
29
|
+
|
30
|
+
json_array["leftMargin"] = @left_margin unless @left_margin.nil?
|
31
|
+
|
32
|
+
json_array["bottomMargin"] = @bottom_margin unless @bottom_margin.nil?
|
33
|
+
|
34
|
+
json_array["rightMargin"] = @right_margin unless @right_margin.nil?
|
35
|
+
|
36
|
+
json_array["pageWidth"] = @page_width unless @page_width.nil?
|
37
|
+
|
38
|
+
json_array["pageHeight"] = @page_height unless @page_height.nil?
|
39
|
+
|
40
|
+
json_array["templateId"] = @_template_id unless @_template_id.nil?
|
41
|
+
|
42
|
+
json_array["resourceName"] = @resource_name unless @resource_name.nil?
|
43
|
+
|
44
|
+
json_array["id"] = @id unless @id.nil?
|
45
|
+
|
46
|
+
JSON.pretty_generate(json_array)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative "ResourceType"
|
3
|
+
#
|
4
|
+
# Represents a Excel resource.
|
5
|
+
#
|
6
|
+
class ExcelResource < Resource
|
7
|
+
|
8
|
+
#
|
9
|
+
# Initializes a new instance of the ExcelResource class.
|
10
|
+
#
|
11
|
+
# @param name="filePath">The Excel file path.
|
12
|
+
# @param name="resourceName">The The resource name with file extension.
|
13
|
+
def initialize(file, resourceName = nil)
|
14
|
+
@resource_name = nil
|
15
|
+
@file_extension = nil
|
16
|
+
super(file, resourceName)
|
17
|
+
|
18
|
+
@_type = ResourceType::EXCEL
|
19
|
+
@_mime_type = nil
|
20
|
+
super(file, resource_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Sets the resource name.
|
25
|
+
#
|
26
|
+
# @remarks The resource name should be specified with a file extension.
|
27
|
+
def resource_name=(value)
|
28
|
+
@resource_name = value
|
29
|
+
if (value == nil || File.extname(value) == nil)
|
30
|
+
raise "Invalid resource name."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_accessor :mime_type
|
35
|
+
|
36
|
+
def file_extension=(value)
|
37
|
+
@file_extension = value
|
38
|
+
inputFileExtension = ""
|
39
|
+
if (@resource_name != nil)
|
40
|
+
if (File.extname(value) != nil)
|
41
|
+
inputFileExtension = File.extname(value).ToLower
|
42
|
+
else
|
43
|
+
raise "Invalid resource name."
|
44
|
+
end
|
45
|
+
elsif (FilePath != nil)
|
46
|
+
if (File.extname(FilePath) != nil)
|
47
|
+
inputFileExtension = File.extname(FilePath).ToLower
|
48
|
+
else
|
49
|
+
raise "Invalid file path specified."
|
50
|
+
end
|
51
|
+
else
|
52
|
+
raise "Invalid file path or resource name."
|
53
|
+
end
|
54
|
+
|
55
|
+
if (inputFileExtension == ".xls")
|
56
|
+
@mime_type = "application/vnd.ms-excel"
|
57
|
+
".xls"
|
58
|
+
elsif (inputFileExtension == ".xlsx" && @data[0] == 0x50 && @data[1] == 0x4b)
|
59
|
+
@mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
60
|
+
".xlsx"
|
61
|
+
else
|
62
|
+
raise "Unsupported file type or invalid file extension."
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def SetMimeType()
|
67
|
+
|
68
|
+
# _ = FileExtension
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_json(_options = {})
|
72
|
+
json_array = {}
|
73
|
+
json_array["type"] = "excel"
|
74
|
+
|
75
|
+
json_array["resourceName"] = @resource_name
|
76
|
+
JSON.pretty_generate(json_array)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative "FontResource"
|
3
|
+
|
4
|
+
#
|
5
|
+
# Represents font.
|
6
|
+
#
|
7
|
+
class Font
|
8
|
+
#
|
9
|
+
# Initializes a new instance of the Font class using the font name that is present in the cloud resource
|
10
|
+
# manager.
|
11
|
+
#
|
12
|
+
# @param cloud_resource_name [String] The font name present in the cloud resource manager.
|
13
|
+
#
|
14
|
+
def initialize(cloud_resource_name = nil)
|
15
|
+
@data = {}
|
16
|
+
@_resource = nil
|
17
|
+
@embed = nil
|
18
|
+
@subset = nil
|
19
|
+
|
20
|
+
@resource_name = cloud_resource_name
|
21
|
+
@_name = SecureRandom.uuid
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.create_font(font_resource = nil, resource_name = nil)
|
25
|
+
font = Font.new
|
26
|
+
font._resource = font_resource
|
27
|
+
font.resource_name = resource_name
|
28
|
+
|
29
|
+
font._name = SecureRandom.uuid
|
30
|
+
font
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :_name, :_resource
|
34
|
+
|
35
|
+
#
|
36
|
+
# Gets or sets a boolean indicating whether to embed the font.
|
37
|
+
#
|
38
|
+
attr_accessor :embed
|
39
|
+
|
40
|
+
#
|
41
|
+
# Gets or sets a boolean indicating whether to subset embed the font.
|
42
|
+
#
|
43
|
+
attr_accessor :subset
|
44
|
+
|
45
|
+
#
|
46
|
+
# Gets or sets a name for the font resource.
|
47
|
+
#
|
48
|
+
attr_accessor :resource_name
|
49
|
+
|
50
|
+
#
|
51
|
+
# Gets the Times Roman core font with Latin 1 encoding.
|
52
|
+
#
|
53
|
+
def self.times_roman
|
54
|
+
@@times_roman = Font.new if @@times_roman.nil?
|
55
|
+
|
56
|
+
@@times_roman._name = "timesRoman"
|
57
|
+
@@times_roman
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Gets the Times Bold core font with Latin 1 encoding.
|
62
|
+
#
|
63
|
+
def self.times_bold
|
64
|
+
@@times_bold = Font.new if @@times_bold.nil?
|
65
|
+
|
66
|
+
@@times_bold._name = "timesBold"
|
67
|
+
@@times_bold
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Gets the Times Italic core font with Latin 1 encoding.
|
72
|
+
#
|
73
|
+
def self.times_italic
|
74
|
+
@@times_italic = Font.new if @@times_italic.nil?
|
75
|
+
|
76
|
+
@@times_italic._name = "timesItalic"
|
77
|
+
@@times_italic
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Gets the Times Bold Italic core font with Latin 1 encoding.
|
82
|
+
#
|
83
|
+
def self.times_bold_italic
|
84
|
+
@@times_bold_italic = Font.new if @@times_bold_italic.nil?
|
85
|
+
|
86
|
+
@@times_bold_italic._name = "timesBoldItalic"
|
87
|
+
@@times_bold_italic
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Gets the Helvetica core font with Latin 1 encoding.
|
92
|
+
#
|
93
|
+
def self.helvetica
|
94
|
+
@@helvetica = Font.new if @@helvetica.nil?
|
95
|
+
|
96
|
+
@@helvetica._name = "helvetica"
|
97
|
+
@@helvetica
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Gets the Helvetica Bold core font with Latin 1 encoding.
|
102
|
+
#
|
103
|
+
def self.helvetica_bold
|
104
|
+
@@helvetica_bold = Font.new if @@helvetica_bold.nil?
|
105
|
+
|
106
|
+
@@helvetica_bold._name = "helveticaBold"
|
107
|
+
@@helvetica_bold
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# Gets the Helvetica Oblique core font with Latin 1 encoding.
|
112
|
+
#
|
113
|
+
def self.helvetica_oblique
|
114
|
+
@@helvetica_oblique = Font.new if @@helvetica_oblique.nil?
|
115
|
+
|
116
|
+
@@helvetica_oblique._name = "helveticaOblique"
|
117
|
+
@@helvetica_oblique
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# Gets the Helvetica Bold Oblique core font with Latin 1 encoding.
|
122
|
+
#
|
123
|
+
def self.helvetica_bold_oblique
|
124
|
+
@@helvetica_boldOblique = Font.new if @@helvetica_boldOblique.nil?
|
125
|
+
|
126
|
+
@@helvetica_boldOblique._name = "helveticaBoldOblique"
|
127
|
+
@@helvetica_boldOblique
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
# Gets the Courier core font with Latin 1 encoding.
|
132
|
+
#
|
133
|
+
def self.courier
|
134
|
+
@@courier = Font.new if @@courier.nil?
|
135
|
+
|
136
|
+
@@courier._name = "courier"
|
137
|
+
@@courier
|
138
|
+
end
|
139
|
+
|
140
|
+
#
|
141
|
+
# Gets the Courier Bold core font with Latin 1 encoding.
|
142
|
+
#
|
143
|
+
def self.courier_bold
|
144
|
+
@@courier_bold = Font.new if @@courier_bold.nil?
|
145
|
+
|
146
|
+
@@courier_bold._name = "courierBold"
|
147
|
+
@@courier_bold
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# Gets the Courier Oblique core font with Latin 1 encoding.
|
152
|
+
#
|
153
|
+
def self.courier_oblique
|
154
|
+
@@courier_oblique = Font.new if @@courier_oblique.nil?
|
155
|
+
|
156
|
+
@@courier_oblique._name = "courierOblique"
|
157
|
+
@@courier_oblique
|
158
|
+
end
|
159
|
+
|
160
|
+
#
|
161
|
+
# Gets the Courier Bold Oblique core font with Latin 1 encoding.
|
162
|
+
#
|
163
|
+
def self.courier_bold_oblique
|
164
|
+
@@courier_boldOblique = Font.new if @@courier_boldOblique.nil?
|
165
|
+
|
166
|
+
@@courier_boldOblique._name = "courierBoldOblique"
|
167
|
+
@@courier_boldOblique
|
168
|
+
end
|
169
|
+
|
170
|
+
#
|
171
|
+
# Gets the Symbol core font.
|
172
|
+
#
|
173
|
+
def self.symbol
|
174
|
+
@@symbol = Font.new if @@symbol.nil?
|
175
|
+
|
176
|
+
@@symbol._name = "symbol"
|
177
|
+
@@symbol
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Gets the Zapf Dingbats core font.
|
182
|
+
#
|
183
|
+
def self.zapf_dingbats
|
184
|
+
@@zapf_dingbats = Font.new if @@zapf_dingbats.nil?
|
185
|
+
|
186
|
+
@@zapf_dingbats._name = "zapfDingbats"
|
187
|
+
@@zapf_dingbats
|
188
|
+
end
|
189
|
+
|
190
|
+
#
|
191
|
+
# Initializes a new instance of the Font class using the file path of the font and resource name.
|
192
|
+
#
|
193
|
+
# @param file_path [String] The file path of the font file.
|
194
|
+
# @param resource_name [String] The resource name for the font.
|
195
|
+
#
|
196
|
+
def self.from_file(file_path, resource_name = nil)
|
197
|
+
resource = Resource.new(file_path, resource_name)
|
198
|
+
Font.create_font(resource, resource.resource_name)
|
199
|
+
end
|
200
|
+
|
201
|
+
def self.from_stream(_stream, _resource_name = nil)
|
202
|
+
resource = Resource.new(stream, resource_name)
|
203
|
+
Font.create_font(resource, resource.resource_name)
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.get_google_font_text(name, weight, italic)
|
207
|
+
if italic == true
|
208
|
+
name + ":" + weight.to_s + "italic"
|
209
|
+
else
|
210
|
+
name + ":" + weight.to_s
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
#
|
215
|
+
# Gets the font from the google.
|
216
|
+
#
|
217
|
+
# @param fontName [string] The name of the google font.
|
218
|
+
# @param bold [bold] If true font weight will be taken as 700 otherwise 400.
|
219
|
+
# @param italic [italic] The italic property of the font.
|
220
|
+
# @returns The font object.
|
221
|
+
#
|
222
|
+
def self.google(font_name, bold = nil, italic = false)
|
223
|
+
font = Font.new()
|
224
|
+
if bold == true
|
225
|
+
font._name = Font.get_google_font_text(font_name, 700, italic)
|
226
|
+
elsif (bold.is_a?(Integer) == true)
|
227
|
+
font._name = Font.get_google_font_text(font_name, bold, italic);
|
228
|
+
elsif bold == false
|
229
|
+
font._name = Font.get_google_font_text(font_name, 400, italic);
|
230
|
+
else
|
231
|
+
font._name = font_name;
|
232
|
+
end
|
233
|
+
font
|
234
|
+
end
|
235
|
+
|
236
|
+
#
|
237
|
+
# Gets the font from the global storage.
|
238
|
+
#
|
239
|
+
# @param fontName [string] The name of the font to get from the global storage..
|
240
|
+
# @returns The font object.
|
241
|
+
#
|
242
|
+
def self.global(font_name)
|
243
|
+
font = Font.new()
|
244
|
+
font._name = font_name
|
245
|
+
font
|
246
|
+
end
|
247
|
+
|
248
|
+
def to_json(_options = {})
|
249
|
+
json_array = {}
|
250
|
+
json_array["name"] = @_name unless @_name.nil?
|
251
|
+
|
252
|
+
json_array["embed"] = @embed unless @embed.nil?
|
253
|
+
|
254
|
+
json_array["subset"] = @subset unless @subset.nil?
|
255
|
+
|
256
|
+
json_array["resourceName"] = @resource_name unless @resource_name.nil?
|
257
|
+
|
258
|
+
JSON.pretty_generate(json_array)
|
259
|
+
end
|
260
|
+
|
261
|
+
@@times_roman = nil
|
262
|
+
@@times_bold = nil
|
263
|
+
@@times_italic = nil
|
264
|
+
@@times_bold_italic = nil
|
265
|
+
@@helvetica = nil
|
266
|
+
@@helvetica_bold = nil
|
267
|
+
@@helvetica_oblique = nil
|
268
|
+
@@helvetica_boldOblique = nil
|
269
|
+
@@courier = nil
|
270
|
+
@@courier_bold = nil
|
271
|
+
@@courier_oblique = nil
|
272
|
+
@@courier_boldOblique = nil
|
273
|
+
@@symbol = nil
|
274
|
+
@@zapf_dingbats = nil
|
275
|
+
end
|
276
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
require_relative 'Resource'
|
3
|
+
require_relative 'ResourceType'
|
4
|
+
|
5
|
+
class FontResource < Resource
|
6
|
+
def initialize(file, resource_name = nil)
|
7
|
+
@_mime_type = nil
|
8
|
+
@_type = ResourceType::FONT
|
9
|
+
super(file, resource_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def _file_extension
|
13
|
+
file_header = @data[0, 4]
|
14
|
+
byte_array = file_header.bytes
|
15
|
+
|
16
|
+
if byte_array[0] == 0x4f && byte_array[1] == 0x54 && byte_array[2] == 0x54 && byte_array[3] == 0x4f
|
17
|
+
@_mime_type = 'font/otf'
|
18
|
+
'.otf'
|
19
|
+
elsif byte_array[0] == 0x00 && byte_array[1] == 0x01 && byte_array[2] == 0x00 && byte_array[3] == 0x00
|
20
|
+
@_mime_type = 'font/ttf'
|
21
|
+
'.ttf'
|
22
|
+
else
|
23
|
+
raise 'Unsupported font'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_json(_options = {})
|
28
|
+
json_array = {}
|
29
|
+
json_array['name'] = @name
|
30
|
+
json_array['resourceName'] = @resource_name
|
31
|
+
|
32
|
+
JSON.pretty_generate(@json_array)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module DynamicPDFApi
|
2
|
+
#
|
3
|
+
#
|
4
|
+
# Represents a form field in the PDF document.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
class FormField
|
8
|
+
#
|
9
|
+
# Initializes a new instance of the FormField class using the name and the value of the form field as parameters.
|
10
|
+
#
|
11
|
+
# @param name [String] The name of the form field.
|
12
|
+
# @param value [String] The value of the form field.
|
13
|
+
#
|
14
|
+
def initialize(name, value = nil)
|
15
|
+
@flatten = nil
|
16
|
+
@remove = nil
|
17
|
+
|
18
|
+
@name = name
|
19
|
+
@value = value
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Gets or sets name of the form field.
|
24
|
+
#
|
25
|
+
attr_accessor :name
|
26
|
+
|
27
|
+
#
|
28
|
+
# Gets or sets value of the form field.
|
29
|
+
#
|
30
|
+
attr_accessor :value
|
31
|
+
|
32
|
+
#
|
33
|
+
# Gets or sets a boolean indicating whether to flatten the form field.
|
34
|
+
#
|
35
|
+
attr_accessor :flatten
|
36
|
+
|
37
|
+
#
|
38
|
+
# Gets or sets a boolean indicating whether to remove the form field.
|
39
|
+
#
|
40
|
+
attr_accessor :remove
|
41
|
+
|
42
|
+
def to_json(_options = {})
|
43
|
+
json_array = {}
|
44
|
+
json_array['name'] = @name
|
45
|
+
json_array['value'] = @value
|
46
|
+
|
47
|
+
json_array['flatten'] = if !@flatten.nil?
|
48
|
+
@flatten
|
49
|
+
else
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
json_array['remove'] = if !@remove.nil?
|
54
|
+
@remove
|
55
|
+
else
|
56
|
+
false
|
57
|
+
end
|
58
|
+
|
59
|
+
JSON.pretty_generate(json_array)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|