WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

wbconvert2pdfcreator


;' Convert2PDF script   --> wbConvert2PDFcreator.wbt
;' Part of PDFCreator
;' License: GPL
;' Homepage: http://www.sourceforge.net/projects/pdfcreator
;' Version: 1.0.0.0
;' Date: September, 1. 2005
;' Author: Frank Heindörfer
;' Comments: This script convert a printable file in a pdf-file using
;'           the com interface of PDFCreator.
;
; Ported to winbatch 2006A, jan, 2006 by J.W. Teunisse (info@mitc.nl, www.mitc.nl) Date: 1-MAR-2006
;
; the script converts a document (word or other) to PDF using PDFCreator (see Sourceforge.ent)
; the orginal whs script is commented out
;
; Dutch: het WHS script converteert een document naar de PDF formaat, daarvoor wordt 1 of meer filenamen gelezen vanaf de commandline
;
;---------- UDS PDFCreator events handling ------------
#DefineSubRoutine PDFCreator_eReady()    ; event handling printing is ready/finished
  ReadyState = 1
  Return
#EndSubRoutine

#DefineSubRoutine PDFCreator_eError()     ; event handling error-control, see PDFCreator Help file
; MsgBox "An error is occured!" & vbcrlf & vbcrlf & _
;  "Error [" & PDFCreator.cErrorDetail("Number") & "]: " & PDFcreator.cErrorDetail("Description"), vbCritical + vbSystemModal, AppTitle
; Wscript.Quit
  eNumber = oPDFC.cErrorDetail("Number")
  eDetail = oPDFC.cErrorDetail("Description")
  Message("wbConvert2PDF Error-control",StrCat("Error [%eNumber%]:", eDetail,@CRLF,"This script stops!!"))
  Exit
  Return
#EndSubRoutine

;---- start main body -----
maxTime = 30    ;' in seconds
sleepTime = 250 ;' in milliseconds
fnaam = "your_document.doc"             ;; Word document
in_dir = "d:\your_input_directory"       ;; input directory
out_dir = "d:\your_output_directory"    ;; output directory
indocfnaam = StrCat(in_dir,fnaam)
;
IntControl(73, 2, 0, 0, 0)                ; wb Error handling
;
;;PDFCreator = CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")
If AppExist("PDFCreator.exe")
  oPDFC  = ObjectGet("PDFCreator.clsPDFCreator")
  newPDFC = @FALSE
Else
  oPDFC  = ObjectCreate("PDFCreator.clsPDFCreator")
  newPDFC = @TRUE
EndIf
;-------- WHS script -------
;;Set PDFCreator = Wscript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")
;;PDFCreator.cStart "/NoProcessingAtStartup"
;;With PDFCreator
;; .cOption("UseAutosave") = 1
;; .cOption("UseAutosaveDirectory") = 1
;; .cOption("AutosaveFormat") = 0                              ' 0 = PDF
;; DefaultPrinter = .cDefaultprinter
;; .cDefaultprinter = "PDFCreator"
;; .cClearcache
;;End With
;------------ here under the winbatch code -------
bstart = oPDFC.cStart("/NoProcessingAtStartup")
oOption1 = ObjectCreate("PDFCreator.clsPDFCreatorOptions")
oError = ObjectCreate("PDFCreator.clsPDFCreatorError")
lAutosave = oPDFC.cOption("UseAutosave")
sAutoSaveDir = oPDFC.cOption("AutosaveDirectory")
sStrUseAutoSave = ObjectType("BSTR","UseAutosave")         ;; this is Winbatch function to create a COM/OLE variable
oPDFC.cOption("UseAutosave") = 1
    ;;oPDFC.cOption(sStrUseAutoSave) = 1
