Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Mike Gagnon
  Where is Mike Gagnon?
 Pointe Claire
 Canada
 Mike Gagnon
 To: Oliver Cortazar
  Where is Oliver Cortazar?
 San Luis Potosi
 Mexico
 Oliver Cortazar
 Tags
Subject: RE: pdf generation
Thread ID: 289418 Message ID: 289419 # Views: 81 # Ratings: 0
Version: Visual FoxPro 9 Category: 3rd Party Software
Date: Friday, December 31, 2010 11:54:05 PM         
   


> Hello Experts!!!
> First of all: Happy new year !!!
>
> I hope that this next year will be one of massive success for everyone, I wish you all the best.
>
> I have a little problem. I need to generate a pdf file from a program. I have been using PDF creator, which works fine, however, I need the file to be generated automatically, without prompting the file name or anything.
>
> Is there anyway to do this with PDFCreator? or is there any other way to do this?
>
> I apreciate your help, thanks in advance.



Close Databases All
 #Define TH32CS_SNAPPROCESS 2
 #Define TH32CS_SNAPTHREAD 4
 #Define TH32CS_SNAPMODULE 8
 #Define MAX_PATH 260
 #Define PE32_SIZE 296
 
Local cPrinterNow,cOldPrinter
 cOldPrinter = Set("Printer",2)
 Declare Sleep In Win32API Integer nMilliseconds
 Declare Integer CloseHandle In kernel32 Integer hObject
 Declare Integer CreateToolhelp32Snapshot In kernel32;
 INTEGER dwFlags, Integer th32ProcessID
 Declare Integer Process32First In kernel32;
 INTEGER hSnapshot, String @ lppe
 Declare Integer Process32Next In kernel32;
 INTEGER hSnapshot, String @ lppe
 
checkExe("PDFCreator.exe")
 Cd Home(2)+"\tastrade\data\"
 PrinterNow = "pdfcreator"
 If Upper(PrinterNow) <> Upper(cOldPrinter)
 resetprinter(PrinterNow)
 Endif
 Select * From customer Into Cursor tmpCust
 Create Report customer From tmpCust Fields company_name
 oPDFC = Createobject("PDFCreator.clsPDFCreator","pdfcreator")
 oPDFC.cStart("/NoProcessingAtStartup")
 oPDFC.cOption("UseAutosave") = 1
 oPDFC.cOption("UseAutosaveDirectory") = 1
 oPDFC.cOption("PDFUserPass") =1
 If !Directory("c:\temp4\")
 Md "c:\temp4"
 Endif
 oPDFC.cOption("AutosaveDirectory")="c:\temp4\"
 oPDFC.cOption("AutosaveFormat") = 0
 DefaultPrinter = oPDFC.cDefaultprinter
 oPDFC.cDefaultprinter = "pdfcreator"
 oPDFC.cClearCache
 ReadyState = 0
 oPDFC.cprinterstop=.F.
 For i = 1 To 4
 oPDFC.cOption("AutosaveFilename") = "toto"+Alltrim(Str(i))
 Report Form customer To Printer Noconsole
 nSleepSeconds = 5
 nMilliseconds = nSleepSeconds * 1000
 =Sleep(nMilliseconds)
 Endfor
 oPDFC.cDefaultprinter = cOldPrinter
 oPDFC.cClearCache
 Release oPDFC
 resetprinter(cOldPrinter)
 Procedure saveProcessData (lcBuffer)
 Local m.execname
 m.execname = Substr(lcBuffer, 37)
 m.execname = Substr(m.execname, 1, At(Chr(0),m.execname)-1)
 m.processid = buf2dword (Substr(lcBuffer, 9,4))
 Insert Into csResult From Memvar
 Return
 
Procedure resetprinter(tcPrinter)
 Local oWsh
 oWsh = Createobject('WScript.Network')
 oWsh.SetDefaultPrinter(tcPrinter)
 Endproc
 
Function buf2dword (lcBuffer)
 Return Asc(Substr(lcBuffer, 1,1)) + ;
 Asc(Substr(lcBuffer, 2,1)) * 256 +;
 Asc(Substr(lcBuffer, 3,1)) * 65536 +;
 Asc(Substr(lcBuffer, 4,1)) * 16777216
 
Function num2dword (lnValue)
 #Define m0 256
 #Define m1 65536
 #Define m2 16777216
 Local b0, b1, b2, b3
 b3 = Int(lnValue/m2)
 b2 = Int((lnValue - b3*m2)/m1)
 b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
 b0 = Mod(lnValue, m0)
 Return Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)
 

Function checkExe(tcExe)
 Create Cursor csResult (;
 execname C(250),;
 processid N(16))
 Local hSnapshot, lcBuffer
 
hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0)
 lcBuffer = num2dword(PE32_SIZE) + Repli(Chr(0), PE32_SIZE-4)
 
If Process32First (hSnapshot, @lcBuffer) = 1
 = saveProcessData (lcBuffer)
 
Do While .T.
 If Process32Next (hSnapshot, @lcBuffer) = 1
 = saveProcessData (lcBuffer)
 Else
 Exit
 Endif
 Enddo
 Else
 Endif
 
= CloseHandle (hSnapshot)
 Select csResult
 Locate For Upper(execname) = Upper(tcExe)
 If Found()
 Killprocess(csResult.ProcessID)
 Endif
 
Procedure Killprocess
 Lparameters tnProcessID
 Local lnHandle
 Declare Integer OpenProcess In Win32API ;
 integer dwDesiredAccess, Integer bInheritHandle, Integer dwProcessID
 Declare Integer TerminateProcess In Win32API ;
 integer hProcess, Integer uExitCode
 lnHandle = OpenProcess(1, 1, tnProcessID)
 llReturn = TerminateProcess(lnHandle, 0) > 0
 Endproc



Mike Gagnon
Refox XI +(English version)

ENTIRE THREAD

pdf generation Posted by Oliver Cortazar @ 12/31/2010 10:59:03 PM
RE: pdf generation Posted by Mike Gagnon @ 12/31/2010 11:54:05 PM
RE: pdf generation Posted by ron philippo @ 1/1/2011 5:06:18 PM
RE: pdf generation Posted by Koen Piller @ 1/1/2011 5:25:34 PM
RE: pdf generation Posted by Mike Gagnon @ 1/1/2011 10:35:41 PM
RE: pdf generation Posted by Cesar @ 1/2/2011 4:07:53 AM
RE: pdf generation Posted by Oliver Cortazar @ 1/3/2011 6:14:28 PM
RE: pdf generation Posted by Bob Brook @ 1/1/2011 3:37:23 PM
RE: pdf generation Posted by Oliver Cortazar @ 1/3/2011 6:16:11 PM