0

ruby, PDFCreator, Microsoft Office 및 OpenOffice와 함께 Windows Web Server 2008을 사용하여 파일을 PDF로 자동 변환합니다. 설치 프로그램은 Microsoft Office 파일에서는 정상적으로 작동하지만 OpenOffice 파일 (예 : .sxw)과 함께 자동으로 작동하지는 못합니다. PDFCreator 수동으로 할 때 .sxw 파일을 문제없이 변환 할 수 있지만 아래의 내 루비 스크립트로 시도 할 때 다음 오류가 throw됩니다.OpenOffice 파일이있는 PDFCreator

오류 : 1 설명 : ActiveX 서버가 시작되지 않았습니다! ActiveX 서버를 시작하려면 \ "cStart() \"함수를 사용하십시오!

def convert(filename, data) 
    require 'win32ole' 

    dirpath = File.join('/', 'files') 
    filepath = File.join(dirpath, filename) 
    puts filepath 
    filepath_out = File.join(dirpath, 'output.pdf') 
    begin 
    File.open(filepath, 'wb+') { |f| f.write(data) } 
    puts File.exists?(filepath).inspect 
    pdfcreator = WIN32OLE.new('PDFCreator.clsPDFCreator') 
    event = WIN32OLE_EVENT.new(pdfcreator) 
    event.on_event('eReady') do 
     File.open(filepath_out, 'rb') { |f| update_attribute(:data_converted, f.read) } 
     $printed = true 
    end 
    event.on_event('eError') do 
     pdfcreator.cClose() 
     raise 'error' 
    end 
    if !pdfcreator.cIsPrintable(filepath) 
     raise 'error' 
    end 
    pdfcreator.cStart('/NoProcessingAtStartup') 
    pdfcreator.setproperty('cOption', 'UseAutosave', 1) 
    pdfcreator.setproperty('cOption', 'UseAutosaveDirectory', 1) 
    pdfcreator.setproperty('cOption', 'AutosaveFormat', 0) 
    pdfcreator.setproperty('cDefaultprinter', 'PDFCreator') 
    pdfcreator.cClearCache() 
    pdfcreator.setproperty('cPrinterStop', false) 
    pdfcreator.setproperty('cOption', 'AutosaveDirectory', File.dirname(filepath_out)) 
    pdfcreator.setproperty('cOption', 'AutosaveFilename', File.basename(filepath_out)) 
    $printed = false 
    pdfcreator.cPrintfile("C:\\files" + File.basename(filepath)) 
    started_at = Time.new 
    loop { 
     pdfcreator.cOption('UseAutosave') # noop to get ready event 
     break if $printed 
     if (Time.new - started_at)>TIMEOUT 
      raise 'timeout' 
     end 
     sleep 0.5 
    } 
    rescue => e 
    raise e 
    ensure 
    begin 
     pdfcreator.cClearCache() 
     pdfcreator.cClose() 
    rescue 
    end 
    begin 
     File.delete(filepath) if File.exists?(filepath) 
     File.delete(filepath_out) if File.exists?(filepath_out) 
    rescue 
    end 

    end 

아이디어가 있으십니까?

감사합니다, Peder

답변

0

이상한. 이제 작동 중입니다!

1

이 스크립트는 cIsPrintable을 호출하고 Windows 레지스트리에서 "인쇄"명령을 검색합니다.

Windows 레지스트리에이 명령을 작성한 이유가 뭔가 설치되어 있어야하며 이제는 작동합니다.