Module: AddImageInsidePdf
- Defined in:
- lib/add_image_inside_pdf.rb,
lib/add_image_inside_pdf/version.rb,
lib/add_image_inside_pdf/text_replace_processor.rb
Defined Under Namespace
Classes: TextReplaceProcessor
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Method Summary
collapse
Class Method Details
.replace_all_text_by_image(pdf_file_path, strings_to_replace, image_local_path, height = 20) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/add_image_inside_pdf.rb', line 15
def self.replace_all_text_by_image pdf_file_path, strings_to_replace, image_local_path, height=20
file_name = pdf_file_path
strings_to_black = strings_to_replace
doc = HexaPDF::Document.open(file_name)
doc.pages.each.with_index do |page, index|
processor = AddImageInsidePdf::TextReplaceProcessor.new(page, strings_to_black)
page.process_contents(processor)
processor.replace_text_to_image(image_local_path, height)
end
doc.write(file_name, optimize: true)
file_name
end
|
.replace_text_by_image(pdf_file_path, string_to_replace, image_local_path, height = 20) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/add_image_inside_pdf.rb', line 2
def self.replace_text_by_image pdf_file_path, string_to_replace, image_local_path, height=20
file_name = pdf_file_path
strings_to_black=[string_to_replace]
doc = HexaPDF::Document.open(file_name)
doc.pages.each.with_index do |page, index|
processor = AddImageInsidePdf::TextReplaceProcessor.new(page, strings_to_black)
page.process_contents(processor)
processor.replace_text_to_image(image_local_path, height)
end
doc.write(file_name, optimize: true)
file_name
end
|