Bluepoint Design

Practical cost effective solutions   
Macro Express Sample Macro: Fax PDF Breakup

Home
Up
Multiple Choice Trick
Multiple Multiple Choice
Occurrences
Repeat Validation
GoTo
First file
Fax PDF Breakup
Day of Year
Multiple Attachments
Multiple eMail Addresses
Text Padding
Building TSV Files
This is a stand alone macro that breaks up a fax into several files. Describing the need is easier than the function so let me try that. I have a client that receives faxes as PDF but sometimes a fax will come in with a cover and individual pages for several participants. The standard is that a copy of each of these be saved per participant but we don't want the other pages germane to others in this filed copy. But we want to keep the cover pages. So this macro makes the necessary number of PDFs and deletes the superfluous pages. This is actually part of a much larger macro but this runs fine by itself. It's just not as clean as I would like for posting but I'm not going to spend the time. Basically it will ask you for the file, number of cover pages and the number of pages per participant. Then it will test to make sure the number jive with the total number of pages. Then it creates multiple files, deletes the original and parses out the pages.

This macro requires my Delete to Recycle Bin subroutine. Often I use this on network files and I loath the way Windows just deletes a file instead of moving it to the recycle so this copies the file to the local hard drive and then deletes it so it will go to the Recycle Bin.

The sample file is a playable macro which you can simply download and launch.

Page last updated: 02/05/2008

Fax_Breakup.mxe
Macro Script
Pause: Complex
Activate or Launch: "Adobe Acrobat Professional" OR "Acrobat.exe"
// Set source file
// T2 Get source file and date from file T7 from N3 N4 N5
Variable Set String %T2% from File Name
// Launch the source file
Program Launch: "%T2%"
Wait For Window Title: "Adobe Acrobat Professional"
// Get path of file and propose to user as destination while allowing them to change.
Variable Set From File Path
Variable Set String %T21% "%T21%%T22%"
If Message: "Destination Directory for File Fragments"
Else
  Variable Set String %T21% from Folder Name
End If
// Get the total number of pages from acrobat using the Delete Pages dialog
Text Type: <END>
Text Type: <SHIFT><CONTROL>d
Wait For Window Title: "Delete Pages"
Delay 250 Milliseconds
Clipboard Copy
Variable Set Integer %N8% from Clipboard
Get Control %C1% (Delete Pages: RichEdit20W)
Get Control %C2% (Delete Pages: RichEdit20W)
Get Control %C3% (Delete Pages: Button)
Get Control %C4% (Delete Pages: Button)
Get Control %C5% (Adobe Acrobat: Button)
Mouse Single Left Click on Control %C4%
Delay 100 Milliseconds
Text Type: <HOME>
// Repeat to make sure thet get a valid number of pages
Repeat Until %N10% = 1
  // Get the number of cover pages and the per participant pages from user.
  Repeat Until %N6% >= 0
    Variable Set Integer %N6% from Prompt
  Repeat End
  Repeat Until %N7% > 0
    Variable Set Integer %N7% from Prompt
  Repeat End
  // Convert page integers to decimal
  Variable Modify Integer: Convert %N6% to decimal %D6%
  Variable Modify Integer: Convert %N7% to decimal %D7%
  Variable Modify Integer: Convert %N8% to decimal %D8%
  // Calculate the number of pages if there were two participants
  Variable Modify Decimal: %D9% = 2 * %D7%
  Variable Modify Decimal: %D9% = %D6% + %D9%
  // Test if there is a minimum number of pages.
  If Variable %D9% > variable %D8%
    Pause: Complex
    Macro Stop
  End If
  // Validate the user value combination
  Variable Modify Decimal: %D9% = %D8% - %D6%
  Variable Modify Decimal: %D9% = %D9% / %D7%
  Variable Modify Decimal: Truncate %D9% to integer %N9%
  Variable Modify Decimal: Copy %D9% to %D10%
  Round Decimal Variable %D10% to 0 decimal places
  If Variable %D9% <> variable %D10%
    Pause: Complex
    Macro Stop
  End If
  Variable Set Integer %N10% to 1
Repeat End
// Close the file
Activate Window: "Adobe Acrobat Professional"
Delay 100 Milliseconds
Text Type: <CONTROL><SHIFT><F4>
Wait for File Ready: "%T2%"
Delay 1 Seconds
// Create PDF's to modify and move original to recycle bin
Repeat with Variable using %N9%
  If File Exists "%T21%Breakup %T23% %N11%.pdf"
    Pause: Complex
    Repeat Exit
  End If
  Text Box Display: Creating duplicate files
  Copy File or Files: "%T2%"
  Text Box Close: Creating duplicate files
