# Adding image in pdf using pdf writer

**URL:** <https://www.ruby-forum.com/t/adding-image-in-pdf-using-pdf-writer/164935>\
**Category:** Rails\
**Created:** [April 7, 2009, 4:42pm UTC](https://www.ruby-forum.com/t/adding-image-in-pdf-using-pdf-writer/164935 "2009-04-07T16:42:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [April 7, 2009, 4:42pm UTC](https://www.ruby-forum.com/t/adding-image-in-pdf-using-pdf-writer/164935/1 "2009-04-07T16:42:42Z")

</div>

Hi,

I am using this code, but I am not able to add the image in pdf using  
pdf writer.  
Is there any wrong with code?

def pdf1  
\_pdf = PDF::Writer.new  
\_pdf.select\_font “Times-Roman”  
\_pdf.text “Hello, Ruby.”, :font\_size =\> 72, :justification =\>  
:center  
\_pdf.image “[http://localhost:3001/images/rails.png](http://localhost:3001/images/rails.png)”  
send\_data \_pdf.render, :filename =\> “hello.pdf”,  
:type =\> “application/pdf”  
end  
I am getting this error:-  
“PNG alpha channel transparency is not supported; only palette  
transparency is supported.”

Please help me to solve this problem.

Thanks,  
Tushar

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [April 7, 2009, 5:30pm UTC](https://www.ruby-forum.com/t/adding-image-in-pdf-using-pdf-writer/164935/2 "2009-04-07T17:30:39Z")

</div>

Pretty straightforward error. You need to make sure you’re using a PNG  
without alpha-transparency (24-bit uses them, 8-bit doesn’t.)

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [April 8, 2009, 6:48am UTC](https://www.ruby-forum.com/t/adding-image-in-pdf-using-pdf-writer/164935/3 "2009-04-08T06:48:28Z")

</div>

Jack B. wrote:

> Pretty straightforward error. You need to make sure you’re using a PNG  
> without alpha-transparency (24-bit uses them, 8-bit doesn’t.)

Hi,  
Is there no way to support those images?  
Thanks,  
Tushar
