<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/github---mileszs-wicked-pdf-pdf-generator-from-html-plugin-for-ruby-on-rails-zda5hdt3m" -->

---
title: GitHub - mileszs/wicked_pdf: PDF generator (from HTML)...
description: Wicked PDF is a Ruby on Rails plugin that generates PDF files from HTML views using the wkhtmltopdf shell utility. It supports Ruby 2.2–3.2 and Rails 4–7.0....
canonical: https://daily.dev/posts/github---mileszs-wicked-pdf-pdf-generator-from-html-plugin-for-ruby-on-rails-zda5hdt3m
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: GitHub - mileszs/wicked_pdf: PDF generator (from HTML) plugin for Ruby on Rails | daily.dev
og:description: Wicked PDF is a Ruby on Rails plugin that generates PDF files from HTML views using the wkhtmltopdf shell utility. It supports Ruby 2.2–3.2 and Rails 4–7.0....
og:url: https://daily.dev/posts/github---mileszs-wicked-pdf-pdf-generator-from-html-plugin-for-ruby-on-rails-zda5hdt3m
og:image: https://api.daily.dev/og/posts/Zda5hdt3M.png
og:image:alt: GitHub - mileszs/wicked_pdf: PDF generator (from HTML) plugin for Ruby on Rails
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# GitHub - mileszs/wicked_pdf: PDF generator (from HTML) plugin for Ruby on Rails

