Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
How to create PDF documents from MS word doc using Ruby
Talib Hussain
12/15/2008 11:02:00 AM
Hi Experts,
Could you please tell me how to create PDF documents from MS word doc
using Ruby?
I have no. of documents (Word Files) which I need to convert to .PDF.
TIA,
Talib Hussain
--
Posted via
http://www.ruby-...
.
2 Answers
Heesob Park
12/15/2008 1:49:00 PM
0
2008/12/15 Talib Hussain <talibhn@gmail.com>:
> Hi Experts,
>
> Could you please tell me how to create PDF documents from MS word doc
> using Ruby?
>
> I have no. of documents (Word Files) which I need to convert to .PDF.
>
1. Download and install PDFCreator (
http://www.pdfforge.org/products/...
)
2. Save the following code as word2pdf.rb and run "ruby word2pdf.rb *.doc"
# adopted from PDFCreator COM Ruby sample code by Frank Heind?fer
require 'win32ole'
pdfcreator = WIN32OLE.new('PDFCreator.clsPDFCreator')
event = WIN32OLE_EVENT.new(pdfcreator)
event.on_event('eReady') do
$readyState = 1
end
pdfcreator.cStart('/NoProcessingAtStartup')
pdfcreator.setproperty('cOption', 'UseAutosave', 1)
pdfcreator.setproperty('cOption', 'UseAutosaveDirectory', 1)
pdfcreator.setproperty('cOption', 'AutosaveFormat', 0) # 0 = PDF
pdfcreator.cClearCache()
pdfcreator.setproperty('cPrinterStop', false)
word = WIN32OLE.new('word.application')
word.activeprinter = 'PDFCreator'
ARGV.each do |file|
pdfcreator.setproperty('cOption', 'AutosaveDirectory', File.dirname(file))
pdfcreator.setproperty('cOption', 'AutosaveFilename',
File.basename(file, File.extname(file)))
file = file.gsub('/','\\')
if !FileTest.exist?(file) then
print 'Can''t find the file: ', file
break
end
doc = word.documents.open(file,'ReadOnly' => true)
$readyState = 0
word.printout
while $readyState==0
pdfcreator.cOption('UseAutosave')
sleep 1
end
word.activedocument.close(false)
end
word.quit
pdfcreator.cClearCache()
pdfcreator.cClose()
HTH,
Park Heesob
Talib Hussain
12/16/2008 6:36:00 AM
0
Heesob Park wrote:
> 2008/12/15 Talib Hussain <talibhn@gmail.com>:
>> Hi Experts,
>>
>> Could you please tell me how to create PDF documents from MS word doc
>> using Ruby?
>>
>> I have no. of documents (Word Files) which I need to convert to .PDF.
> end
>
>
> HTH,
>
> Park Heesob
Thanks a lot
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
How to create PDF documents from MS word doc using Ruby
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password