Article Discussion
Creating Printable Documents with Ruby
Summary: In this article, Austin Ziegler introduces the creation of a variety of types of documents with PDF::Writer for Ruby. This introduction covers basic creation, partial document generation and customization, and Rails-generated documents.
23 posts.
The ability to add new comments in this discussion is temporarily disabled.
Most recent reply: December 1, 2008 4:33 AM by Gustavo
    James
     
    Posts: 9 / Nickname: jbritt / Registered: March 24, 2003 4:10 PM
    Creating Printable Documents with Ruby
    October 9, 2005 8:00 PM      
    In this article, Austin Ziegler introduces the creation of a variety of types of documents with PDF::Writer for Ruby. This introduction covers basic creation, partial document generation and customization, and Rails-generated documents.

    Read this Artima article by Austin Ziegler, creator of PDF::Writer

    http://www.artima.com/rubycs/articles/pdf_writer.html

    What do you think about using PDF::Writer?
    • Matthew
       
      Posts: 2 / Nickname: matthewmur / Registered: October 9, 2005 9:54 PM
      Re: Creating Printable Documents with Ruby
      October 10, 2005 2:05 AM      
      I liked the article. Good introduction. I'm new to ruby and rails and am learning and starting to work on a first project which is going to involve lots of number type data so it would be really nice to allow people to be able to export that data in lots of different formats. You mentioned there was just one type of chart available at the minute. Would it be very difficult to introduce other types of charts and colour them ? And as far as I can see (maybe I'm wrong and need to pay more attention) these are static examples where everything we see in the pdf has been hardcoded. How would I go about creating a generic export PDF type function that would take the XHTML structure and spit it out into a nice pdf?
      • Austin
         
        Posts: 2 / Nickname: aziegler / Registered: October 10, 2005 11:05 AM
        Re: Creating Printable Documents with Ruby
        October 10, 2005 4:35 PM      
        > You mentioned there was just one type of chart available
        > at the minute. Would it be very difficult to introduce
        > other types of charts and colour them?

        Strictly speaking, it wouldn't. It's a matter of time. Charts::StdDev is the only type because that's all that I've had time to develop. Any user-submitted chart type would be accepted into the PDF::Write project under the same licence.

        > And as far as I can see (maybe I'm wrong and need to pay
        > more attention) these are static examples where
        > everything we see in the pdf has been hardcoded.

        For the examples in the article, that is correct. I don't have a database application where this would make sense to demonstrate and considered it a little too advanced for this introduction.

        > How would I go about creating a generic export PDF type
        > function that would take the XHTML structure and spit it
        > out into a nice pdf?

        That's the real rub. It's a hard problem that will take a lot of code to solve. There are some bizarre things with XHTML support that need serious thought. (There's a reason that the table support model in PDF::Writer isn't based on the XHTML table model.)
        • Matthew
           
          Posts: 2 / Nickname: matthewmur / Registered: October 9, 2005 9:54 PM
          Re: Creating Printable Documents with Ruby
          October 11, 2005 0:23 AM      
          Ok, thanks for replying :) Now, I'm a completely useless coder really for this type of thing bue perhaps I could help a little bit in other ways. I'm going to start development of my first little rails application this week which would include plenty of data that you could play around once I get it onto a live domain. Then I saw this article on sitepoint a few weeks ago about pdfs and php. Maybe it could help you with a few ideas:

          http://www.sitepoint.com/article/generate-pdfs-php
          • Austin
             
            Posts: 2 / Nickname: aziegler / Registered: October 10, 2005 11:05 AM
            Re: Creating Printable Documents with Ruby
            October 11, 2005 3:19 AM      
            Thank you for the pointer. The relevant code is on the 4th page of that article, and all it does is have a simple example of a manually generated pie chart. The difficulty with making charts in PDF::Writer is that they have to be a little smarter than that, as they are components to be reused. My main problem isn't with figuring out how to create such charts (as I could easily take Charts::StdDev and create Line and High-Low charts, and it wouldn't take much to go from those to vertical Bar charts), but a severe lack of time.

            Future directions for PDF::Writer include SVG import (which may make some of the charting issues moot, as well), presentation support (which is almost done, but probably still a month from release), document reading and modification, and direct TTF support. Some of the work for SVG import will make it much easier to do XHTML conversion at a later date, but I think I will be leaving that for others to tackle using PDF::Writer as a worker capability.
    • Zach
       
      Posts: 2 / Nickname: zdennis / Registered: September 22, 2004 8:40 AM
      Re: Creating Printable Documents with Ruby
      November 6, 2005 4:03 PM      
      Austin, a great read! This almost seems to simple. I look forward to using PDF::Writer, and I look forward to being able to utilize ruby to generate pdfs rather then using Java!
    • Peter
       
      Posts: 1 / Nickname: pgillogley / Registered: November 28, 2005 6:46 PM
      Re: Creating Printable Documents with Ruby
      November 29, 2005 0:05 AM      
      Hi

      I fell across this by accident. I had been wondering how I could create a utility that I could call from a ruby test script would log my screen based tests and support inclusion of screen images, tables, colours for highlighting sections of test. I also wanted to use common file format so that the documents could be displayed by most users. I had imagined that I would need to write something to create MS Word RTF documents (I assumed Adobe would be too hard). Then I saw your PDF::Writer for Ruby!...

      The install was easy (using GEMS) and the demos run first time. The PDFs look great. All very positive (and very professional). I am looking forward to using this in my testing.

      Thanks for creating this and sharing it

      Peter Gillogley

      http://www.gillogley.com/testing.shtml
    • George
       
      Posts: 1 / Nickname: thelonious / Registered: December 1, 2005 11:43 PM
      Re: Creating Printable Documents with Ruby
      December 2, 2005 5:22 AM      
      Hi. I am using PDF:Writer for a month now and I face only one problem, as long as I live in Greece: display of greek characters. As a first approach I extract an .afm file from a greek font file, copy it to /lib/pdf/writer/font, add the differences to the select_font function (cp1253 codes) and get greek characters displayed correctly, but only in viewers different than acrobat reader. In acrobat reader the characters are correct but seems that all the metrics are gone.
      Do you have any ideas?
    • Kenneth
       
      Posts: 1 / Nickname: pryce / Registered: August 15, 2005 11:53 PM
      Re: Creating Printable Documents with Ruby
      January 6, 2006 2:25 AM      
      How about support for xsl-fo? Since it's a standard formatting technique in f.ex. xml-based publishing systems, it would seem like a natural feature to add.

      Best regards,

      Kenneth,
      Denmark
    • Ray
       
      Posts: 1 / Nickname: raycarr / Registered: February 23, 2006 0:11 AM
      Re: Creating Printable Documents with Ruby
      February 23, 2006 5:17 AM      
      Does anyone know if PDF::Writer supports png images with transparecy?

      Cheers, Ray
    • sinson
       
      Posts: 1 / Nickname: franee / Registered: July 11, 2006 7:24 PM
      Re: Creating Printable Documents with Ruby
      July 11, 2006 11:31 PM      
      Hello,

      I used pdf writer in rails and i used the example:

      send_data _pdf.render, :filename => "hello.pdf",
      :type => "application/pdf"

      When i download and open the pdf file, it can't be read because it is corrupt. Any ideas?

      Thanks,
      /franee
    • Kareem
       
      Posts: 1 / Nickname: kbadr / Registered: August 25, 2006 8:00 AM
      Re: Creating Printable Documents with Ruby
      August 25, 2006 1:02 PM      
      Does anyone know how to make the PDF Writer library fit a table to a page. Or, rather, resize a page to make a table fit. I've got code that dynamically generates tables (for a printable version of a report), but if the table has a lot of data, it doesn't fit on the page, and the table just gets chopped off on the left and right. Is there a way to tell PDF Writer to make the page resize to fit all the objects that are going to be rendered on it?
    • sf
       
      Posts: 1 / Nickname: sfdesigner / Registered: January 5, 2007 4:30 AM
      Re: Creating Printable Documents with Ruby
      January 5, 2007 10:38 AM      
      Where is the 95 page manual? I can't find a link to it anywhere. Is it contained in a downloadable archive?
      • wiktor
         
        Posts: 1 / Nickname: wmacura / Registered: February 3, 2007 2:07 AM
        Re: Creating Printable Documents with Ruby
        February 3, 2007 8:11 AM      
        http://files.rubyforge.mmmultiworks.com/ruby-pdf/pdf-writer-demo-1.1.3.tar.gz

        The manual is in there :-)
        • Chris
           
          Posts: 1 / Nickname: arch79 / Registered: February 5, 2007 4:23 AM
          Re: Creating Printable Documents with Ruby
          February 5, 2007 10:28 AM      
          Is there any way to implement subtables with PDF:Writer? I have created a report for a database app that displays each sale on a row. I need to be able to display a subtable inside each row for the lineitems for that sale.
    • Rudy
       
      Posts: 1 / Nickname: rudisoe / Registered: April 15, 2007 10:09 PM
      Re: Creating Printable Documents with Ruby
      April 16, 2007 3:16 AM      
      I have this strange newbie problem with pdf::Writer in Ruby on rails. (MacOSX, MAMP, Locomotive, TExtmate)

      I took the first example out of the article, and it does actually saves the file, but... NOT to the desktop, but to the railsrootdirectory. Whatever I try, I can't get it to download it to the desktop, and I cannot find an explanation how to get the files there. Without it, the whole idea of pdf::writer seems a bit lost to me.
      Could someone help me out here?
      Many thanks inb advance.
      Rudi
    • wai
       
      Posts: 1 / Nickname: kevinwai / Registered: April 24, 2007 4:18 PM
      Re: Creating Printable Documents with Ruby
      April 24, 2007 9:22 PM      
      Hi,

      I am new to ruby and right now I am trying to do an export of a HTML table to a pdf file.

      Firstly, I have a dynamic data in the table whereby user needs to select different drop down lists and send the values to the back end to query the database and display the result. I am using ajax to do this.

      However, I still don't know how to create a pdf file of a HTML table.

      Can anyone help me with this?

      Thanks.
    • franz
       
      Posts: 2 / Nickname: practor / Registered: June 27, 2007 6:51 PM
      Re: Creating Printable Documents with Ruby
      June 28, 2007 0:40 AM      
      I'm trying to do the Marshal dumping and loading. Everything works fine from my Rails console but I get the error message "dump format error" via the web browser. Any ideas why?

      Thanks in advance,
      Franz
    • franz
       
      Posts: 2 / Nickname: practor / Registered: June 27, 2007 6:51 PM
      Re: Creating Printable Documents with Ruby
      June 28, 2007 2:05 AM      
      For some reason I haven't figured out yet, the dump formats differ when dumping from the console and from within my rails app. I did the dump from my rails app and used that as my template and now all is working as it should.

      Thanks for making such a useful PDF tool for ruby.

      Kind regards,
      Franz
      • bbb
         
        Posts: 1 / Nickname: railspdf / Registered: July 11, 2007 0:55 AM
        Re: Creating Printable Documents with Ruby
        July 11, 2007 6:58 AM      
        hi everyone,
        I used the pdf ::writter , it's very good . but I want to create the pdf page basing on the rhtml page that what's I don't know how because I don't want to recreate the queries and all the tests that I used to get the .rhtml page. what I want really is that I can from my page.rhtml and with cliking on the link pdf ,generate a pdf pge that contain the same information as the.rhtml
        can u help
        thanks
        • ricardo
           
          Posts: 2 / Nickname: ricardo85x / Registered: June 2, 2008 3:32 AM
          Re: Creating Printable Documents with Ruby
          June 2, 2008 8:40 AM      
          Hi

          I want to create a TAG for changing the text color like that:


          pdf.text("name: <c:color text='Green'> Robert </c:alink> ")

          but it is so hard to make.

          Some one know to do that or know if there is a way to change the color of a string like take(with tags)
          • ricardo
             
            Posts: 2 / Nickname: ricardo85x / Registered: June 2, 2008 3:32 AM
            Re: Creating Printable Documents with Ruby
            June 2, 2008 8:41 AM      
            Hi

            I want to create a TAG for changing the text color like that:


            pdf.text("name: <c:color text='Green'> Robert </c:color> ")

            but it is so hard to make.

            Some one know to do that or know if there is a way to change the color of a string like take(with tags)
    • Orthon
       
      Posts: 1 / Nickname: markeb / Registered: August 22, 2008 2:58 AM
      Re: Creating Printable Documents with Ruby
      August 22, 2008 8:07 AM      
      hi

      i have a weird PDF generation, i have to make a report and to do it i create various dinamic tables, but when i create the pdf in the first page tables apear normal, on the second apears the heading of column and in the next pages one column per page (the name of the column) after all column names apear the tables go normal and no more column names apear....

      can anyone help im cainda new on ruby and this its driving me crazy

      thamks
      • Gustavo
         
        Posts: 1 / Nickname: gdelfino / Registered: November 30, 2008 10:24 PM
        Re: Creating Printable Documents with Ruby
        December 1, 2008 4:33 AM      
        I need to open an existing PDF file and add some text to it. Is this possible using PDF::Writer?