**[Ruby Flow](https://daily.dev/sources/rubyflow)** · 13 min read · 0 upvotes · 0 comments

## Summary

Wicked PDF is a Ruby on Rails plugin that generates PDF files from HTML views using the wkhtmltopdf shell utility. It supports Ruby 2.2–3.2 and Rails 4–7.0. Installation requires adding the gem and optionally the wkhtmltopdf-binary gem. Usage is straightforward: respond to PDF format requests in controllers and write standard HTML views. The plugin provides helpers for asset pipeline, Webpacker, and CDN references to handle absolute asset paths required by wkhtmltopdf. Advanced options cover orientation, page size, headers, footers, table of contents, margins, cookies, authentication, and progress tracking. It also supports generating PDFs from strings, HTML files, or URLs, attaching PDFs to emails, and using Rack middleware for automatic PDF rendering. Security considerations include sanitizing user-generated HTML to prevent SSRF via internal metadata endpoints.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://github.com/mileszs/wicked_pdf>

## Questions this post answers

### How do I generate a PDF from an HTML view in Ruby on Rails using wicked_pdf?

Install the wicked_pdf and wkhtmltopdf-binary gems, run rails generate wicked_pdf, then respond to the PDF format in your controller with render pdf: 'file_name'. Because wkhtmltopdf runs outside Rails, use wicked_pdf helpers like wicked_pdf_stylesheet_link_tag and wicked_pdf_image_tag in your PDF layout to provide absolute asset paths instead of relative ones.

_Rails developers shipping PDF exports track wicked_pdf updates and gotchas on daily.dev._

### How do I generate a PDF from a string in Rails without rendering a view using wicked_pdf?

Call WickedPdf.new.pdf_from_string('<h1>Hello</h1>') to create a PDF directly from an HTML string. You can also use pdf_from_html_file('/absolute/path') for a local file or pdf_from_url('https://example.com') for a URL. To use Rails templates, pass render_to_string output as the string argument, including layout and footer content options.

_Developers building background PDF jobs find wicked_pdf patterns and edge cases discussed on daily.dev._

### What are the security risks of using wicked_pdf with user-generated HTML?

Allowing user-generated HTML through wicked_pdf can expose internal infrastructure via SSRF. For example, an iframe or object tag pointing to http://169.254.169.254/latest/meta-data/ can leak AWS instance metadata. It is strongly recommended to sanitize user HTML before conversion and to block requests to internal IP addresses and hostnames.

_Teams handling user content in PDF pipelines stay ahead of vulnerabilities like these on daily.dev._

## Similar posts on daily.dev

- [Building Virtuous PDF: How Gusto Replaced a Deprecated Library with a Modern PDF Microservice](https://daily.dev/posts/building-virtuous-pdf-how-gusto-replaced-a-deprecated-library-with-a-modern-pdf-microservice-q3r9ntw7b) · Gusto Engineering · 1 upvotes · 2 comments
- [Generating Charts in Pure Ruby Without JavaScript](https://daily.dev/posts/generating-charts-in-pure-ruby-without-javascript-yqenrulz1) · RUBYLAND · 0 upvotes · 0 comments
- [About sghtmltopdf](https://daily.dev/posts/about-sghtmltopdf-fliv0adxy) · Ruby Flow · 0 upvotes · 0 comments
- [Write PDFs in React. Render them from Go. No Node, no browser, no sidecar.](https://daily.dev/posts/write-pdfs-in-react-render-them-from-go-no-node-no-browser-no-sidecar--yoq6vdfyj) · Medium · 91 upvotes · 2 comments
- [Tutorialkit.rb: the ruby.wasm journey goes onward—Martian Chronicles, Evil Martians’ team blog](https://daily.dev/posts/tutorialkit-rb-the-ruby-wasm-journey-goes-onward-martian-chronicles-evil-martians-team-blog-zhyxjbjx2) · Martian Chronicles · 0 upvotes · 0 comments

---

Tags: [#ruby](https://daily.dev/tags/ruby), [#rails](https://daily.dev/tags/rails)

[View this post on daily.dev](https://daily.dev/posts/github---mileszs-wicked-pdf-pdf-generator-from-html-plugin-for-ruby-on-rails-zda5hdt3m)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"GitHub - mileszs/wicked_pdf: PDF generator (from HTML) plugin for Ruby on Rails","url":"https://daily.dev/posts/github---mileszs-wicked-pdf-pdf-generator-from-html-plugin-for-ruby-on-rails-zda5hdt3m","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/github---mileszs-wicked-pdf-pdf-generator-from-html-plugin-for-ruby-on-rails-zda5hdt3m"},"datePublished":"2026-08-09T14:20:42.758Z","dateModified":"2026-08-09T14:21:10.910Z","description":"Wicked PDF is a Ruby on Rails plugin that generates PDF files from HTML views using the wkhtmltopdf shell utility. It supports Ruby 2.2–3.2 and Rails 4–7.0....","image":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","thumbnailUrl":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","isAccessibleForFree":true,"articleSection":"Ruby Flow","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Ruby Flow","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/a21aaa8bcbbf448193a016895c90a0e1","url":"https://daily.dev/sources/rubyflow"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/github---mileszs-wicked-pdf-pdf-generator-from-html-plugin-for-ruby-on-rails-zda5hdt3m","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ruby,rails","timeRequired":"PT13M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Ruby Flow","item":"https://daily.dev/sources/rubyflow"},{"@type":"ListItem","position":3,"name":"GitHub - mileszs/wicked_pdf: PDF generator (from HTML) plugin for Ruby on Rails"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/github---mileszs-wicked-pdf-pdf-generator-from-html-plugin-for-ruby-on-rails-zda5hdt3m#faq","mainEntity":[{"@type":"Question","name":"How do I generate a PDF from an HTML view in Ruby on Rails using wicked_pdf?","acceptedAnswer":{"@type":"Answer","text":"Install the wicked_pdf and wkhtmltopdf-binary gems, run rails generate wicked_pdf, then respond to the PDF format in your controller with render pdf: 'file_name'. Because wkhtmltopdf runs outside Rails, use wicked_pdf helpers like wicked_pdf_stylesheet_link_tag and wicked_pdf_image_tag in your PDF layout to provide absolute asset paths instead of relative ones. Rails developers shipping PDF exports track wicked_pdf updates and gotchas on daily.dev."}},{"@type":"Question","name":"How do I generate a PDF from a string in Rails without rendering a view using wicked_pdf?","acceptedAnswer":{"@type":"Answer","text":"Call WickedPdf.new.pdf_from_string('<h1>Hello</h1>') to create a PDF directly from an HTML string. You can also use pdf_from_html_file('/absolute/path') for a local file or pdf_from_url('https://example.com') for a URL. To use Rails templates, pass render_to_string output as the string argument, including layout and footer content options. Developers building background PDF jobs find wicked_pdf patterns and edge cases discussed on daily.dev."}},{"@type":"Question","name":"What are the security risks of using wicked_pdf with user-generated HTML?","acceptedAnswer":{"@type":"Answer","text":"Allowing user-generated HTML through wicked_pdf can expose internal infrastructure via SSRF. For example, an iframe or object tag pointing to http://169.254.169.254/latest/meta-data/ can leak AWS instance metadata. It is strongly recommended to sanitize user HTML before conversion and to block requests to internal IP addresses and hostnames. Teams handling user content in PDF pipelines stay ahead of vulnerabilities like these on daily.dev."}}]}
```

