`
CaiDeHen
  • 浏览: 94272 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#78 Generating PDF Documents

阅读更多
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>
分享到:
评论

相关推荐

    Advanced PDF Generator 2.0.0.0 Full Source

    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 pdfcreator

    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-node操作pdf

    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...

    ISO 11452-4-2020.pdf

    - **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 ...

    i.MX Linux® Reference Manual

    - **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...

    Skiena-The_Algorithm_Design_Manual.pdf

    6.4 War Story: Dialing for Documents . . . . . . . . . . . . . . . . . 212 6.5 Network Flows and Bipartite Matching . . . . . . . . . . . . . . 217 6.6 Design Graphs, Not Algorithms . . . . . . . . . ...

    Perl.Template.Toolkit

    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 ...

    spring-boot-reference.pdf

    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. ...

    polikar2012.pdf

    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 ...

    Release Notes for Altium Designer Version 15.0 - 2014-11-17.pdf

    - **OLE 对象支持 (OLE Object Support in PCB Documents)**:新增了对 OLE 对象的支持,允许用户在 PCB 文档中嵌入其他应用程序的对象,如 Excel 表格或 Word 文档。 - **矩形焊盘孔支持 (Support for Rectangular ...

    Lerner -- Python Workout. 50 Essential Exercises -- 2020.pdf

    - Generating random strings. - Ensuring password complexity requirements. 28. **Join Numbers** - **Objective:** Concatenate a list of numbers into a single string. - **Key Concepts:** - ...

    Django 1.0 Website Development.pdf

    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 ...

    pecan 官网开源文档 英文版 pdf, pecan document

    - 表单生成和验证(Generating and Validating Forms)。 - 会话和用户认证(Working with Sessions and User Authentication)。 - 数据库、事务和对象关系映射(ORMs)操作(Working with Databases, Transactions...

    using-liferay-portal-6.2.pdf

    5.1 Getting Started with the Documents and Media Portlet . . . . . . . . . . 113 5.2 Document Types and Metadata Sets . . . . . . . . . . . . . . . . . . . . 116 5.3 Alternative File Repository ...

    Python Cookbook, 2nd Edition

    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 ...

Global site tag (gtag.js) - Google Analytics