Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

PDFCreator - Print2PDF


  • Please log in to reply
34 replies to this topic

#1 ptrex

ptrex

    Universalist

  • MVPs
  • 2,420 posts

Posted 16 March 2007 - 07:11 PM

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

Someone in the help forum was wondering how to use the PDFCreator in AutoIT.
When reading this, I was surprised to find that PDFCreator had a COM object in it's latest version.

I have been using PDFCreator since years, but never know this :">

Anyhow here is the example on how to create a PDF Test page.

AutoIt         
;; Testpage2PDF script ; Part of $PDFCreator ; License: GPL ; Homepage: <a href='http://www.sf.net/projects/pdfcreator' class='bbc_url' title='External link' rel='nofollow external'>http://www.sf.net/projects/pdfcreator</a> ; 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 AutoItSetOption("MustDeclareVars", 1) Const $maxTime = 10 ; in seconds Const $sleepTime = 250 ; in milliseconds Dim $fso, $WshShell, $PDFCreator, $DefaultPrinter, $ReadyState, $c, _ $Scriptname, $Scriptbasename $fso = ObjCreate("Scripting.FileSystemObject") $Scriptbasename = $fso.GetBaseName(@ScriptFullPath) $WshShell = ObjCreate("WScript.Shell") $PDFCreator = ObjCreate("PDFCreator.clsPDFCreator") $PDFCreator.cStart ("/NoProcessingAtStartup") $ReadyState = 0 With $PDFCreator .cOption("UseAutosave") = 1 .cOption("UseAutosaveDirectory") = 1 .cOption("AutosaveDirectory") = $fso.GetParentFolderName(@ScriptFullPath) .cOption("AutosaveFilename") = "Testpage - PDFCreator" .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() .cPrintPDFCreatorTestpage() .cPrinterStop = 0 EndWith $c = 0 Do $c = $c + 1     Sleep ($sleepTime) Until ($ReadyState = 0) and ($c < ($maxTime * 1000 / $sleepTime)) With $PDFCreator .cDefaultprinter = $DefaultPrinter     Sleep( 200) .cClose() EndWith If $ReadyState = 0 then Consolewrite ("Creating test page as pdf." & @CRLF & @CRLF & "An error is occured: Time is up!"& @CR) ProcessClose("PDFCreator.exe") EndIf ;--- $PDFCreator events --- Func PDFCreator_eReady() $ReadyState = 1 EndFunc Func PDFCreator_eError() Consolewrite ("An error is occured!" & @CRLF & @CRLF & _ "Error [" & $PDFCreator.cErrorDetail("Number") & "]: " & $PDFCreator.cErrorDetail("Description")& @CR) ;VA Wscript.Quit EndFunc


AutoIt         
; Convert2PDF script ; Part of $PDFCreator ; License: GPL ; Homepage: <a href='http://www.sf.net/projects/pdfcreator' class='bbc_url' title='External link' rel='nofollow external'>http://www.sf.net/projects/pdfcreator</a> ; 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, $File $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:_AppsAutoIT3COMPDFCreatorVBScriptsGUI.vbs") $PDFCreator = ObjCreate("PDFCreator.clsPDFCreator") $PDFCreator.cStart ("/NoProcessingAtStartup") With $PDFCreator .cOption("UseAutosave") = 1 .cOption("UseAutosaveDirectory") = 1 .cOption("AutosaveFormat") = 1 ; 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 = $File ;"C:TmpTest.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 ProcessClose("PDFCreator.exe") ;--- $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




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 :whistle:

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

Enjoy !!

ptrex

Edited by ptrex, 14 September 2012 - 09:01 AM.








#2 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,573 posts

Posted 16 March 2007 - 07:40 PM

Handy to have.
Do you happen to know what the other possibilities are for .cOption("AutosaveFormat") ?
GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#3 ptrex

ptrex

    Universalist

  • MVPs
  • 2,420 posts

Posted 16 March 2007 - 07:50 PM

@GEOSoft

other possibilities are for .cOption("AutosaveFormat")


I just discovered it half an hour ago.

So I can tell all options, but for sure TIFF and ASCII.

regards,

ptrex

#4 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,573 posts

Posted 16 March 2007 - 08:23 PM

@GEOSoft
I just discovered it half an hour ago.

So I can tell all options, but for sure TIFF and ASCII.

regards,

ptrex

OK, thanks for posting this info. Keep us updated. In the meantime I'm just downloading PDFCreator now. I've meant to do that for a long time anyway. I used to have a full load of Acrobat installed but since I had to replace a hard drive, I didn't re-install it this time. I'm Using FoxIt as a reader and I've tried using a Word add-in that I have for creating PDF's but that's kind of crappy and as slow as Acrobat.
GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#5 Josbe

Josbe

    Infrequent ghost ☺

  • Active Members
  • PipPipPipPipPipPip
  • 1,585 posts

Posted 16 March 2007 - 08:36 PM

I didn't know either, thanks ptrex. :whistle:

#6 ptrex

ptrex

    Universalist

  • MVPs
  • 2,420 posts

Posted 16 March 2007 - 08:36 PM

@GEOSoft

These are all the file types I could find.

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

If you get some scripts translated post them. There are very interesting included !!

regards,

ptrex

Edited by ptrex, 16 March 2007 - 10:10 PM.


#7 ptrex

ptrex

    Universalist

  • MVPs
  • 2,420 posts

Posted 16 March 2007 - 09:31 PM

@all

I added "Testpage2PDFSendEmail" as well.

But is seems not to do it at all times. Needs more experimenting.

Let me know how it runs on other machines.

thanks

ptrex

