# How to use WIN32OLE to Save As PDF

**URL:** <https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117>\
**Category:** Ruby\
**Created:** [January 22, 2010, 8:08pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117 "2010-01-22T20:08:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 22, 2010, 8:08pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/1 "2010-01-22T20:08:10Z")

</div>

Hi,

I’ve been trying to figure out how to use Win32OLE to save as a PDF. It  
doesn’t seem like there’s any good documentation on how to do this, so I  
was hoping someone here has experience with this.

Anyhoo, if anyone’s tried this before, and actually gotten somewhere  
with it, please let me know.

Thanks

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 22, 2010, 8:23pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/2 "2010-01-22T20:23:04Z")

</div>

On Jan 22, 2:08 pm, Joe P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted viahttp://www.ruby-forum.com/.

Ever look at this?

[http://ruby-pdf.rubyforge.org/pdf-writer/](http://ruby-pdf.rubyforge.org/pdf-writer/)

Seems like it’d be straightforward, at least moreso than digging into  
all of the OLE stuff…

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 22, 2010, 8:27pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/3 "2010-01-22T20:27:38Z")

</div>

Greg Kujawa wrote:

> Ever look at this?
> 
> [http://ruby-pdf.rubyforge.org/pdf-writer/](http://ruby-pdf.rubyforge.org/pdf-writer/)
> 
> Seems like it’d be straightforward, at least moreso than digging into  
> all of the OLE stuff…

Yeah, I’ve seen that. I just figure there has to be a way to save  
directly as a PDF using WIN32OLE. If only there was like a list of  
FileFormats that it uses…

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 22, 2010, 8:45pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/4 "2010-01-22T20:45:55Z")

</div>

On Fri, Jan 22, 2010 at 2:20 PM, gregarican [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Jan 22, 2:08 pm, Joe P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ever look at this?
> 
> [http://ruby-pdf.rubyforge.org/pdf-writer/](http://ruby-pdf.rubyforge.org/pdf-writer/)

Please don’t use PDF::Writer anymore. If you need pure Ruby PDF  
generation, Prawn is the way to go.  
If there are features that are holding you back, let us know.

(Disclosure: I am the maintainer of Prawn and the ‘if all hell breaks  
loose’ maintainer of PDF::Writer (originally written by Austin  
Ziegler) )

-greg

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 22, 2010, 8:47pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/5 "2010-01-22T20:47:40Z")

</div>

On 22.01.2010 20:27, Joe P. wrote:

> Yeah, I’ve seen that. I just figure there has to be a way to save  
> directly as a PDF using WIN32OLE.

Only if an OLE capable tool is installed that a) accepts your input and  
b) writes PDF (for example, OO.o Writer, or MS Word 2007).

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 22, 2010, 9:05pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/6 "2010-01-22T21:05:03Z")

</div>

Alrighty, so I figured it out.

It turns out 17 is the FormatType for PDF, so you just have to do  
something like this:

document.SaveAs(filename, 17)

I didn’t see any documentation about this, but we just started going up  
from 0 as a FormateType, and once we hit 17, it made a valid PDF!!

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 22, 2010, 9:18pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/7 "2010-01-22T21:18:07Z")

</div>

On Fri, Jan 22, 2010 at 3:05 PM, Joe P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Alrighty, so I figured it out.
> 
> It turns out 17 is the FormatType for PDF, so you just have to do  
> something like this:
> 
> document.SaveAs(filename, 17)

FormatType for what? You never mentioned what program you’re using  
via win32ole (i’m assuming MS Office?). In the future, be sure to do  
that so that people know what you’re talking about.

-greg

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 25, 2010, 2:20pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/8 "2010-01-25T14:20:29Z")

</div>

> FormatType for what? You never mentioned what program you’re using  
> via win32ole (i’m assuming MS Office?). In the future, be sure to do  
> that so that people know what you’re talking about.
> 
> -greg

Sorry. Yeah, I’m using MS Office through win32ole.

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 25, 2010, 8:59pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/9 "2010-01-25T20:59:22Z")

</div>

In case anyone else is searching for how to use win32ole to save as a  
PDF, Mr. Mullet posted some nice instructions here:

> **[Saving Microsoft Office Documents as PDFs](http://rubyonwindows.blogspot.com/2010/01/saving-microsoft-office-documents-as.html)**
>
> A recent discussion in the Ruby Forum reminded me that it is possible with Microsoft Office 2007 applications to save a document in Adobe PD...

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 26, 2010, 11:11pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/10 "2010-01-26T23:11:21Z")

</div>

Joe P. wrote:

> In case anyone else is searching for how to use win32ole to save as a  
> PDF, Mr. Mullet posted some nice instructions here:  
> [Ruby on Windows: Saving Microsoft Office Documents as PDFs](http://rubyonwindows.blogspot.com/2010/01/saving-microsoft-office-documents-as.html)

To can save office 2007 documents to pdf format you have to download the  
free ms plugin, google =\> ‘pdf plugin office 2007’

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 23, 2010, 3:23pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/11 "2010-01-23T15:23:04Z")

</div>

Gregory B. wrote:

> On Fri, Jan 22, 2010 at 2:20 PM, gregarican [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > On Jan 22, 2:08ï¿½pm, Joe P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> > Ever look at this?
> > 
> > [http://ruby-pdf.rubyforge.org/pdf-writer/](http://ruby-pdf.rubyforge.org/pdf-writer/)  
> > Please don’t use PDF::Writer anymore. If you need pure Ruby PDF  
> > generation, Prawn is the way to go.  
> > If there are features that are holding you back, let us know.
> 
> (Disclosure: I am the maintainer of Prawn and the ‘if all hell breaks  
> loose’ maintainer of PDF::Writer (originally written by Austin  
> Ziegler) )

What Greg said.

-austin

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 27, 2010, 12:11pm UTC](https://www.ruby-forum.com/t/how-to-use-win32ole-to-save-as-pdf/182117/12 "2010-01-27T12:11:54Z")

</div>

On 26.01.2010 23:12, Marco M. wrote:

> To can save office 2007 documents to pdf format you have to download the  
> free ms plugin, google =\> ‘pdf plugin office 2007’

Better way: install Office 2007 Service Pack 2, which includes the  
functionality.

> **[Microsoft Support](https://support.microsoft.com/en-us/?scid=kb%3Ben-us%3B953195&x=8&y=10)**
>
> Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.
