I'm creating a service to add a watermark to the top of a client pdf file. When I add it to the pdf source, the html text loads fine but not the image (a small square is shown instead).
Here some piece of my code:
add_online_signature_to_partner_quote_pdf_service.rb
:
class AddOnlineSignatureToPartnerQuotePdfService
def initialize(quote)
@quote = quote
end
def call
pdf = CombinePDF.new
source = CombinePDF.parse(@quote.document.download, { allow_optional_content: true })
signature = CombinePDF.parse(generate_signature(@quote))
pdf << source
pdf << signature
update_quote_with_signature(@quote, pdf)
end
private
def generate_signature(quote)
project = quote.project
ac = ApplicationController.new
pdf = WickedPdf.new.pdf_from_string(
ac.render_to_string(
template: "advanced_admin/quotes/form/_partner_quote_signature.pdf.erb",
layout: "pdf.html",
locals: { quote: quote, project: project, pdf: true }
)
)
end
def update_quote_with_signature(quote, pdf)
quote.document.attach(
io: StringIO.new(pdf.to_pdf),
filename: "quote_complete.pdf",
content_type: "application/pdf"
)
end
end
_partner_quote_signature.pdf.erb
:
<div>
<h1>my title</h1>
<%= wicked_pdf_image_tag "logo-blue.png" %>
<p>my paragraph</p>
</div>
The image I want to generate within my PDF is classically located in my asset pipeline app/assets/images/logo-blue.png
I tried a lot of different syntaxes I saw on other topics but nothing seems to work... The 'wkhtmltopdf-binary' gem version is 0.12.6.5
Do you have an idea how I could make my code working? Thanks a lot!