Repeat End
Wait for File Ready: "%T2%"
Write Registry String: "feedback"
Macro Run: Delete to recycle bin
// Open each PDF and delete extra pages
Repeat with Variable using %N9%
  // Calculate begining and ends of each deleteint range. Before and after participant's file.
  Variable Modify Integer: %N12% = %N6% + 1
  Variable Modify Integer: %N13% = %N11% - 1
  Variable Modify Integer: %N13% = %N13% * %N7%
  Variable Modify Integer: %N13% = %N6% + %N13%
  Variable Modify Integer: %N14% = %N7% + %N13%
  Variable Modify Integer: Inc (%N14%)
  // Launch the file...
  Program Launch: "%T21%Breakup %T23% %N11%.pdf"
  Wait For Window Title: "Adobe Acrobat Professional"
  // Delete the last range of pages if not the last itteration
  If Variable %N11% < variable %N9%
    Text Type: <SHIFT><CONTROL>d
    Wait For Window Title: "Delete Pages"
    Delay 250 Milliseconds
    Text Type: %N14%
    Text Type: <TAB>
    Text Type: %N8%
    Mouse Single Left Click on Control %C3%
    Wait for Control %C5% to become visible
    Mouse Single Left Click on Control %C5%
    Wait For Window Title: "Adobe Acrobat Professional"
    Delay 250 Milliseconds
  End If
  // Delete the first range of pages if not the first itteration
  If Variable %N11% > 1
    Text Type: <SHIFT><CONTROL>d
    Wait For Window Title: "Delete Pages"
    Delay 250 Milliseconds
    Text Type: %N12%
    Text Type: <TAB>
    Text Type: %N13%
    Mouse Single Left Click on Control %C3%
    Wait for Control %C5% to become visible
    Mouse Single Left Click on Control %C5%
    Wait For Window Title: "Adobe Acrobat Professional"
    Delay 250 Milliseconds
  End If
  // Close PDF and save
  Text Type: <CONTROL><SHIFT><F4>
  Get Control %C6% (Adobe Acrobat: Button)
  Wait for Control %C6% to become visible
  Mouse Single Left Click on Control %C6%
  Wait for File Ready: "%T21%Breakup %T23% %N11%.pdf"
