I have a feature that allows users to generate PDFs. This is done by creating an HTML version of the page and using Puppeteer to render it to a PDF. This feature worked fine but recently we made some changes to our Cloudformation templates, and had to spin up new EC2 instances. This broke puppeteer. I’ve reinstalled it and updated the Node version. Now, however I’m not even getting to the PDF generate, the application is throwing this error message:
(Phoenix.Template.UndefinedError) Could not render "quote_pdf.html" for StorefrontWeb.PDFView, please define a matching clause for render/2 or define a template at "lib/storefront_web/templates/pdf/**/*". No templates were compiled for this module.
But quote_pdf.html
does exist, it hasn’t moved or changed, and I’ve redeployed a few times just to be sure. I’ve even changed up the file suffix from, trying .html.eex
.html.leex
, .html.heex
. I’ve also created other dummy HTML files in that directory to be sure.
#uses view to call `render/2`
use StorefrontWeb, :view
@spec to_pdf(Map.t()) :: {:ok, String.t()} | {:error, atom()}
def to_pdf( assigns) do
filename = create_filename(assigns)
render_pdf("quote_pdf.html", filename, assigns)
end
# sobelow_skip ["Traversal.FileModule"]
defp render_pdf(template, filename, %{quote_id: quote_id} = assigns) do
root_path = Application.get_env(:storefront_web, :tmp_dir)
with html <- render_html(template, assigns),
# the next clauses are never called
html_path <- Path.join([root_path, "#{filename}.html"]),
pdf_path <- Path.join([root_path, "#{filename}.pdf"]),
:ok <- File.write(html_path, html),
{_, 0} <-
System.cmd("puppeteer-pdf", [
html_path,
"--path",
pdf_path
]) do
...
end
def render_html(template, assigns) do
template
|> __MODULE__.render(assigns)
|> html_escape()
|> safe_to_string()
end
Any idea why my template is no longer being found? I mentioned the server and node updates because they happened at the same time this stopped working however all the related errors went away when I got Puppeteer installed so I don’t think they are related.