1 (изменено: Andrey.Fetisov, 2013-06-13 14:23:05)

Тема: VBS: Печать файлов группами по 6 на pdfcreator и авто объединение.

Всем привет.
Документы создаются путём печати на PDFCreator в виде PDF файлов по 6 шт - к одному клиенту (вручную объединяем в 1ин PDF), потом еще 6 к другому клиенту (опять объединяем) и т.д. по каждому из 50-100 клиентов ежедневно.

ВОПРОС. Как объединять их по 6 файлов в один автоматически? Прикрепил пояснение диаграмму.
КАК написать чтоб файлы отправлялись на печать группами по 6 шт для объединения в один файл?
Псевдокод группировки файлов по 6 шт - группа1 - печать - удаление Группы1 - еще 6 шт - группа2 - печать - удаление группы2 и т.д. пока файлы не кончатся.
Как то так? :
For Each File in Folder.Files
    Count.Files.select=6
    Print.Count.Files
c.CombyneAll
Delete Count.Files
next
Вот код показывающий по очереди все файлы в директории:


Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder("C:")
MsgBox Folder.Files.Count
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder("C:\")
For Each File In Folder.Files
    WScript.Echo File.Name
Next

Нашел классный скрипт CombyneJobs.vbs который обращаясь к PDFCreator создает текстовые файлы и комбинирует в один PDF файл.

Нужно объединять файлы по 6 штук = комплект для одного клиента. Вместо создания текстовых файлов как в этом скрипте (CreateTextfileAndPrint). Вот код:

' CombineJobs script
' Part of PDFCreator
' License: GPL
' Homepage: http://www.pdfforge.org/products/pdfcreator
' Windows Scripting Host version: 5.1
' Version: 1.0.0.0
' Date: September, 1. 2005
' Author: Frank Heindцrfer
' Comments: This script combines some printjobs in one pdf.

Option Explicit

Const maxTime = 30    ' in seconds
Const sleepTime = 250 ' in milliseconds

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

Set fso = CreateObject("Scripting.FileSystemObject")

ScriptBaseName = fso.GetBaseName(Wscript.ScriptFullname)

AppTitle = "PDFCreator - " & ScriptBaseName

If CDbl(Replace(WScript.Version,".",",")) < 5.1 then
 MsgBox "You need the ""Windows Scripting Host version 5.1"" or greater!", vbCritical + vbSystemModal, AppTitle
 Wscript.Quit
End if

opath = CompletePath(fso.GetParentFolderName(Wscript.ScriptFullname))

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

Set PDFCreator = Wscript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")
PDFCreator.cStart "/NoProcessingAtStartup"

With PDFCreator
 .cPrinterStop = true
 .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"

 Wscript.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 While (.cCountOfPrintjobs <> 1) and (c < (maxTime * 1000 / sleepTime))
  c = c + 1
  Wscript.Sleep sleepTime
 Loop

 .cPrinterStop = False
End With

c = 0
ReadyState = 0
Do While (ReadyState = 0) and (c < (maxTime * 1000 / sleepTime))
 c = c + 1
 Wscript.Sleep sleepTime
Loop

If ReadyState = 0 then
 MsgBox "An error is occured: Time is up!", vbExclamation + vbSystemModal, AppTitle
 Wscript.quit
End If

With PDFCreator
 .cDefaultprinter = DefaultPrinter
 Wscript.Sleep 200
 .cClose
End With

Public Sub CreateTextfileAndPrint(Filename, Content)
 Dim fso, f
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f = fso.CreateTextFile(Filename, True)
 f.WriteLine(Content)
 f.Close
 PDFCreator.cPrintfile cStr(Filename)
 WScript.Sleep 2000                                        ' Wait until the file is printed
 fso.DeleteFile(Filename)
End Sub

Private Function CompletePath(Path)
 If Right(Path, 1) <> "\" Then
   CompletePath = Path & "\"
  Else
   CompletePath = Path
 End If
End Function

'--- PDFCreator events ---

Public Sub PDFCreator_eReady()
 ReadyState = 1
End Sub

Public Sub PDFCreator_eError()
 MsgBox "An error is occured!" & vbcrlf & vbcrlf & _
  "Error [" & PDFCreator.cErrorDetail("Number") & "]: " & PDFcreator.cErrorDetail("Description"), vbCritical + vbSystemModal, AppTitle
 Wscript.Quit
End Sub