Public Function PrintRepPdf(RepName As String, txtPath As String, txtFile As String)
Dim PdfCreate As New PDFCreator.clsPDFCreator
Dim DefaultPrinter As String
Dim c As Long
Dim OutputFilename As String
Dim dblTimer As Double
With PdfCreate
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = txtPath & "\"
.cOption("AutosaveFilename") = txtFile
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultPrinter
.cDefaultPrinter = "PDFCreator"
'.cDefaultPrinter = DLookup("[stampante pdf]", "impostazioni", "[ID] = 1")
.cClearCache
'Attesa 2 secondi per assicurarsi che l'oggetto pdf sia pronto
dblTimer = Timer
Do
If dblTimer + 2 < Timer Then Exit Do
DoEvents
Loop
' qui faccio la chiamata al mio DataReports
StampaFattura
.cPrinterStop = False
End With
c = 0
Do While (PdfCreate.cOutputFilename = "") And (c < (maxTime * 1000 / sleepTime))
c = c + 1
Sleep 200
Loop
OutputFilename = PdfCreate.cOutputFilename
With PdfCreate
.cDefaultPrinter = DefaultPrinter
Sleep 200
.cClose
End With
Sleep 2000 ' Wait until PDFCreator is removed from memory
If OutputFilename = "" Then
MsgBox "Creating pdf file." & vbCrLf & vbCrLf & "An error is occured: Time is up!", vbExclamation + vbSystemModal
End If
End Function