Jump to content

PDFCreator - Print2PDF


ptrex
 Share

Recommended Posts

  • 9 months later...

hey mates,

i use this udf for pdfs but my problem was how i can skip the "exit" in the script i dont want to exit my script after pdfing:

; Convert2PDF script
; Part of $PDFCreator
; License: GPL
; Homepage: http://www.sf.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.

; Translated by ptrex
GLobal $File
GLobal $count


Const $maxTime = 30  ; in seconds
Const $sleepTime = 250; in milliseconds

Dim $objArgs, $ifname, $fso, $PDFCreator, $DefaultPrinter, $ReadyState, _
 $i, $c, $AppTitle, $Scriptname, $ScriptBasename

Func _startpdf()
    
$fso = ObjCreate("Scripting.FileSystemObject")



$Scriptname = $fso.GetFileName(@ScriptFullPath)
$ScriptBasename = $fso.GetFileName(@ScriptFullPath)

$AppTitle = "PDF - " & $ScriptBasename

$File = ("C:\Tmp\Speicher1_" & $count & ".xls")

$PDFCreator = ObjCreate("PDFCreator.clsPDFCreator")
$PDFCreator.cStart ("/NoProcessingAtStartup")



With $PDFCreator
 .cOption("UseAutosave") = 1
 .cOption("UseAutosaveDirectory") = 1
 .cOption("AutosaveFormat") = 0             ; 0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII
 $DefaultPrinter = .cDefaultprinter
 .cDefaultprinter = "PDFCreator"
 .cClearcache()
EndWith

; For $i = 0 to $objArgs.Count - 1
 With $PDFCreator
  $ifname = "C:\Tmp\Speicher1_" & $count & ".xls";$objArgs($i)
  If Not $fso.FileExists($ifname) Then
   MsgBox (0,"Error","Can't find the file: " & $ifname & @CR & $AppTitle)

;  exit <---- how i can skip this exit, when i delete it the script doesnt work anymore-----------------------------------------------------------

  EndIf
  If Not .cIsPrintable(String($ifname)) Then
   ConsoleWrite("Converting: " & $ifname & @CRLF & @CRLF & _
    "An error is occured: File is not printable!" & @CRLF &  $AppTitle & @CR)
  EndIf

  $ReadyState = 0
  .cOption("AutosaveDirectory") = $fso.GetParentFolderName($ifname)
  .cOption("AutosaveFilename") = $fso.GetBaseName($ifname)
  .cPrintfile (String($ifname))
  .cPrinterStop = 0

  $c = 0
  Do 
   $c = $c + 1
   Sleep ($sleepTime)
  Until ($ReadyState = 0) and ($c < ($maxTime * 1000 / $sleepTime))
  
  If $ReadyState = 0 then
   ConsoleWrite("Converting: " & $ifname & @CRLF & @CRLF & _
    "An error is occured: File is not printable!" & @CRLF &  $AppTitle & @CR)
;  exit <---- how i can skip this exit, when i delete it the script doesnt work anymore-----------------------------------------------------------
  EndIf
 EndWith
;Next

With $PDFCreator
 .cDefaultprinter = $DefaultPrinter
 .cClearcache()
    Sleep (200)
 .cClose()
EndWith

Endfunc


;--- $PDFCreator events ---

Func PDFCreator_eReady()
 $ReadyState = 1
EndFunc

Func PDFCreator_eError()
 MsgBox(0, "An error is occured!" , "Error [" & $PDFCreator.cErrorDetail("Number") & "]: " & $PDFCreator.cErrorDetail("Description")& @CR)
EndFunc
Edited by Vision
Link to comment
Share on other sites

  • 2 weeks later...

Ptrex,

Thanks for taking the time to convert the scripts. The script kept giving me an error every time, and I'm trying to learn how this COM interface works. Here's what I've found:

right after the instruction to actually produce the output file, (.cPrintfile cStr(ifname)), the original VBScript said:

c = 0

Do While (ReadyState = 0) and (c < (maxTime * 1000 / sleepTime))

c = c + 1

Wscript.Sleep sleepTime

Loop

If ReadyState = 0 then

MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _

"An error is occured: Time is up!", vbExclamation + vbSystemModal, AppTitle

Exit For

End If

So, in human speak: "Keep working (on the "Print" process) until "ReadyState" is no longer zero, or the timeout expires. If the timeout has expired, then display an error."

What I didn't see is how "ReadyState" could ever change, because the only other reference to readystate is in a subroutine:

Public Sub PDFCreator_eReady()

ReadyState = 1

End Sub

