litlmike Posted August 27, 2020 Share Posted August 27, 2020 Because of coronavirus I have to make student packets every week. It's roughly 10 pages front and back that each student gets a week. Those 10 pages are identical for every student. However I need an individual cover sheet that has the student name and other data on it. I use Mail Merge via Word for it, but I can export to a PDF. I am paying for a copy place to staple them together for me, so what I need is 54 individual PDF files that have the 10 pages plus the unique cover page on top of it. Any thoughts on how to accomplish this? _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
Danp2 Posted August 27, 2020 Share Posted August 27, 2020 Why not give them two PDFs - one containing the 10 pages and the other containing the cover sheets? They could simply put a cover sheet with each packet and then staple them together. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
litlmike Posted August 27, 2020 Author Share Posted August 27, 2020 1 hour ago, Danp2 said: Why not give them two PDFs - one containing the 10 pages and the other containing the cover sheets? They could simply put a cover sheet with each packet and then staple them together. They said they can't do it. That it has to be a combined file. They said they can't do cover sheets. _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
Nine Posted August 27, 2020 Share Posted August 27, 2020 (edited) So if I understand you correctly, you have a word document that contains the first 10 identical pages, plus a second word document that contains 54 different pages, one page per student. You want to merge both documents and save 54 different PDF documents thru the print functionality of Word. Is that it ? Edited August 27, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
water Posted August 27, 2020 Share Posted August 27, 2020 There are many command line tools available to combine PDFs. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
litlmike Posted August 27, 2020 Author Share Posted August 27, 2020 43 minutes ago, Nine said: So if I understand you correctly, you have a word document that contains the first 10 identical pages, plus a second word document that contains 54 different pages, one page per student. You want to merge both documents and save 54 different PDF documents thru the print functionality of Word. Is that it ? Not quite. I have File A (cover page) that is 54 pages long, and each page is unique to student name. One page needs to be distributed to each set of the File B for each student packet. I have File B that is ten pages long (body of the packet). Those need to be copied 54 times and have a cover page (File A) put on them. Student #1 gets: Cover Page #1 - File A (unique page) Body of the Packet - File B (not unique) Student #54 gets: Cover Page #54 - File A (unique page) Body of the Packet - File B (not unique) _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
Nine Posted August 27, 2020 Share Posted August 27, 2020 I was understanding it correctly. What I need to know is the format of File A and File B. Cause if they are MS-Word documents, the script would be totally different from PDF documents. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Danp2 Posted August 27, 2020 Share Posted August 27, 2020 I've used PDFsam in the past for a similar project. Decibel 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
litlmike Posted August 27, 2020 Author Share Posted August 27, 2020 22 minutes ago, Nine said: I was understanding it correctly. What I need to know is the format of File A and File B. Cause if they are MS-Word documents, the script would be totally different from PDF documents. Oh sorry, they can both be PDF if that is easier. Flie A is a .docx that I convert to PDF for printing purposes, but whatever is easier. File B is a PDF. _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
litlmike Posted August 27, 2020 Author Share Posted August 27, 2020 18 minutes ago, Danp2 said: I've used PDFsam in the past for a similar project. Cool I will look at it now. _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
litlmike Posted August 27, 2020 Author Share Posted August 27, 2020 59 minutes ago, Danp2 said: I've used PDFsam in the past for a similar project. Is it possible to do this with AutoIt as well? _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
Danp2 Posted August 27, 2020 Share Posted August 27, 2020 Yes... by repeatedly calling PDFSam with the appropriate parameters to extract and merge the designated files. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
water Posted August 27, 2020 Share Posted August 27, 2020 I use PDFSam too - great tool that does exactly what you need My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
robertocm Posted August 28, 2020 Share Posted August 28, 2020 I use the command line version from the author of PDFSam: https://sejda.org/ An example of addbackpages command: "Takes one or more pages from a PDF document and adds them to one or more PDF documents after each 'n' pages." expandcollapse popup#include <Constants.au3> Global $iPID, $sOutput = "" ;$iPID = Run(@ComSpec & " /C " & '"' & @ScriptDir & '\sejda-console-2.10.4\bin\sejda-console.bat" merge -h', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;$iPID = Run(@ComSpec & " /C " & '"' & @ScriptDir & '\sejda-console-2.10.4\bin\sejda-console.bat" merge -l C:\files.csv -o C:\output.pdf --overwrite', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Global $sFolder = "C:\escaner\", $sFileName = '', $sText = '' ;Assign a Local variable the search handle of all files in the directory. Local $hSearch = FileFindFirstFile($sFolder & "*.pdf") ;Check if the search was successful, if not display a message and exit If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.") Exit EndIf While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop $sText &= " " & $sFolder & $sFileName WEnd ;Close the search handle. FileClose($hSearch) $sText = StringMid($sText,2) ;$iPID = Run(@ComSpec & " /C """ & @ScriptDir & "\sejda-console-2.10.4\bin\sejda-console.bat"" merge -l C:\FILEST~1\files.csv -o C:\FILEST~1\output.pdf --overwrite", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;$sFileShort= FileGetShortName($sFolder) ;$iPID = Run(@ComSpec & " /C """ & @ScriptDir & "\sejda-console-2.10.4\bin\sejda-console.bat"" merge -l " & $sFileShort & "files.csv -o " & $sFileShort & "output.pdf --overwrite", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $iPID = Run(@ComSpec & " /C """ & @ScriptDir & "\sejda-console-2.10.4\bin\sejda-console.bat"" addbackpages -f " & $sText & " -b " & @ScriptDir & "\TEST.pdf -o " & $sFolder & " -j overwrite", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) ConsoleWrite($sOutput) ;another option ;While 1 ; $sOutput &= StdoutRead($iPID, False, False) ; If @error Then ; ExitLoop ; EndIf ; Sleep(10) ;WEnd ;ConsoleWrite($sOutput) ;another option ;While 1 ; $sOutput = StdoutRead($iPID) ; If @error Then ExitLoop; ConsoleWrite($sOutput) ;WEnd An example of simplesplit #include <Constants.au3> Global $iPID, $sOutput = "" ;$iPID = Run(@ComSpec & " /C " & '"' & @ScriptDir & '\sejda-console-2.10.4\bin\sejda-console.bat" merge -h', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;$iPID = Run(@ComSpec & " /C " & '"' & @ScriptDir & '\sejda-console-2.10.4\bin\sejda-console.bat" merge -l C:\files.csv -o C:\output.pdf --overwrite', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Global $sFolder = "C:\escaner\", $sFileName = '', $sText = '' ;Assign a Local variable the search handle of all files in the directory. Local $hSearch = FileFindFirstFile($sFolder & "*.pdf") ;Check if the search was successful, if not display a message and exit If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.") Exit EndIf While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop $sText &= " " & $sFolder & $sFileName WEnd ;Close the search handle. FileClose($hSearch) $sText = StringMid($sText,2) $iPID = Run(@ComSpec & " /C """ & @ScriptDir & "\sejda-console-2.10.4\bin\sejda-console.bat"" simplesplit -f " & $sText & " -o " & $sFolder & " -s all -j overwrite", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) ConsoleWrite($sOutput) Link to comment Share on other sites More sharing options...
rudi Posted September 7, 2020 Share Posted September 7, 2020 Hi, IMHO pdftk is really easy to use from AutoIT: DESCRIPTION If PDF is electronic paper, then pdftk is an electronic staple-remover, hole-punch, binder, secret-decoder-ring, and X-Ray-glasses. Pdftk is a simple tool for doing everyday things with PDF documents. Use it to: * Merge PDF Documents or Collate PDF Page Scans * Split PDF Pages into a New Document * Rotate PDF Documents or Pages * Decrypt Input as Necessary (Password Required) * Encrypt Output as Desired * Fill PDF Forms with X/FDF Data and/or Flatten Forms * Generate FDF Data Stencils from PDF Forms * Apply a Background Watermark or a Foreground Stamp * Report PDF Metrics, Bookmarks and Metadata * Add/Update PDF Bookmarks or Metadata * Attach Files to PDF Pages or the PDF Document * Unpack PDF Attachments * Burst a PDF Document into Single Pages * Uncompress and Re-Compress Page Streams * Repair Corrupted PDF (Where Possible) this is a small part of a script written to recursively split a lot of multipage PDF files to single page PDFs: Func SplitPDF($_FullPathFileName) ; Syntax: pdftk <input.pdf> burst output <FileName_[format-spec].pdf> ; Example: pdftk c:\temp\PDF-Dok-A.pdf burst output c:\temp\PDF-Dok-A_%02d.pdf (_%02d will insert before the EXT: "_01", "_02", ... $pdftk = "pdftk.exe" ; installed using pdftk_server-2.02-win-setup.exe $pdftkDir = "C:\Program Files (x86)\PDFtk Server\bin" Local $RegExPathFnExt = "(?i)(^.*\\)(.*)(\.pdf$)" ; $1 = Path with trailing BACKSLASH, $2= FileName, $3 = ".PDF" Local $_Path = StringRegExpReplace($_FullPathFileName, $RegExPathFnExt, "$1") Local $_FN = StringRegExpReplace($_FullPathFileName, $RegExPathFnExt, "$2") Local $_Ext = StringRegExpReplace($_FullPathFileName, $RegExPathFnExt, "$3") Local $_pdftkParam = ' "' & $_FullPathFileName & '" burst output "' & $PDFOutDir & "\" & $_FN & "_%02d" & $_Ext & '"' Local $PID_TifSplit = Run(@ComSpec & " /c " & $pdftk & $_pdftkParam, $pdftkDir, @SW_SHOW, $STDERR_MERGED) ; $STDERR_MERGED --> chatch both, STDOUT and STDERR messages Local $pdftkTXT = "" While ProcessExists($PID_TifSplit) $pdftkTXT &= StdoutRead($PID_TifSplit) WEnd If StringStripWS($pdftkTXT, 8) = "" Then ; Keine Ausgaben außer WS --> kein Fehler ConsoleWrite("no errors recognized" & @CRLF) Else $ErrCount+=1 $ErrTXT &= $_FN & $_Ext & @CRLF & $pdftkTXT & @CRLF & "--------------------------" & @CRLF EndIf EndFunc ;==>SplitPDF Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
First_Project Posted September 7, 2020 Share Posted September 7, 2020 I am not good at coding but someone helped me on my code so I would like to put my two cents here. I think you can do it in easier way if above suggestion doesnt work. You can still use your mail merge to them and print then as PDF. Then you will end up with 540 pages of pdf file. You can then use other software like PDF-XCHANGE-Viewer to extract those file by every 10th pages, then you will end up with 54 individual files and then save it. Then you can use simple autoit script to click windows button to save those 54 individual files its much more easier. All the best! Link to comment Share on other sites More sharing options...
First_Project Posted September 7, 2020 Share Posted September 7, 2020 3 minutes ago, First_Project said: I am not good at coding but someone helped me on my code so I would like to put my two cents here. I think you can do it in easier way if above suggestion doesnt work. You can still use your mail merge to them and print then as PDF. Then you will end up with 540 pages of pdf file. You can then use other software like PDF-XCHANGE-Viewer to extract those file by every 10th pages, then you will end up with 54 individual files and then save it. Then you can use simple autoit script to click windows button to save those 54 individual files its much more easier. All the best! Or after mail merge, you can set simple autoit script to save as pdf every 10th page on mail merged word file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now