oPDFC.cOption("UseAutosaveDirectory") = 1
opDFC.cOption("AutosaveFormat") = 0                              ;;' 0 = PDF format
lFSOT = oPDFC.cOption("FilenameSubstitutionsOnlyInTitle")
oPDFC.cOption("FilenameSubstitutionsOnlyInTitle")= 0   ; no substitution
DefaultPrinter = opDFC.cDefaultprinter
opDFC.cDefaultprinter = "PDFCreator"
opDFC.cClearcache
oPDFReady=oPDFC.cTestEvent("Ready")
oPDFError=oPDFC.cTestEvent("Error")
oPDFUnknown=oPDFC.cTestEvent("Unknown")
ok = objecteventadd(oPDFC,"eReady", "PDFCreator_eReady")
ok = objecteventadd(oPDFC,"eError", "PDFCreator_eError")
;ok = objecteventadd(oPDFC,"eUnknown", "PDFCreator_eError")   ; not tested, comes from script Testevents.vbs
;
;For i = 0 to objArgs.Count - 1
;  With PDFCreator
;  ifname = objArgs(i)
;  If Not fso.FileExists(ifname) Then
;   MsgBox "Can't find the file: " & ifname, vbExclamation + vbSystemModal, AppTitle
;   Exit For
;  End If
;  if Not .cIsPrintable(CStr(ifname)) Then
;   MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
;    "An error is occured: File is not printable!", vbExclamation + vbSystemModal, AppTitle
;   WScript.Quit
;  End if
sInDocFnaam = ObjectType("BSTR",indocfnaam)
lDocPrintable = oPDFC.cIsPrintable(sInDocFnaam)
If lDocPrintable == @FALSE Then
;   MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
;    "An error is occured: File is not printable!", vbExclamation + vbSystemModal, AppTitle
; schrijf foutregel
   Message("scriptname",StrCat("An error is occured: File is not printable! ", indocfnaam))
   Exit  ; script
End If  ; not Doc. Printable

  ReadyState = 0
  OutFnaam = FileRoot(indocfnaam)
  sOutFnaam = ObjectType("BSTR",OutFnaam)
  sOutDirFnaam = ObjectType("BSTR", StrCat(out_dir,OutFnaam))
  oPDFC.cOption("AutosaveDirectory") = out_dir
  oPDFC.cOption("AutosaveFilename") = sOutFnaam
  oPDFC.cOption("SaveFilename") = sOutDirFnaam
  oPDFC.cPrintfile(sInDocFnaam)
  lPrtStop =oPDFC.cPrinterStop
  oPDFC.cPrinterStop = @FALSE

  c = 0
  d = maxTime * 1000 / sleepTime
  While (ReadyState == 0) && (c < d)
     c = c + 1
     TimeDelay(sleepTime/1000)
  EndWhile
  If ReadyState == 0 Then
     Message("wbCOnvert2PDF Converting: ", "An error is occured: Time is up!")
  End If
; End With
;Next   ; for argumenten commandline
TimeDelay(1)  ; wait 1-2 seconden

;With PDFCreator
; .cDefaultprinter = DefaultPrinter
; .cClearcache
; WScript.Sleep 200
; .cClose
;End With
  oPDFC.cDefaultprinter = DefaultPrinter
  oPDFC.cClearcache
  TimeDelay(1)         ;; wait a second
; start cleaning up
ok = objecteventremove(oPDFC,"eReady")
ok = objecteventremove(oPDFC,"eError")
oPDFReady = 0   ; closeobject
oPDFError = 0
oPDFUnknown = 0
oError = ""   ; closeobject
oOption1 = ""
oPDFC = ""
Exit

;'--- PDFCreator events --- see UDS -----------
;
;Public Sub PDFCreator_eReady()
; ReadyState = 1
;End Sub

;Public Sub PDFCreator_eError()
; MsgBox "An error is occured!" & vbcrlf & vbcrlf & _
;  "Error [" & PDFCreator.cErrorDetail("Number") & "]: " & PDFcreator.cErrorDetail("Description"), vbCritical + vbSystemModal, AppTitle
; Wscript.Quit
;End Sub

:wbErrorhandling
; error handling
Message("wbConvert2PDF Error","??:which one??")
Return

Article ID:   W17243
File Created: 2007:07:03:14:28:58
Last Updated: 2007:07:03:14:28:58