But there is no reference to that subroutine anywhere within the script.

Reading the helpfile, I came to understand that pdfcreator.exe, via the COM interface, is capable of calling back to our script saying, "I'm finished" (telling our script to launch subroutine "PDFCreator_eReady()")

In order to make that work, AutoIT must be set to listen for COM events.

So I changed your script in the following way:

I added a "listen for events" line right after the object create:

CODE

$PDFCObject=ObjEvent($PDFCreator,"PDFCreator_") ; Start receiving Events. Don't forget to dim $pdfcobject above.

and i modified the "Do until" statement as follows:

CODE

$c = 0

Do

$c = $c + 1

Sleep ($sleepTime)

Until ($ReadyState <> 0) or ($c >= ($maxTime * 1000 / $sleepTime))

It's working fine for me now. Do I understand this correctly? (Complete code below)

Bob

CODE

AutoItSetOption("MustDeclareVars", 1)

Const $maxTime = 30 ; in seconds

Const $sleepTime = 250 ; in milliseconds

Dim $objArgs, $ifname, $fso, $PDFCreator, $DefaultPrinter, $ReadyState, _

$i, $c, $AppTitle, $Scriptname, $ScriptBasename,$PDFCObject

$fso = ObjCreate("Scripting.FileSystemObject")

$Scriptname = $fso.GetFileName(@ScriptFullPath)

$ScriptBasename = $fso.GetFileName(@ScriptFullPath)

$AppTitle = "PDFCreator - " & $ScriptBasename

$PDFCreator = ObjCreate("PDFCreator.clsPDFCreator")

$PDFCreator.cStart ("/NoProcessingAtStartup")

$PDFCObject=ObjEvent($PDFCreator,"PDFCreator_") ; Start receiving Events.

With $PDFCreator

.cOption("UseAutosave") = 1

.cOption("UseAutosaveDirectory") = 1

.cOption("AutosaveFormat") = 5 ; 0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII

.cOption("BitmapResolution") = 150

.cOption("TiffColorscount") = 2

$DefaultPrinter = .cDefaultprinter

.cDefaultprinter = "PDFCreator"

.cClearcache()

EndWith

; For $i = 0 to $objArgs.Count - 1

With $PDFCreator

$ifname = "C:\ss.rtf" ;$objArgs($i)

If Not $fso.FileExists($ifname) Then

MsgBox (0,"Error","Can't find the file: " & $ifname & @CR & $AppTitle)

Exit

EndIf

If Not .cIsPrintable($ifname) Then

ConsoleWrite("Converting: " & $ifname & @CRLF & @CRLF & _

"An error is occured: File is not printable!" & @CRLF & $AppTitle & @CR)

EndIf

$ReadyState = 0

.cOption("AutosaveDirectory") = $fso.GetParentFolderName($ifname)

.cOption("AutosaveFilename") = $fso.GetBaseName($ifname)

.cPrintfile($ifname)

.cPrinterStop = 0

$c = 0

Do

$c = $c + 1

Sleep ($sleepTime)

Until ($ReadyState <> 0) or ($c >= ($maxTime * 1000 / $sleepTime))

If $ReadyState = 0 then

ConsoleWrite("Converting: " & $ifname & @CRLF & @CRLF & _

"An error is occured: File is not printable!" & @CRLF & $AppTitle & @CR)

Exit

EndIf

EndWith

;Next

With $PDFCreator

.cDefaultprinter = $DefaultPrinter

.cClearcache()

Sleep (200)

.cClose()

EndWith

;--- $PDFCreator events ---

Func PDFCreator_eReady()

$ReadyState = 1

EndFunc

Func PDFCreator_eError()

MsgBox(0, "An error is occured!" , "Error [" & $PDFCreator.cErrorDetail("Number") & "]: " & $PDFCreator.cErrorDetail("Description")& @CR)

EndFunc

Link to comment
Share on other sites

  • 1 year later...

hi sorry for bumping old post.

Anyway I would like to see if you can attach the source code?

Because I can't read your posted code as some part of the code changed into unknown code.

thanks.

I see the same thing, full of "IQèÅÕ½ÐìµÀìQµÀìQµÀìÀÌØíA". Please can the source code be fixed or re posted.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

  • 6 months later...

Hi ptrex, could you please re-upload the UDF ?

Thanks.

PDFCreator in AutoIT

0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII

;Testpage2PDF script
; Part of $PDFCreator
; License: GPL
; Homepage: http://www.sf.net/projects/pdfcreator
; Version: 1.0.0.0
; Date: September, 1. 2005
; Author: Frank Heindörfer
; Comments: Save the test page as pdf-file using the com interface of $PDFCreator.

