<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: Печать файлов группами по 6 на pdfcreator и авто объединение.]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=8386&amp;type=atom" />
	<updated>2013-06-11T12:11:44Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=8386</id>
		<entry>
			<title type="html"><![CDATA[VBS: Печать файлов группами по 6 на pdfcreator и авто объединение.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=72916#p72916" />
			<content type="html"><![CDATA[<p>Всем привет. <br />Документы создаются путём печати на PDFCreator в виде PDF файлов по 6 шт - к одному клиенту (вручную объединяем в 1ин PDF), потом еще 6 к другому клиенту (опять объединяем) и т.д. по каждому из 50-100 клиентов ежедневно. </p><p>ВОПРОС. Как объединять их по 6 файлов в один автоматически? Прикрепил пояснение диаграмму. <br />КАК написать чтоб файлы отправлялись на печать группами по 6 шт для объединения в один файл?<br />Псевдокод группировки файлов по 6 шт - группа1 - печать - удаление Группы1 - еще 6 шт - группа2 - печать - удаление группы2 и т.д. пока файлы не кончатся. <br />Как то так? :<br />For Each File in Folder.Files<br />&nbsp; &nbsp; Count.Files.select=6<br />&nbsp; &nbsp; Print.Count.Files<br />c.CombyneAll<br />Delete Count.Files<br />next<br />Вот код показывающий по очереди все файлы в директории:<br /></p><div class="codebox"><pre><code>
Set FSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set Folder = FSO.GetFolder(&quot;C:&quot;)
MsgBox Folder.Files.Count
Set FSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set Folder = FSO.GetFolder(&quot;C:\&quot;)
For Each File In Folder.Files
    WScript.Echo File.Name
Next
</code></pre></div><p>Нашел классный скрипт <a href="http://code.metager.de/source/xref/pdfcreator/COM/Samples/Windows%20Scripting%20Host/VBScript/CombineJobs.vbs?r=324">CombyneJobs.vbs</a> который обращаясь к PDFCreator создает текстовые файлы и комбинирует в один PDF файл. </p><p>Нужно объединять файлы по 6 штук = комплект для одного клиента. Вместо создания текстовых файлов как в этом скрипте (CreateTextfileAndPrint). Вот код:<br /></p><div class="codebox"><pre><code>&#039; CombineJobs script
&#039; Part of PDFCreator
&#039; License: GPL
&#039; Homepage: http://www.pdfforge.org/products/pdfcreator
&#039; Windows Scripting Host version: 5.1
&#039; Version: 1.0.0.0
&#039; Date: September, 1. 2005
&#039; Author: Frank Heindцrfer
&#039; Comments: This script combines some printjobs in one pdf.

Option Explicit

Const maxTime = 30    &#039; in seconds
Const sleepTime = 250 &#039; in milliseconds

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

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)

ScriptBaseName = fso.GetBaseName(Wscript.ScriptFullname)

AppTitle = &quot;PDFCreator - &quot; &amp; ScriptBaseName

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

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

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

Set PDFCreator = Wscript.CreateObject(&quot;PDFCreator.clsPDFCreator&quot;, &quot;PDFCreator_&quot;)
PDFCreator.cStart &quot;/NoProcessingAtStartup&quot;

With PDFCreator
 .cPrinterStop = true
 .cOption(&quot;UseAutosave&quot;) = 1
 .cOption(&quot;UseAutosaveDirectory&quot;) = 1
 .cOption(&quot;AutosaveDirectory&quot;) = opath
 .cOption(&quot;AutosaveFilename&quot;) = Scriptbasename
 DefaultPrinter = .cDefaultprinter
 .cDefaultprinter = &quot;PDFCreator&quot;
 .cClearcache

 &#039; 1. page
 CreateTextfileAndPrint opath &amp; &quot;1.txt&quot;, &quot;1&quot;

 &#039; 2. page
 CreateTextfileAndPrint opath &amp; &quot;2.txt&quot;, &quot;2&quot;

 &#039; 3. page
 CreateTextfileAndPrint opath &amp; &quot;3.txt&quot;, &quot;3&quot;

 &#039; 4. page
 CreateTextfileAndPrint opath &amp; &quot;4.txt&quot;, &quot;4&quot;

 Wscript.Sleep 2000                                        &#039; Wait until all files are printed

 &#039; Page order: 1 2 3 4

 &#039;.cMovePrintjobTop 3 
  Page order: 3 1 2 4

  
 &#039;.cMovePrintjobBottom 2
  Page order: 3 2 4 1

 &#039;.cMovePrintjobDown 2
  Page order: 3 4 2 1

 &#039;.cMovePrintjobUp 2
  Page order: 4 3 2 1

 &#039;.cDeletePrintjob 1
  Page order: 3 2 1

 .cCombineAll

 c = 0
 Do While (.cCountOfPrintjobs &lt;&gt; 1) and (c &lt; (maxTime * 1000 / sleepTime))
  c = c + 1
  Wscript.Sleep sleepTime
 Loop

 .cPrinterStop = False
End With

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

If ReadyState = 0 then
 MsgBox &quot;An error is occured: Time is up!&quot;, 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(&quot;Scripting.FileSystemObject&quot;)
 Set f = fso.CreateTextFile(Filename, True)
 f.WriteLine(Content)
 f.Close
 PDFCreator.cPrintfile cStr(Filename)
 WScript.Sleep 2000                                        &#039; Wait until the file is printed
 fso.DeleteFile(Filename)
End Sub

Private Function CompletePath(Path)
 If Right(Path, 1) &lt;&gt; &quot;\&quot; Then
   CompletePath = Path &amp; &quot;\&quot;
  Else
   CompletePath = Path
 End If
End Function

&#039;--- PDFCreator events ---

Public Sub PDFCreator_eReady()
 ReadyState = 1
End Sub

Public Sub PDFCreator_eError()
 MsgBox &quot;An error is occured!&quot; &amp; vbcrlf &amp; vbcrlf &amp; _
  &quot;Error [&quot; &amp; PDFCreator.cErrorDetail(&quot;Number&quot;) &amp; &quot;]: &quot; &amp; PDFcreator.cErrorDetail(&quot;Description&quot;), vbCritical + vbSystemModal, AppTitle
 Wscript.Quit
End Sub
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Andrey.Fetisov]]></name>
			</author>
			<updated>2013-06-11T12:11:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=72916#p72916</id>
		</entry>
</feed>
