Dim objPDFCreatorQueue, printJob, objPDFCreator Dim objShell, objFSO, colArgs , startPath, objExcel, stdout, index, pathfile, filetype, flagConvert, objScr, j Set objFSO = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Shell.Application") Set objPDFCreatorQueue = CreateObject("PDFCreator.JobQueue") Set objPDFCreator = CreateObject("PDFCreator.PDFCreatorObj") Set objExcel = CreateObject("Excel.Application") Set objScr = CreateObject("WScript.Shell") Set colArgs = WScript.Arguments.Named Set itemFolders = (objFSO.GetFolder(colArgs.item("startPath"))).SubFolders Set stdout = objFSO.GetStandardStream (1) If (WScript.Version < 5.6) Then stdout.WriteLine "You need the Windows Scripting Host version 5.6 or greater!" WScript.Quit End If objExcel.Visible = False If objPDFCreator.IsInstanceRunning Then objScr.Run "taskkill /f /im pdfcreator.exe" While objPDFCreator.IsInstanceRunning WScript.Sleep 500 WEnd End If objPDFCreatorQueue.Initialize For Each itemFolder In itemFolders stdout.WriteLine "Carpeta \" & ItemFolder.Name index = 0 If objFSO.FolderExists( colArgs.item("startPath") & "\" & ItemFolder.Name & "\converted" ) Then objFSO.DeleteFolder colArgs.item("startPath") & "\" & ItemFolder.Name & "\converted" objFSO.createFolder colArgs.item("startPath") & "\" & ItemFolder.Name & "\converted" Else objFSO.createFolder colArgs.item("startPath") & "\" & ItemFolder.Name & "\converted" End If For Each itemFile In itemFolder.Files pathfile = " /PrintFile=""" & colArgs.item("startPath") & "\" & ItemFolder.Name & "\" & itemFile.Name & """" filetype = LCase(objFSO.GetExtensionName(itemFile.Name)) flagConvert = True If ((filetype = "xlsx" Or filetype = "xls") And (itemFile.Size < CLng(colArgs.item("excelSize")))) Then objExcel.Workbooks.Open colArgs.item("startPath") & "\" & ItemFolder.Name & "\" & itemFile.Name for j=1 to objExcel.Workbooks(1).Sheets.Count if(objExcel.Workbooks(1).Sheets(j).Visible = False) then objExcel.Workbooks(1).Sheets(j).Visible = True end if next objExcel.Workbooks(1).Sheets.PrintOut , , , False , "PDFCreator" , False , False , "", False objExcel.Workbooks(1).Save objExcel.Workbooks.Close ElseIf filetype = "jpg" Or filetype = "jpeg" Or filetype = "bmp" Or filetype = "png" Or filetype = "gif" Or filetype = "jfif" Or filetype = "tif" Then objShell.ShellExecute "mspaint.exe", "/p " & """" & colArgs.item("startPath") & "\" & ItemFolder.Name & "\" & itemFile.Name & """" & " /pt PDFCreator" , "", "open", 0 ElseIf filetype = "ppt" Or filetype = "pptx" Or filetype = "docx" Or filetype = "doc" Or filetype = "pdf" Then objShell.ShellExecute colArgs.item("pdfCreatorPath"), pathfile , "", "open", 0 Else flagConvert = False End If If flagConvert Then stdout.WriteLine "Convirtiendo archivo .. " & itemFile.Name If Not objPDFCreatorQueue.WaitForJob(120) Then stdout.WriteLine "Despues de 60 segundos no hay ningun proceso para convertir, se cancela." objPDFCreatorQueue.ReleaseCom WScript.Quit Else objPDFCreatorQueue.MergeAllJobs While objPDFCreatorQueue.Count > 0 Set printJob = objPDFCreatorQueue.NextJob printJob.SetProfileByGuid("DefaultGuid") printJob.SetProfileSetting "ShowProgress", "False" printJob.SetProfileSetting "ShowProgress", "False" printJob.SetProfileSetting "ShowQuickActions", "False" printJob.SetProfileSetting "ShowAllNotifications", "False" printJob.SetProfileSetting "SubjectTemplate", itemFolder.Name printJob.AddAction("Stamping") printJob.SetProfileSetting "Stamping.StampText", itemFolder.Name printJob.SetProfileSetting "Stamping.FontAsOutline", "False" printJob.SetProfileSetting "Stamping.FontSize", colArgs.item("fontSize") index = index + 1 printJob.ConvertTo(colArgs.item("startPath") & "\" & itemFolder.Name & "\converted\" & objFSO.GetBaseName(itemFile.Name) & "_" & index & ".pdf" ) If (Not printJob.IsFinished Or Not printJob.IsSuccessful) Then stdout.WriteLine "ERROR convirtiendo " & itemFile.Name & " se cancela proceso." objPDFCreatorQueue.ReleaseCom WScript.Quit Else End If stdout.WriteLine "Conversion finalizada" WScript.Sleep colArgs.item("waitFile") WEnd End If End If Next Next stdout.WriteLine "*** Generando archivo unificado por orden" For Each itemFolder In itemFolders index = 0 For Each itemConvertedFolder In itemFolder.SubFolders If itemConvertedFolder.Name = "converted" Then For Each itemConvertedFile In itemConvertedFolder.Files index = index + 1 pathfile = " /PrintFile=""" & itemConvertedFile & """" objShell.ShellExecute colArgs.item("pdfCreatorPath"), pathfile , "", "open", 0 stdout.WriteLine "Se ejecuto pdrcreator para:" & pathfile & " JobCount=" & objPDFCreatorQueue.Count 'WScript.Sleep 2 * colArgs.item("waitFile") Next End If Next If index > 0 Then stdout.WriteLine "Se espera WaitForJob(120) JobCount=" & objPDFCreatorQueue.Count If Not objPDFCreatorQueue.WaitForJobs(index,120) Then stdout.WriteLine "Despues de 60 segundos no hay ningun proceso para convertir, se cancela." objPDFCreatorQueue.ReleaseCom WScript.Quit Else 'WScript.Sleep index * colArgs.item("waitFile") stdout.WriteLine "Antes de hacer el mergeall JobCount=" & objPDFCreatorQueue.Count objPDFCreatorQueue.MergeAllJobs stdout.WriteLine "Despues de hacer el mergeall JobCount=" & objPDFCreatorQueue.Count While objPDFCreatorQueue.Count > 0 stdout.WriteLine "Entra while con jobcount=" & objPDFCreatorQueue.Count Set printJob = objPDFCreatorQueue.NextJob printJob.SetProfileByGuid("DefaultGuid") printJob.ConvertTo(colArgs.item("startPath") & "\" & ItemFolder.Name & ".pdf") If (Not printJob.IsFinished Or Not printJob.IsSuccessful) Then stdout.WriteLine "ERROR convirtiendo " & ItemFolder.Name & " se cancela proceso." objPDFCreatorQueue.ReleaseCom WScript.Quit Else End If WEnd stdout.WriteLine "Conversion finalizada Orden - " & "\" & itemFolder.Name & ".pdf" End If End If Next stdout.WriteLine "*** Generando archivo unificado" index = 0 For Each ItemPDFFile In (objFSO.GetFolder(colArgs.item("startPath"))).Files index = index + 1 pathfile = " /PrintFile=""" & ItemPDFFile & """" objShell.ShellExecute colArgs.item("pdfCreatorPath"), pathfile , "", "open", 0 'WScript.Sleep 3 * colArgs.item("waitFile") Next If index > 0 Then If Not objPDFCreatorQueue.WaitForJobs(index,120) Then stdout.WriteLine "Despues de 120 segundos no hay ningun proceso para convertir, se cancela." objPDFCreatorQueue.ReleaseCom WScript.Quit Else 'WScript.Sleep index * colArgs.item("waitFile") stdout.WriteLine "Antes de hacer el mergeall JobCount=" & objPDFCreatorQueue.Count objPDFCreatorQueue.MergeAllJobs stdout.WriteLine "Despues de hacer el mergeall JobCount=" & objPDFCreatorQueue.Count While objPDFCreatorQueue.Count > 0 stdout.WriteLine "Entra while con jobcount=" & objPDFCreatorQueue.Count Set printJob = objPDFCreatorQueue.NextJob printJob.SetProfileByGuid("DefaultGuid") printJob.ConvertTo(colArgs.item("outputFile")) If (Not printJob.IsFinished Or Not printJob.IsSuccessful) Then stdout.WriteLine "ERROR convirtiendo " & ItemFolder.Name & " se cancela proceso." objPDFCreatorQueue.ReleaseCom WScript.Quit Else End If WEnd stdout.WriteLine "Conversion finalizada - " & colArgs.item("outputFile") End If End If objPDFCreatorQueue.ReleaseCom 'objExcel.Quit 'Set objExcel = Nothing 'For each itemFolder in itemFolders 'if objFSO.FileExists( colArgs.item("startPath") & "\" & ItemFolder.Name & ".pdf" ) then 'objFSO.DeleteFile colArgs.item("startPath") & "\" & ItemFolder.Name & ".pdf" 'end if 'if colArgs.item("deleteTmp") = "X" then 'objFSO.DeleteFolder colArgs.item("startPath") & "\" & ItemFolder.Name 'else 'objFSO.DeleteFolder colArgs.item("startPath") & "\" & ItemFolder.Name & "\converted" 'end if 'Next