#8 ptrex

ptrex

    Universalist

  • MVPs
  • 2,420 posts

Posted 16 March 2007 - 10:30 PM

@All

Add "Convert2PDF" and "CombineJobs" and "PrintJobInfo"

So that's all for know.

Regards,

ptrex

Edited by ptrex, 16 March 2007 - 10:58 PM.


#9 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,786 posts

Posted 17 March 2007 - 01:49 PM

Looks very promissing. Thanks for sharing.

#10 ptrex

ptrex

    Universalist

  • MVPs
  • 2,420 posts

Posted 17 March 2007 - 04:50 PM

@Josbe / Zedna,


You are welcome !! :whistle:

Regards,

ptrex

#11 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,573 posts

Posted 17 March 2007 - 06:37 PM

I'm trying to make time to play with it today but it's going to be touch & go. What you already have is great. I think I feel another UDF coming up. :whistle:
GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#12 ptrex

ptrex

    Universalist

  • MVPs
  • 2,420 posts

Posted 18 March 2007 - 02:19 PM

@GEOSoft

Great. Do some testing on the PDF2Email thing, it's not stable on my machine.

Added "CombineAndAddBoomarks" see first post.

regards,

ptrex

Edited by ptrex, 18 March 2007 - 03:06 PM.


#13 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,573 posts

Posted 18 March 2007 - 04:04 PM

@GEOSoft

Great. Do some testing on the PDF2Email thing, it's not stable on my machine.

Added "CombineAndAddBoomarks" see first post.

regards,

ptrex

It's not too stable on mine either. I'll have another look at it later.
GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#14 dabus

dabus

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 405 posts

Posted 16 May 2007 - 01:33 PM

Great stuff, so I wanted to create my little any2pdf-converter/binder.
Replaced the CreateTextfileAndPrint and it looks like this now:

CODE

AutoIt         
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()     CreateTextfileAndPrint('D:\Daten\Text\Samba\samba\www.oreilly.com\catalog\samba2\book\appa.html')     CreateTextfileAndPrint('D:\Daten\Text\Samba\samba\www.oreilly.com\catalog\samba2\book\appb.html')     Sleep (2000)                                        ; Wait until all files are printed     .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)     If StringRegExp($Filename, '*.xls|*.doc|*.pdf') Then         ShellExecuteWait($Filename, '', @ScriptDir, 'print')     Else         $IView=StringReplace(RegRead('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrfanView', 'UninstallString'), 'v_uninstall', '_view32')         RunWait('"'&$IView&'" "'&$Filename&'" /print', @ScriptDir)     EndIf       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



All goes well untill I try do combine, that's when pdfcreator pops up and says it couldn't find gsdll32.dll, crashes or whatever. I can't do a regsvr32 on that file. ;( Can you confirm that or even tell me what you did to print other then plain-text files?

Can you tell me if there's a commandline-tool to do the printing? Maybe it would be possible to do it with a postscript-printer that prints into a file with the help of the plain gs.
PdfCreator itself is a little too "out of the box" to be controlled by controlclick/send and so on.

Edited by dabus, 16 May 2007 - 01:43 PM.


#15 DjDeep00

DjDeep00

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 654 posts

Posted 28 September 2007 - 02:01 PM

Hi Ptrex,

I am getting the following error when I tried creating an PDF using the first example from your first post:

Variable must be of type "Object". $PDFCreator.cStart ("/NoProcessingAtStartup") $PDFCreator^ ERROR


I have Acrobat Reader and Writer versions 6.0 installed on my machine.
Please advise.

-DjDeep

Edited by DjDeep00, 28 September 2007 - 02:06 PM.


#16 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,573 posts

Posted 28 September 2007 - 02:24 PM

Hi Ptrex,

I am getting the following error when I tried creating an PDF using the first example from your first post:

Variable must be of type "Object". $PDFCreator.cStart ("/NoProcessingAtStartup") $PDFCreator^ ERROR


I have Acrobat Reader and Writer versions 6.0 installed on my machine.
Please advise.

-DjDeep

But do you have PDFCreator installed??
http://www.sf.net/projects/pdfcreator
GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#17 DjDeep00

DjDeep00

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 654 posts

Posted 28 September 2007 - 02:51 PM

Ok thx Geosoft...I didnt know I had to install PDFCreator...I guess I missed that part...I was under the impression that you can create a PDF if you had PDF Writer installed. And for downloading which one do I need...
PDFCreator-0_9_3_GPLGhostscript.exe or PDFCreator-0_9_3_WithoutGhostscript.exe?

Thanks,
DjDeep

#18 ptrex

ptrex

    Universalist

  • MVPs
  • 2,420 posts

Posted 28 September 2007 - 03:31 PM

@DjDeep00

I recommend to take the first one : PDFCreator-0_9_3_GPLGhostscript.exe

You can create PDF's with PDF writer through the COM inferface, but that's a different story.

regards,

ptrex

#19 DjDeep00

DjDeep00

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 654 posts

Posted 28 September 2007 - 04:50 PM

You can create PDF's with PDF writer through the COM inferface, but that's a different story.

Thanx Ptrex...I guess thats what I need. Kind of like how the Excel functions were made by Locodarwin. How would I do this?

Edited by DjDeep00, 28 September 2007 - 04:51 PM.


#20 ptrex

ptrex

    Universalist

  • MVPs
  • 2,420 posts

Posted 28 September 2007 - 05:45 PM

@DjDeep00

You don't need to do anything, because someone else did it for you.

Acrobat UDF

Regards,

ptrex

Edited by ptrex, 28 September 2007 - 07:08 PM.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users