; Translated by ptrex
oÝ÷ Ù7¬¶ {'§tIPèzÉè¶ÇÚzËZnW¨l¦j§y«­¢+ØìQÍÑÁÉAM¹µ¥°ÍÉ¥ÁÐ(ìAÉнÀÌØíA

ÉѽÈ(ì1¥¹ÍèA0(ì!½µÁè¡ÑÑÀè¼½ÝÝܹ͹¹Ð½Áɽ©Ñ̽ÁÉѽÈ(ìYÉÍ¥½¸èĸÀ¸À¸À(ìÑèMÁѵȰĸÈÀÀÔ(ìÕÑ¡½Èèɹ¬!¥¹ÙÉÈ(ì

½µµ¹ÑÌèMÙÑ¡ÑÍÐÁÌÁµ¥±¹Í¹Ìµ¥°ÕÍ¥¹Ñ¡½´¥¹ÑɽÀÌØíA

Éѽȸ((ìQɹͱÑäÁÑÉà()Õѽ%ÑMÑ=ÁÑ¥½¸ ÅÕ½Ðí5ÕÍѱÉYÉÌÅÕ½Ðì°Ä¤()

½¹ÍÐÀÌØíµáQ¥µôÄÀ쥸ͽ¹Ì)

½¹ÍÐÀÌØíͱÁQ¥µôÈÔÀ쥸µ¥±±¥Í½¹Ì()¥´ÀÌØíͼ°ÀÌØí]Í¡M¡±°°ÀÌØíA

ÉѽȰÀÌØíA

ÉѽÉ=ÁÑ¥½¹Ì°ÀÌØíÕ±ÑAÉ¥¹ÑÈ°ÀÌØíIåMÑÑ°ÀÌØí°|(ÀÌØíÁÁQ¥Ñ±°ÀÌØíMÉ¥Áѹµ°ÀÌØíMÉ¥ÁÑ͹µ((ÀÌØíͼô=©

ÉÑ ÅÕ½ÐíMÉ¥ÁÑ¥¹¹¥±MåÍѵ=©ÐÅÕ½Ðì¤((ÀÌØíMÉ¥ÁÑ͹µôÀÌØíͼ¹Ñ Í9µ¡MÉ¥ÁÑÕ±±AÑ ¤((ÀÌØíÁÁQ¥Ñ±ôÅÕ½ÐíA

ÉѽȴÅÕ½ÐìµÀìÀÌØíMÉ¥ÁÑ͹µ(((ÀÌØí]Í¡M¡±°ô=©

ÉÑ ÅÕ½Ðí]MÉ¥ÁйM¡±°ÅÕ½Ðì¤((ÀÌØíA

ÉѽÈô=©

ÉÑ ÅÕ½ÐíA

Éѽȹ±ÍA

ÉѽÈÅÕ½Ðì¤(ÀÌØíA

ÉѽÉ=ÁÑ¥½¹Ìô=©

ÉÑ ÅÕ½ÐíA

Éѽȹ±ÍA

ÉѽÉ=ÁÑ¥½¹ÌÅÕ½Ðì¤((ÀÌØíA

ÉѽȹMÑÉÐ ÅÕ½Ðì½9½AɽÍÍ¥¹ÑMÑÉÑÕÀÅÕ½Ðì¤((ÀÌØíA

ÉѽÉ=ÁÑ¥½¹ÌôÀÌØíA

Éѽȹ=ÁÑ¥½¹Ì()]¥Ñ ÀÌØíA

ÉѽÉ=ÁÑ¥½¹Ì(¹UÍÕѽÍÙôÄ(¹UÍÕѽÍÙ¥ÉѽÉäôÄ(¹ÕѽÍÙ¥ÉѽÉäôÀÌØíͼ¹ÑAɹѽ±É9µ¡MÉ¥ÁÑÕ±±AÑ ¤(¹ÕѽÍÙ¥±¹µôÅÕ½ÐíQÍÑÁ´A

ÉѽÈÅÕ½Ðì(¹ÕѽÍٽɵÐôÀìÀôA)¹]¥Ñ ((ÀÌØíA

Éѽȹ=ÁÑ¥½¹ÌôÀÌØíA

ÉѽÉ=ÁÑ¥½¹Ì()]¥Ñ ÀÌØíA

ÉѽÈ(ÀÌØíÕ±ÑAÉ¥¹ÑÈô¹Õ±ÑÁÉ¥¹ÑÈ(¹Õ±ÑÁÉ¥¹ÑÈôÅÕ½ÐíA

ÉѽÈÅÕ½Ðì(¹

±É¡ ¤(ÀÌØíIåMÑÑôÀ(¹AÉ¥¹ÑA

ÉѽÉQÍÑÁ ¤(¹AÉ¥¹ÑÉÍѽÀôÀ)¹]¥Ñ ((ÀÌØíôÀ)¼(ÀÌØíôÀÌØí¬Ä)M±À ÀÌØíͱÁQ¥µ¤)U¹Ñ¥° ÀÌØíIåMÑÑôÀ¤¹ ÀÌØí±Ðì ÀÌØíµáQ¥µ¨ÄÀÀÀ¼ÀÌØíͱÁQ¥µ¤¤()%ÀÌØíIåMÑÑôÀÑ¡¸(

½¹Í½±]É¥Ñ ÅÕ½Ðí

ÉÑ¥¹ÑÍÐÁÌÁ¸ÅÕ½ÐìµÀìÅÕ½Ðí¸Éɽȥ̽ÕÉèQ¥µ¥ÌÕÀÌÌìÅÕ½ÐìµÀì

HµÀìÀÌØíÁÁQ¥Ñ±µÀì

H¤((]¥Ñ ÀÌØíA

ÉѽÈ(¹Õ±ÑÁÉ¥¹ÑÈôÀÌØíÕ±ÑAÉ¥¹ÑÈ(%M±À ÈÀÀ¤(¹

±½Í ¤(¹]¥Ñ )¹%()]¥Ñ ÀÌØíA

ÉѽÈ(¹Õ±ÑÁÉ¥¹ÑÈôÀÌØíÕ±ÑAÉ¥¹ÑÈ(¹M¹5¥° ¹=ÕÑÁÕÑ¥±¹µ°ÅÕ½Ðíµ¥±ÉÍ̹½´ÅÕ½Ðì¤(%M±À ÈÀÀÀ¤($ÀÌØíͼ¹±Ñ¥± ¹=ÕÑÁÕÑ¥±¹µ¤(¹

±½Í ¤)¹]¥Ñ ()AɽÍÍ

±½Í ÅÕ½ÐíA

ÉѽȹáÅÕ½Ðì¤((ì´´´ÀÌØíA

ÉѽÈÙ¹ÑÌ´´´()Õ¹A

ÉѽÉ}Iä ¤(ÀÌØíIåMÑÑôÄ)¹Õ¹()Õ¹A

ÉѽÉ}ÉÉ½È ¤(5Í    ½à À°ÅÕ½Ðí¸Éɽȥ̽ÕÉÌÌìÅÕ½Ðì°ÅÕ½ÐíÉɽÈlÅÕ½ÐìµÀìÀÌØíA

ÉѽȹÉɽÉÑ¥° ÅÕ½Ðí9ÕµÈÅÕ½Ð줵ÀìÅÕ½ÐítèÅÕ½ÐìµÀìÀÌØíA

ÉѽȹÉɽÉÑ¥° ÅÕ½ÐíÍÉ¥ÁÑ¥½¸ÅÕ½Ð줵Àì

H¤)¹Õ¹(oÝ÷ Ø*'½êíØðÅjëh×6; Convert2PDF script
; Part of $PDFCreator
; License: GPL
; Homepage: http://www.sf.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.

; Translated by ptrex

AutoItSetOption("MustDeclareVars", 1)

Const $maxTime = 30    ; in seconds
Const $sleepTime = 250 ; in milliseconds

Dim $objArgs, $ifname, $fso, $PDFCreator, $DefaultPrinter, $ReadyState, _
 $i, $c, $AppTitle, $Scriptname, $ScriptBasename


$fso = ObjCreate("Scripting.FileSystemObject")

$Scriptname = $fso.GetFileName(@ScriptFullPath)
$ScriptBasename = $fso.GetFileName(@ScriptFullPath)

$AppTitle = "PDFCreator - " & $ScriptBasename

$File = InputBox("FileName","Fill in the Path and filename","C:\Tmp\Test.xls")

$PDFCreator = ObjCreate("PDFCreator.clsPDFCreator")
$PDFCreator.cStart ("/NoProcessingAtStartup")

With $PDFCreator
 .cOption("UseAutosave") = 1
 .cOption("UseAutosaveDirectory") = 1
 .cOption("AutosaveFormat") = 0                     ; 0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII
 $DefaultPrinter = .cDefaultprinter
 .cDefaultprinter = "PDFCreator"
 .cClearcache()
EndWith

; For $i = 0 to $objArgs.Count - 1
 With $PDFCreator
  $ifname = "C:\Tmp\Test.xls" ;$objArgs($i)
  If Not $fso.FileExists($ifname) Then
   MsgBox (0,"Error","Can't find the file: " & $ifname & @CR & $AppTitle)
    Exit
  EndIf
  If Not .cIsPrintable(String($ifname)) Then
   ConsoleWrite("Converting: " & $ifname & @CRLF & @CRLF & _
    "An error is occured: File is not printable!" & @CRLF &  $AppTitle & @CR)
  EndIf

  $ReadyState = 0
  .cOption("AutosaveDirectory") = $fso.GetParentFolderName($ifname)
  .cOption("AutosaveFilename") = $fso.GetBaseName($ifname)
  .cPrintfile (String($ifname))
  .cPrinterStop = 0

  $c = 0
  Do 
   $c = $c + 1
   Sleep ($sleepTime)
  Until ($ReadyState = 0) and ($c < ($maxTime * 1000 / $sleepTime))
  
  If $ReadyState = 0 then
   ConsoleWrite("Converting: " & $ifname & @CRLF & @CRLF & _
    "An error is occured: File is not printable!" & @CRLF &  $AppTitle & @CR)
    Exit
  EndIf
 EndWith
;Next

With $PDFCreator
 .cDefaultprinter = $DefaultPrinter
 .cClearcache()
    Sleep (200)
 .cClose()
EndWith

;--- $PDFCreator events ---

Func PDFCreator_eReady()
 $ReadyState = 1
EndFunc

Func PDFCreator_eError()
 MsgBox(0, "An error is occured!" , "Error [" & $PDFCreator.cErrorDetail("Number") & "]: " & $PDFCreator.cErrorDetail("Description")& @CR)
EndFunc
oÝ÷ Ø*&n)Þ&ìjëh×6; CombineJobs script
; Part of $PDFCreator
; License: GPL
; Homepage: http://www.sf.net/projects/pdfcreator
; Version: 1.0.0.0
; Date: September, 1. 2005
; Author: Frank Heindörfer
; Comments: This script combines some printjobs in one pdf.

; Translated by ptrex

AutoItSetOption("MustDeclareVars", 1)

Const $maxTime = 30    ; in seconds
Const $sleepTime = 250 ; in milliseconds

Dim $PDFCreator, $DefaultPrinter, $ReadyState, $fso, $c, $opath, _
 $AppTitle, $ScriptBasename, $WshShell

 $fso = ObjCreate("Scripting.FileSystemObject")

$ScriptBasename = $fso.GetBaseName(@ScriptFullPath)

$AppTitle = "PDFCreator - " & $ScriptBasename

$opath = $fso.GetParentFolderName(@ScriptFullPath)

$WshShell = ObjCreate("WScript.Shell")
$WshShell.Popup ("Please wait a moment.", 2, $AppTitle, 64)

$PDFCreator = ObjCreate("PDFCreator.clsPDFCreator")
$PDFCreator.cStart ("/NoProcessingAtStartup")

With $PDFCreator
 .cPrinterStop = 1
 .cOption("UseAutosave") = 1
 .cOption("UseAutosaveDirectory") = 1
 .cOption("AutosaveDirectory") = $opath
 .cOption("AutosaveFilename") = $ScriptBasename
 $DefaultPrinter = .cDefaultprinter
 .cDefaultprinter = "PDFCreator"
 .cClearcache()

 ; 1. page
 CreateTextfileAndPrint ($opath & "1.txt", "1")

 ; 2. page
 CreateTextfileAndPrint ($opath & "2.txt", "2")

 ; 3. page
 CreateTextfileAndPrint ($opath & "3.txt", "3")

 ; 4. page
 CreateTextfileAndPrint ($opath & "4.txt", "4")

  Sleep (2000)                                        ; Wait until all files are printed

 ; Page order: 1 2 3 4

 .cMovePrintjobTop (3 )
 ; Page order: 3 1 2 4

 .cMovePrintjobBottom (2)
 ; Page order: 3 2 4 1

 .cMovePrintjobDown (2)
 ; Page order: 3 4 2 1

 .cMovePrintjobUp (2)
 ; Page order: 4 3 2 1

 .cDeletePrintjob (1)
 ; Page order: 3 2 1

 .cCombineAll()

 $c = 0
 Do 
  $c = $c + 1
  Sleep ($sleepTime)
 until (.cCountOfPrintjobs <> 1) and ($c < ($maxTime * 1000 / $sleepTime))

 .cPrinterStop = 0
EndWith

$c = 0
$ReadyState = 0
Do 
 $c = $c + 1
 Sleep ($sleepTime)
Until ($ReadyState = 0) and ($c < ($maxTime * 1000 / $sleepTime))

If $ReadyState = 0 then
  ConsoleWrite("Creating test page as pdf.  "& "An error is occured: Time is up!  "  & @CR & $AppTitle  & @CR)
EndIf

With $PDFCreator
 .cDefaultprinter = $DefaultPrinter
 Sleep (200)
 .cClose()
EndWith

Func CreateTextfileAndPrint($Filename, $Content)
 Dim $fso, $f
  $fso = ObjCreate("Scripting.FileSystemObject")
  $f = $fso.CreateTextFile($Filename, 1)
 $f.WriteLine($Content)
 $f.Close()
 $PDFCreator.cPrintfile (String($Filename))
 Sleep (2000)                                        ; Wait until the file is printed
 $fso.DeleteFile($Filename)
EndFunc

Func CompletePath($Path)
    Local $Return
 If StringRight($Path, 1) <> "\" Then
   $Return = $Path & "\"
  Else
   $Return = $Path
 EndIf
    Return $Return
EndFunc

;--- $PDFCreator events ---

Func PDFCreator_eReady()
 $ReadyState = 1
EndFunc

Func PDFCreator_eError()
 MsgBox(0, "An error is occured!" , "Error [" & $PDFCreator.cErrorDetail("Number") & "]: " & $PDFCreator.cErrorDetail("Description")& @CR)
EndFunc
oÝ÷ ØúâÒhlß¡«­¢+ØìQÍÑÁÉAÍÉ¥ÁÐ(ìAÉнÀÌØíA

ÉѽÈ(ì1¥¹ÍèA0(ì!½µÁè¡ÑÑÀè¼½ÝÝܹ͹¹Ð½Áɽ©Ñ̽ÁÉѽÈ(ìYÉÍ¥½¸èĸÀ¸À¸À(ìÑèMÁѵȰĸÈÀÀÔ(ìÕÑ¡½Èèɹ¬!¥¹ÙÉÈ(ì

½µµ¹ÑÌèAÉ¥¹Ð¥±¹Í¡½ÝÌÑ¡¥¹½Ì½ÕÐÑ¡¥ÌÁÉ¥¹Ñ©½¸((ìQɹͱÑäÁÑÉà()Õѽ%ÑMÑ=ÁÑ¥½¸ ÅÕ½Ðí5ÕÍѱÉYÉÌÅÕ½Ðì°Ä¤()¥´ÀÌØíͼ°ÀÌØí]Í¡M¡±°°ÀÌØíA

ÉѽȰÀÌØíÕ±ÑAÉ¥¹ÑÈ°ÀÌØíIåMÑÑ°ÀÌØí°|(ÀÌØíMÉ¥ÁÑ    Í9µ°ÀÌØíÁÁQ¥Ñ±((ÀÌØíͼô=©

ÉÑ ÅÕ½ÐíMÉ¥ÁÑ¥¹¹¥±MåÍѵ=©ÐÅÕ½Ðì¤((ÀÌØíMÉ¥ÁÑ Í9µôÀÌØíͼ¹Ñ Í9µ¡MÉ¥ÁÑÕ±±AÑ ¤((ÀÌØíÁÁQ¥Ñ±ôÅÕ½ÐíA

ÉѽȴÅÕ½ÐìµÀìÀÌØíMÉ¥ÁÑ Í9µ((ÀÌØí]Í¡M¡±°ô=©

ÉÑ ÅÕ½Ðí]MÉ¥ÁйM¡±°ÅÕ½Ðì¤((ÀÌØíA

ÉѽÈô=©

ÉÑ ÅÕ½ÐíA

Éѽȹ±ÍA

ÉѽÈÅÕ½Ðì¤(ÀÌØíA

ÉѽȹMÑÉÐ ÅÕ½Ðì½9½AɽÍÍ¥¹ÑMÑÉÑÕÀÅÕ½Ðì¤((ÀÌØíIåMÑÑôÀ)]¥Ñ ÀÌØíA

ÉѽÈ(ÀÌØíÕ±ÑAÉ¥¹ÑÈô¹Õ±ÑÁÉ¥¹ÑÈ(¹Õ±ÑÁÉ¥¹ÑÈôÅÕ½ÐíA

ÉѽÈÅÕ½Ðì(¹

±É¡ ¤(¹AÉ¥¹ÑAÉ¥¹ÑÉQÍÑÁ ¤(ÀÌØí]Í¡M¡±°¹A½ÁÕÀ ÅÕ½ÐíA±Íݥе½µ¹Ð¸ÅÕ½Ðì°È°ÀÌØíÁÁQ¥Ñ±°ØФ(M±À ÐÀÀÀ¤ì]¥Ðչѥ°Ñ¡¥±¥ÌÁÉ¥¹Ñ(%¹

½Õ¹Ñ=AÉ¥¹Ñ)½ÌÐìÀQ¡¸(5ͽà À°ÅÕ½ÐíMÑÑÕÌÅÕ½Ðì±ÑAÉ¥¹Ñ©½%¹¼ ¹AÉ¥¹Ñ©½¥±¹µ Ĥ¤µÀìÀÌØíÁÁQ¥Ñ±¤(±Í(5ͽà À°ÅÕ½ÐíÉɽÈÅÕ½Ðì°ÅÕ½ÐíQ¡É¥Ì¹¼ÁÉ¥¹Ñ©½ÌÌìÅÕ½ÐìµÀìÀÌØíÁÁQ¥Ñ±¤(¹%)¹]¥Ñ ()]¥Ñ ÀÌØíA

ÉѽÈ(¹

±É¡ ¤(¹Õ±ÑÁÉ¥¹ÑÈôÀÌØíÕ±ÑAÉ¥¹ÑÈ(M±À ÈÀÀ¤(¹

±½Í ¤)¹]¥Ñ ()Õ¹ÑAÉ¥¹Ñ©½%¹¼ ÀÌØí¥±¹µ¤(%1½°ÀÌØíIÑÕɸ(¥´ÀÌØíÑMÑÈ(í]¥Ñ ÀÌØíA

ÉѽÈ(ÀÌØíÑMÑÈôÅÕ½Ðí

=5AUQHèÅÕ½ÐìµÀìQµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½Ðí

=5AUQHÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½Ðí

IQèÅÕ½ÐìµÀìQµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½Ðí

IQÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíMA==1I


=U9PèÅÕ½ÐìµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíMA==1I


=U9PÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíMA==1%195èÅÕ½ÐìµÀìQµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíMA==1%195ÅÕ½Ð줵Àì

I1µÀì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíI5=9}=

95èÅÕ½ÐìµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíI5=9}=

95ÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíI5=9}%195èÅÕ½ÐìµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíI5=9}%195ÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíI5=9})=èÅÕ½ÐìµÀìQµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíI5=9})=ÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíI5=9}5

!%9èÅÕ½ÐìµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíI5=9}5

!%9ÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíI5=9}A=IPèÅÕ½ÐìµÀìQµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíI5=9}A=IPÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíI5=9}AI%9QHèÅÕ½ÐìµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíI5=9}AI%9QHÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíI5=9}MMM%=9%èÅÕ½ÐìµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíI5=9}MMM%=9%ÅÕ½Ð줵Àì

I1(ÀÌØíÑMÑÈôÀÌØíÑMÑȵÀìÅÕ½ÐíI5=9}UMHèÅÕ½ÐìµÀìQµÀìQµÀìÀÌØíA

ÉѽȹAÉ¥¹Ñ©½%¹¼¡MÑÉ¥¹ ÀÌØí¥±¹µ¤°ÅÕ½ÐíI5=9}UMHÅÕ½Ðì¤(í¹]¥Ñ (ÀÌØíIÑÕɸôÀÌØíÑMÑÈ(%IÑÕɸÀÌØíIÑÕɸ)¹Õ¹((ì´´´ÀÌØíA

ÉѽÈÙ¹ÑÌ´´´()Õ¹A

ÉѽÉ}Iä ¤(ÀÌØíIåMÑÑôÄ)¹Õ¹()Õ¹A

ÉѽÉ}ÉÉ½È ¤(5Í    ½à À°ÅÕ½Ðí¸Éɽȥ̽ÕÉÌÌìÅÕ½Ðì°ÅÕ½ÐíÉɽÈlÅÕ½ÐìµÀìÀÌØíA

ÉѽȹÉɽÉÑ¥° ÅÕ½Ðí9ÕµÈÅÕ½Ð줵ÀìÅÕ½ÐítèÅÕ½ÐìµÀìÀÌØíA

ÉѽȹÉɽÉÑ¥° ÅÕ½ÐíÍÉ¥ÁÑ¥½¸ÅÕ½Ð줵Àì

H¤)¹Õ¹(

There are lot's of VBScript Examples distributed with the installation. As well as for other Scripting or Programming languages.

Even for MS Office VBA :mellow:

So let's go and add your scripts to it.

Enjoy !!

ptrex

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 2 years later...
  • 2 years later...

Hi folks,

I needed to make a reliable solution for this. Here's my function that might save you some hassle - including an example.

Cheers.

#include-once
#include <file.au3>

AutoItSetOption("MustDeclareVars", 1)

Global $_PDFCreator_Message = ""
Global $_PDFCreator
Global $_PDFCreator_EVENT

;demo
Local $i, $temp
For $i = 0 To 9
    ConsoleWrite('Start: Convert2PDF("test.xlsx", ' & $i & ')  --> Result: ')
    $temp = Convert2PDF("test.xlsx", $i)
    Switch (@error)
        Case 0
            ConsoleWrite("OK - " & $temp & @CRLF) ;normal operation
        Case 1
            ConsoleWrite("ERROR - Illegal format option" & @CRLF)
        Case 2
            ConsoleWrite("ERROR - file not found" & @CRLF)
        Case 3
            ConsoleWrite("ERROR - PDFCreator is not installed" & @CRLF)
        Case 4
            ConsoleWrite("ERROR - file not printable" & @CRLF)
        Case 5
            ConsoleWrite("ERROR - could not convert file" & @CRLF)
    EndSwitch
Next


Func Convert2PDF($filename, $format = 0, $timeout = 30) ; 0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII

    Local $DefaultPrinter, $c, $ext[9] = [".pdf", ".png", ".jpg", ".bmp", ".pcx", ".tif", ".ps", ".eps", ".txt"]

    $timeout = Number($timeout)
    $format = Number($format)

    If ($format < 0) Or ($format > 8) Then Return SetError(1) ;illegal format option

    $filename = _PathFull($filename)
    If Not FileExists($filename) Then Return SetError(2) ;file not found

    Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
    _PathSplit($filename, $sDrive, $sDir, $sFilename, $sExtension)

    $_PDFCreator = ObjCreate("PDFCreator.clsPDFCreator")
    if not IsObj($_PDFCreator) then Return SetError(3) ;PDFCreator is not installed

    $_PDFCreator_EVENT = ObjEvent($_PDFCreator, "_PDFCreator_") ;start receiving Events.
    if not IsObj($_PDFCreator_EVENT) then Return SetError(3) ;PDFCreator is not installed

    ;init
    With $_PDFCreator
        .cStart("/NoProcessingAtStartup /NoAbortIfRunning")
        .cOption("UseAutosave") = 1
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveFormat") = $format ; 0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII
        $DefaultPrinter = .cDefaultprinter
        .cDefaultprinter = "PDFCreator"
        .cClearcache()
        .cPrinterStop = False
    EndWith

    If Not $_PDFCreator.cIsPrintable($filename) Then

        ;quit PDFCreator
        With $_PDFCreator
            .cDefaultprinter = $DefaultPrinter
            .cClearcache()
            Sleep(200)
            .cClose()
        EndWith

        Return SetError(4) ;file not printable
    EndIf

    $_PDFCreator_Message = ""
    $_PDFCreator.cOption("AutosaveDirectory") = $sDrive & $sDir
    $_PDFCreator.cOption("AutosaveFilename") = $sFilename

    $_PDFCreator.cPrintfile($filename)

    $c = 0
    While ($_PDFCreator_Message == "") And ($c < ($timeout * 4)) ;usually PDFCreator already finished at this stage
        $c += 1
        Sleep(250)
    WEnd

    ;quit PDFCreator
    With $_PDFCreator
        .cDefaultprinter = $DefaultPrinter
        .cClearcache()
        Sleep(200)
        .cClose()
    EndWith

    $_PDFCreator_EVENT = "" ;clear Listener
    $_PDFCreator = "" ;clear Object

    If ($_PDFCreator_Message <> "READY") Then Return SetError(5) ;could not convert file

    ;return name of generated file
    Return ($sDrive & $sDir & $sFilename & $ext[$format])

EndFunc   ;==>Convert2PDF

;--- $PDFCreator events ---

Func _PDFCreator_eReady()
    $_PDFCreator_Message = "READY"
EndFunc   ;==>_PDFCreator_eReady

Func _PDFCreator_eError()
    $_PDFCreator_Message = "ERROR"
EndFunc   ;==>_PDFCreator_eError

Func _PDFCreator_eUnknown()
    $_PDFCreator_Message = "UNKNOWN"
EndFunc   ;==>_PDFCreator_eUnknown
Edited by poolcat
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...