I am trying to create a feature that creates a PDF and image with data given by the user.
For the PDF I successfully converted my template **.html.erb
to PDF using the Wicked PDF gem. However, I cannot find a similar gem or way to create an image out of my ERB file after a few hours of searching.
This is how I converted my template to PDF using Wicked PDF.
def linesheet_pdf
# variables used to create the pdf
@items = params[:items]
@contact = params[:contact]
# send pdf file back to front end
response_to do |format|
format.pdf do
render pdf: "filename.pdf",
template: "path/to/html/erb/file/XYZ.html.erb",
type: 'application/pdf', page_size: 'Letter'
end
end
end
By doing this I was able to use my HTML file with the styling from my custom CSS file.
I initially thought about converting the PDF to an image as a workaround but I found the image file converted from the PDF with multiple pages will not be a single image with long scroll.