# PDF::Writer, embedding non-PNGs

**URL:** <https://www.ruby-forum.com/t/pdf-writer-embedding-non-pngs/123627>\
**Category:** Ruby\
**Created:** [December 19, 2007, 10:12am UTC](https://www.ruby-forum.com/t/pdf-writer-embedding-non-pngs/123627 "2007-12-19T10:12:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [December 19, 2007, 10:12am UTC](https://www.ruby-forum.com/t/pdf-writer-embedding-non-pngs/123627/1 "2007-12-19T10:12:59Z")

</div>

Hi,

the PDF::Writer documentation reads:

add\_image(image, x, y, …)

Add an image from a loaded image (JPEG or PNG) resource …  
^^^^ ^^^

The image I want to embed is in PostScript. In concrete, it is the  
output of the GNU barcode tool.

Is there any smarter way to embed it than to convert it to a pixel image  
without knowing the printers resolution?

Thanks in advance,

Bertram

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [December 19, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/pdf-writer-embedding-non-pngs/123627/2 "2007-12-19T12:27:52Z")

</div>

-------- Original-Nachricht --------

> Datum: Wed, 19 Dec 2007 18:11:33 +0900  
> Von: Bertram S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: PDF::Writer, embedding non-PNGs

> ## The image I want to embed is in PostScript. In concrete, it is the
> 
> Bertram S.  
> Stuttgart, Deutschland/Germany  
> [http://www.bertram-scharpf.de](http://www.bertram-scharpf.de)

Dear Bertram,

from PDF::Writer’s documentation,

([artima - Creating Printable Documents with Ruby](http://www.artima.com/rubycs/articles/pdf_writerP.html) and  
Changelog in pdf-writer-1.1.7)

it seems that it doesn’t yet support any vector graphics or eps file  
support.  
An alternative, – non-Ruby – way would be to use latex to embed eps  
files and create a pdf from there, modifying the template.tex  
file with the entries for creating images, given in this tutorial:

[http://www.pages.drexel.edu/~pyo22/students/latexRelated/latexTutorial.html](http://www.pages.drexel.edu/~pyo22/students/latexRelated/latexTutorial.html)

That webpage is now a bit dated, so for the installation of latex,  
I’d rather recommend this:

[http://scripts.sil.org/cms/scripts/page.php?site\_id=nrsi&id=xetex](http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=xetex)

Use the command ‘xelatex’ from the xetex package on the source file  
created. I think it will output a pdf straight away.

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [December 19, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/pdf-writer-embedding-non-pngs/123627/3 "2007-12-19T14:11:46Z")

</div>

On 12/19/07, Bertram S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> One further way failed as well: I found a Code39 barcode font on the web  
> as a TrueType font. Trying to embed it as described in the manual yields  
> the fatal message:
> 
> /usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3/lib/pdf/writer.rb:878:in `load_font': undefined local variable or method `fbfile’ for #PDF::Writer:0xb788ad6c (NameError)

PDF::Writer 1.1.3 is not the most recent version. I believe that Greg  
and Michael fixed some font bugs.

Your expectation (of being able to embed EPS or another PDF) is  
unrealistic given the reality of the internal implementation of PDF.  
If you can grab the drawing instructions from an EPS (not hard, and  
can be programmed), you can insert them directly into an object stream  
on a PDF. (I’ve actually done this, manually.)

-austin

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [December 21, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/pdf-writer-embedding-non-pngs/123627/4 "2007-12-21T17:55:42Z")

</div>

Hi,

Am Mittwoch, 19. Dez 2007, 22:10:53 +0900 schrieb Austin Z.:

> On 12/19/07, Bertram S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > One further way failed as well: I found a Code39 barcode font on the web  
> > as a TrueType font. Trying to embed it as described in the manual yields  
> > the fatal message:
> > 
> > /usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3/lib/pdf/writer.rb:878:in `load_font': undefined local variable or method `fbfile’ for #PDF::Writer:0xb788ad6c (NameError)
> 
> PDF::Writer 1.1.3 is not the most recent version. I believe that Greg  
> and Michael fixed some font bugs.

Sorry, both Gentoo and FreeBSD install 1.1.3 by default.

./local/gems/pdf-writer-1.1.7/lib/pdf/writer.rb:844:in `load_font': undefined local variable or method `fbfile’ for  
#PDF::Writer:0xb77e2400 (NameError)

Bertram

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [December 19, 2007, 1:52pm UTC](https://www.ruby-forum.com/t/pdf-writer-embedding-non-pngs/123627/5 "2007-12-19T13:52:26Z")

</div>

Hi,

Am Mittwoch, 19. Dez 2007, 20:26:57 +0900 schrieb Axel E.:

> > The image I want to embed is in PostScript. In concrete, it is the  
> > output of the GNU barcode tool.
> > 
> > Is there any smarter way to embed it than to convert it to a pixel image  
> > without knowing the printers resolution?
> 
> it seems that it doesn’t yet support any vector graphics or eps file support.  
> An alternative, – non-Ruby – way would be to use latex to embed eps  
> files and create a pdf from there, modifying the template.tex  
> file with the entries for creating images, given in this tutorial:

This is very disappointing. I expected it were at least possible to  
embed another PDF document on the page.

One further way failed as well: I found a Code39 barcode font on the web  
as a TrueType font. Trying to embed it as described in the manual yields  
the fatal message:

/usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3/lib/pdf/writer.rb:878:in  
`load_font': undefined local variable or method`fbfile’ for  
#PDF::Writer:0xb788ad6c (NameError)

This seems to be a severe bug as the variable `fbfile’ doesn’t appear  
anywhere else in the whole /usr/lib/ruby tree.

It seems that TeX still remains the only real typesetting system.

Bertram
