在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Using HTMLDOCThe sample code below requires HTMLDOC.
If you’re using Windows, you may have problems unless you add the following after generator = IO.popen….
PdfWriterAlternatively if you want more control over where everything is written/drawn onto the page James Hollingshead has put some code up at http://www.hollo.org/pdfwriter . It also generates everything in a single pass so no need for temporary files. It is very lightweight and all in a single file that can be copied to the lib directory and required. Using it is as simple as:
PDF::Writer (Austin Ziegler)http://rubyforge.org/projects/ruby-pdf/ (Instructions updated by Austin Ziegler.) Install PDF::Writer (and dependencies) with \RubyGems:
One way is to create a .pdf file in public/pdf and send it to the browser with a redirect, as shown below:
Alternately, generate the document and send it directly to the browser:
This is the preferred way to send documents, as the documents will be sent inline and two requests won’t step on each others’ generated documents. There will be further details on what is possible in an upcoming Ruby Code & Style article that I’m writing. Another alternative method is to create a template handler to handle, say,
in your
And in your
If you want to use ActionView helpers via this method, just use the @action_view instance variable:
Check you’re not using a layout for actions rendering an rpdf template
If you would like to have the user prompted to download the file instead of displaying it within the window (can be useful for handling validation prior to download), then add the following to your PDFRender class:
Ruby FPDFAn other alternative is Ruby FPDF, a port of PHP FPDF. It’s just one small Ruby file, which can be dropped in your Rails application “lib” folder. Download at http://brian.imxcc.com/fpdf/ (moved to http://zeropluszero.com/software/fpdf/ ?). Many examples, plus a font generator, are included.
Here is an example of using content stored in a database and generating a PDF with FPDF. Fpdf::Table allows easy adding tables to Ruby FPDF. JasperReportsJasperReports is a powerful—and even more important—well known open source Java reporting tool that has the ability to deliver rich content in formats such as PDF, RTF, HTML, CSV and XML. Read HowtoIntegrateJasperReports into Rails. NotesHeaders for Internet ExplorerNote
that you may have to play around a bit to get send_data to work with
Internet Explorer. The following lines worked wonders for me (see the API docs for more info on
Do not use a layoutIf you are not using
PDF Form FillUsing all the tools listed above to create a nice looking pdf file will take you a lot of time to learn how to do. The easier way is to create a form using Adobe Acrobat. Simply use the text field tool to create where dynamic text should be entered in at and give them variable names. Now use this script to create an FDF compatible file… def createFDF(info) This function will return your fdf temp file, Now to enter that info into a pdf you will need pdftk found at http://www.accesspdf.com/pdftk/ Once that is installed you can do something like this… u = User.find(:first) Next just pass the pdf_output to the browser for the user to get the pdf file, or save it in the database. Happy hacking! – Chief PDFlib and PDFlib-LitePDFlib newest release contains Ruby bindings. PDFlib and PDFlib-Lite is one of the fastest PDF generation libraries in production. This is a commercial library though (unless you meet their strict requirements for their opensource license). For installation and usage information, you can view this 2 part series by Bob Silva Generating PDFs in Rails – Part I – Installing Comments: Comments: Rfpdf PluginI am a long time user of PDFlib. When I started working with Ruby on Rails, like Ruby on Rails I searched for a free PDF capable solution. I tried RTex with mixed results – sometimes it worked sometimes it didn’t. Then I found Ruby on FPDF. I have been very pleased. I did like the template view capability of RTex, which accommodated embedding the ruby code in files with .rtex extensions. I also had a client that needed Chinese, Japanese and Korean support. These languages were supported in the PHP version of FPDF but only Chinese had been ported and that port didn’t work properly so I spent the weekend porting these three languages to Ruby from PHP. The Rfpdf Plugin incorporates: Ruby FPDF, e-ruby template view support (.rfpdf files) and additional Asian support for Chinese, Japanese and Korean languages. Download it at http://rubyforge.org/projects/rfpdf/ or see From: http://wiki.rubyonrails.com/rails/pages/HowtoGeneratePDFs |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论