# Pdf::Writer and #image

**URL:** <https://www.ruby-forum.com/t/pdf-writer-and-image/51546>\
**Category:** Rails\
**Created:** [January 2, 2006, 10:31pm UTC](https://www.ruby-forum.com/t/pdf-writer-and-image/51546 "2006-01-02T22:31:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [January 2, 2006, 10:31pm UTC](https://www.ruby-forum.com/t/pdf-writer-and-image/51546/1 "2006-01-02T22:31:29Z")

</div>

Greetings all - happy new year,

I’m having problems getting Pdf::Writer image insertion.

pdf.image “/path/to/images/logo.jpg”

is firing “JPEG marker not found!”

Originally created the RGB (8 bit) JPEG in photoshop. After the above,  
I’ve exported with an alternate tool using (OSX) preview.

This tutorial  
[http://www.artima.com/rubycs/articles/pdf\_writer2.html](http://www.artima.com/rubycs/articles/pdf_writer2.html)  
says that CMYK or RGB encoding is needed - so that’s not the problem.  
Other than that requirement, are there others?

Optionally I tried PNG, but this resulted in a nil.unpack error (‘The  
error occured while evaluating nil.unpack’)

I’ve now run out of file types. harumph!

Secondary question, how do I reference a relative path to the file  
(/images and …/images/file don’t work) ? Or perhaps a way to find the  
server root path from the os?

Thanx for any pointers.

---

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [January 2, 2006, 11:39pm UTC](https://www.ruby-forum.com/t/pdf-writer-and-image/51546/2 "2006-01-02T23:39:46Z")

</div>

On 02/01/06, Jodi S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Greetings all - happy new year,
> 
> I’m having problems getting Pdf::Writer image insertion.
> 
> pdf.image “/path/to/images/logo.jpg”
> 
> is firing “JPEG marker not found!”

You’re using the natively built Ruby for OS X. It is known to be  
broken. Install one from darwinports, fink, or build your own.

> Secondary question, how do I reference a relative path to the file  
> (/images and …/images/file don’t work) ? Or perhaps a way to find the  
> server root path from the os?

That will be something that the Rails people will have to deal with.  
PDF::Writer will work from the current working directory, and that may  
not be what you think it is in the file you’re dealing with.

## -austin

Austin Z. \* removed\_email\_address@domain.invalid  
\* Alternate: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [January 3, 2006, 12:00am UTC](https://www.ruby-forum.com/t/pdf-writer-and-image/51546/3 "2006-01-03T00:00:56Z")

</div>

On 1/2/06, Jodi S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Secondary question, how do I reference a relative path to the file  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

There are some JPEG variations such as JPEG2000 and progressive JPEG  
that are not quite universally supported. Check to make sure your  
JPEG isn’t progressive. This is general advice, because I don’t know  
PDF::Writer. Your problem may very well be something else.

For relative paths, I use File.join RAILS\_ROOT, “path”, “to”, “file”

–  
Kyle M.  
Chief Technologist  
E Factor Media // FN Interactive  
removed\_email\_address@domain.invalid  
1-866-263-3261

---

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [January 3, 2006, 4:50am UTC](https://www.ruby-forum.com/t/pdf-writer-and-image/51546/4 "2006-01-03T04:50:38Z")

</div>

Austin:

> You’re using the natively built Ruby for OS X. It is known to be  
> broken. Install one from darwinports, fink, or build your own.

&&

Kyle:

> I use File.join RAILS\_ROOT, “path”, “to”, “file”

YES! Thank you both. Hours later, and much googling, gem updates, and  
tada.

Logo in my report header!

Good nite.  
Jodi