Repeat End
Open Folder: %T21%
Pause: Complex
Macro Text
<PAUSE2:Center,CenterThis macro will break up a fax PDF into seperate files.T><LAUNCHYES3:2:0360Adobe Acrobat Professional<LAUNCH:C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe2><REM2:Set source file><REM2:T2 Get source file and date from file T7 from N3 N4 N5><TVAR2:02:09:Source file><REM2:Launch the source file><LAUNCHDEL2:0:01%T2%2><WAITWIN2:000010:000000:Adobe Acrobat Professional><REM2:Get path of file and propose to user as destination while allowing them to change.><VFFILE:1:T:21:T:22:T:23:F:1:%T2%><TVAR2:21:01:%T21%%T22%><IFMESS3:00000:1:4:Destination Directory for File Fragments%T21% Is this location OK for the resultant files?Location OKNew LocationCenter:Center><ELSE><TVAR2:21:10:Location for resultant files><ENDIF><REM2:Get the total number of pages from acrobat using the Delete Pages dialog><TEXTTYPE:<END>><TEXTTYPE:<SHIFT><CONTROL>d><WAITWIN2:000000:000010:Delete Pages><MSD:250><CLIPC><IVAR2:08:11:><GETCONTROL2:01:ACROBAT.EXE:#32770Delete Pages003:1Static1Static3RichEdit20W><GETCONTROL2:02:ACROBAT.EXE:#32770Delete Pages003:1Static1Static5RichEdit20W><GETCONTROL2:03:ACROBAT.EXE:#32770Delete Pages003:1Static1Static7Button><GETCONTROL2:04:ACROBAT.EXE:#32770Delete Pages003:1Static1Static8Button><GETCONTROL2:05:ACROBAT.EXE:#32770Adobe Acrobat003:1Static1Static4Button><CCLICK:T:04:0:T:><MSD:100><TEXTTYPE:<HOME>><REM2:Repeat to make sure thet get a valid number of pages><REP3:08:000001:000002:0010:0:01:1><REM2:Get the number of cover pages and the per participant pages from user.><REP3:08:000005:000002:0006:0:01:0><IVAR2:06:02:FHow many cover pages are there?FFCenter:Center><ENDREP><REP3:08:000004:000002:0007:0:01:0><IVAR2:07:02:FHow many pages per participant?FFCenter:Center><ENDREP><REM2:Convert page integers to decimal><NMVAR:06:06:0:0000006:0:0000000><NMVAR:06:07:0:0000007:0:0000000><NMVAR:06:08:0:0000008:0:0000000><REM2:Calculate the number of pages if there were two participants><DMVAR:03:09:2:2:1:000000000000007.0000><DMVAR:01:09:1:000000000000006.0000:1:000000000000009.0000><REM2:Test if there is a minimum number of pages.><IFVAR2:6:09:4:D8><PAUSE2:Center,CenterError: The sum of cover pages and 2 participants must be less than ot equal to the total number of pages. Please try again.T><MSTOP><ENDIF><REM2:Validate the user value combination><DMVAR:02:09:1:000000000000008.0000:1:000000000000006.0000><DMVAR:04:09:1:000000000000009.0000:1:000000000000007.0000><DMVAR:06:09:1:000000000000009.0000:1:000000000000000.0000><DMVAR:07:09:1:000000000000010.0000:1:000000000000000.0000><ROUND:10:0><IFVAR2:6:09:2:D10><PAUSE2:Center,CenterError: Total number of pages less cover needs to be evenly divisible by the pages per participant. Try again.T><MSTOP><ENDIF><IVAR2:10:01:1><ENDREP><REM2:Close the file><ACTIVATE2:Adobe Acrobat Professional><MSD:100><TEXTTYPE:<CONTROL><SHIFT><F4>><WFREADY:000000:000000:000000%T2%><DELAY:1><REM2:Create PDF's to modify and move original to recycle bin><REP3:05:000001:000001:0009:1:11:><IFOTH:01:2:%T21%Breakup %T23% %N11%.pdf><PAUSE2:Center,CenterError: File name already exists. T><EXITREP><ENDIF><TBOX4:T:3:CenterCenter000278000200:000:Creating duplicate filesCopying file %N11% of %N9%><DOFILE:05:YN:%T2%>%T21%Breakup %T23% %N11%.pdf><TBCLOSE:Creating duplicate files><ENDREP><WFREADY:000000:000030:000000%T2%><REGWSTR:2:HKEY_LOCAL_MACHINE\SOFTWARE\Insight Software Solutions\Macro Express\Miscellaneous\feedback><MACRUN2:Delete to recycle bin><REM2:Open each PDF and delete extra pages><REP3:05:000001:000001:0009:1:11:><REM2:Calculate begining and ends of each deleteint range. Before and after participant's file.><NMVAR:01:12:1:0000006:2:0000001><NMVAR:02:13:1:0000011:2:0000001><NMVAR:03:13:1:0000013:1:0000007><NMVAR:01:13:1:0000006:1:0000013><NMVAR:01:14:1:0000007:1:0000013><NMVAR:08:14:0:0000001:0:0000000><REM2:Launch the file...><LAUNCHDEL2:0:01%T21%Breakup %T23% %N11%.pdf2><WAITWIN2:000010:000000:Adobe Acrobat Professional><REM2:Delete the last range of pages if not the last itteration><IFVAR2:5:11:3:N9T><TEXTTYPE:<SHIFT><CONTROL>d><WAITWIN2:000000:000010:Delete Pages><MSD:250><TEXTTYPE:%N14%><TEXTTYPE:<TAB>><TEXTTYPE:%N8%><CCLICK:T:03:0:T:><WAITCONTROL:000000:000030:05:02><CCLICK:T:05:0:T:><WAITWIN2:000010:000000:Adobe Acrobat Professional><MSD:250><ENDIF><REM2:Delete the first range of pages if not the first itteration><IFVAR2:2:11:4:1><TEXTTYPE:<SHIFT><CONTROL>d><WAITWIN2:000000:000010:Delete Pages><MSD:250><TEXTTYPE:%N12%><TEXTTYPE:<TAB>><TEXTTYPE:%N13%><CCLICK:T:03:0:T:><WAITCONTROL:000000:000030:05:02><CCLICK:T:05:0:T:><WAITWIN2:000010:000000:Adobe Acrobat Professional><MSD:250><ENDIF><REM2:Close PDF and save><TEXTTYPE:<CONTROL><SHIFT><F4>><GETCONTROL2:06:ACROBAT.EXE:#32770Adobe Acrobat003:1Static1Static4Button><WAITCONTROL:000010:000000:06:02><CCLICK:T:06:0:T:><WFREADY:000002:000000:000000%T21%Breakup %T23% %N11%.pdf><ENDREP><MYCOMP:%T21%><PAUSE2:Center,CenterAll done!T>

Here is file to experiment with.
 

Fax_Breakup.pdf
Support File
This is a sample PDF to use with the macro
 
Practical cost effective solutions