In this episode I will show you how to create PDF documents using the excellent PDF::Writer gem.
# environment.rb
require 'pdf/writer'
Mime::Type.register 'application/pdf', :pdf
# products_controller.rb
def index
@products = Product.find(:all)
respond_to do |format|
format.html
format.pdf do
send_data ProductDrawer.draw(@products), :filename => 'products.pdf', :type => 'application/pdf', :disposition => 'inline'
end
end
end
# product_drawer.rb
def self.draw(products)
pdf = PDF::Writer.new
products.each do |product|
pdf.text product.name
end
pdf.render
end
<p><%= link_to 'PDF Format', formatted_products_path(:pdf) %></p>
分享到:
相关推荐
Generating PDF documents with internal and external links Unicode characters full support Two encryption methods support - 40 bit and 128 bit Defining the document properties: author, keywords, ...
AspPDF is an ActiveX server component for generating, opening and modifying documents in Portable Document Format (PDF). With AspPDF, your application can automatically create customer invoices, ...
PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy. It's written in CoffeeScript, but you can choose to use the API...
- **Documentation and Reporting**: Comprehensive guidelines are given for documenting the test results and generating reports. This documentation serves as evidence of compliance and is crucial for ...
- **Interrupt Hardware Operation:** Describes the hardware mechanism for generating interrupts, which are signals that indicate an event has occurred that requires immediate attention by the processor...
6.4 War Story: Dialing for Documents . . . . . . . . . . . . . . . . . 212 6.5 Network Flows and Bipartite Matching . . . . . . . . . . . . . . 217 6.6 Design Graphs, Not Algorithms . . . . . . . . . ...
It begins with a fast-paced but thorough tutorial on building web content with the Template Toolkit, and then walks you through generating and using data files, particularly with XML. It also ...
Multi-profile YAML Documents 24.6.4. YAML Shortcomings 24.7. Type-safe Configuration Properties 24.7.1. Third-party Configuration 24.7.2. Relaxed Binding 24.7.3. Merging Complex Types 24.7.4. ...
1. **Bootstrap Aggregation (Bagging)**: This approach involves generating multiple training sets by randomly sampling the original dataset with replacement, then training individual models on these ...
- **OLE 对象支持 (OLE Object Support in PCB Documents)**:新增了对 OLE 对象的支持,允许用户在 PCB 文档中嵌入其他应用程序的对象,如 Excel 表格或 Word 文档。 - **矩形焊盘孔支持 (Support for Rectangular ...
- Generating random strings. - Ensuring password complexity requirements. 28. **Join Numbers** - **Objective:** Concatenate a list of numbers into a single string. - **Key Concepts:** - ...
Putting it all together: generating user pages 40 Creating the URL 40 Writing the view 41 Designing the template 42 Populating the model with data 44 Summary 45 Chapter 4: User Registration and ...
- 表单生成和验证(Generating and Validating Forms)。 - 会话和用户认证(Working with Sessions and User Authentication)。 - 数据库、事务和对象关系映射(ORMs)操作(Working with Databases, Transactions...
5.1 Getting Started with the Documents and Media Portlet . . . . . . . . . . 113 5.2 Document Types and Metadata Sets . . . . . . . . . . . . . . . . . . . . 116 5.3 Alternative File Repository ...
Counting Pages of PDF Documents on Mac OS X Recipe 2.25. Changing File Attributes on Windows Recipe 2.26. Extracting Text from OpenOffice.org Documents Recipe 2.27. Extracting Text from ...