imedo Development Blog

there is no charge for awesomeness

Archive for the ‘pdf’ tag

PDF2PNG – PDF Thumbnail Generator Script

without comments

If you need to generate thumbnails of the first pages of alot of PDF documents you can use this tiny ruby script:
http://bit.ly/8T0B1a
I also included smusher support to crush the PNGs after they were created. Just gem install smusher and uncomment the smusher command.

Enjoy!

Popularity: 1% [?]

Written by mscherf

December 10th, 2009 at 12:07 pm

Posted in Development

Tagged with , , ,

Testing PDF generation

without comments

Generating PDFs in a Rails application is a fairly common task. Maybe you want to create a letter, report, document or maybe an invoice. Either way the stuff that normally ends up in an PDF is important and you want to make sure the right stuff ends up there.

This pretty much sounds like a case for automated testing. But how do you test PDF content? One option would be to generate the PDF and then create a HTML out of the PDF using pdftohtml, parse the HTML and make some assertions. As you can guess, this approach isn’t very feasable, because the generated HTML isn’t very easy to parse.

Most of the time PDF generation in Rails applications is done using the RTex Plugin – the PDF is generated via LaTeX. This makes testing a lot easier because you can just parse and check the generated LaTeX-Source.

Everyone how has seen a LaTeX source file may ask: How the hell do I parse that?

In our case we added some “helper” comments like ”% SUM BEGIN” and ”% SUM END” before and after the part we were interested in and then used basic RegEx to parse out the interesting part. You have to manually check that the markup still looks as expected due to the newline handling of LaTeX (one is ok, two = new paragraph). Most of the time it is sufficient to look for ERB-Tags and use < %- instead of < %.

This approach works pretty well for us. One question which you should always keep in mind when you write tests is: What do I test on this level of testing and what do I leave out.

For the PDF/LaTeX-Testcase we choose to test the basic interaction between the objects that provide values for the PDF generation and the Template. We don’t test all combinations, just a few basic cases. Testing all or at least a lot of combinations, edge cases etc. is clearly a concern of unit tests.

Popularity: 1% [?]

Written by hvolkmer

August 6th, 2009 at 6:52 am

Posted in Testing

Tagged with , ,

Awesome Email Presentation

without comments

As requested here is the presentation for our awesome email plugin:

Slides

Rails Awesome Email

View SlideShare presentation (tags: ruby on rails ror)

Popularity: 1% [?]

Written by mscherf

August 11th, 2008 at 11:03 pm