Remove blank PDF pages with A-PDF Scan Optimizer

Recently I posted about A-PDF Page Cut, which was able to split PDF pages in half, it turns out that once you do this you get a lot of blank pages (not nice for your Kindle). Conveniently, produced by the same company is A-PDF Scan Optimizer which removes these blank pages. A-PDF Scan Optimizer does have a number of other features tailored to page scanning documents, included de-skewing, and rescaling, but I was only interested in the blank page removal feature.

To remove blank pages of a non-scanned PDF, Scan Optimizer is very straight forward to use, but if you have scanned PDFs which may have some grey shades on the blank pages, it may require a bit of tweaking to get right.

A-PDF Scan Optimizer startup interface

Once you have “Turned On” the Delete Blank Pages option click Settings to bring up the options.

A-PDF Scan Optimizer delete blank settings

Though the help is non-existent for the Delete Blank Pages settings, there are two main settings to change and these are used to determine if a page is considered blank;

  • Black\white value – grey scale images have 256 shades of grey (0 being black and 255 being white), this setting sets the threshold to determine what should be black and what should be white, a setting of 128 means half the greys shades are white and half are black. If there are slight grey shades on your blank pages, this should be set so that you can no longer see them on the preview.
  • Threshold value – now that the image is black and white only, what is the faction of acceptable black on the page to still consider the page blank. This is useful if there are black specs on the pages. A value of 0.001 means 0.1% of the page can have black on it and still be considered blank. Set this high enough so that you get a result of “blank”.

Since my PDFs all originated from a digital source, I set them to the extreme settings of 255 and 0.00001. Click Optimize and Save As, the Scan Optimizer will batch process the list of PDFs and log which pages were deleted.

Rigid file manipulation functions for VBA/VBS

Ever since starting work I have been learning and using VBA/VBS to make life easier. I will start posting some of my generic functions as a source for others. They may not be written optimally, but they do work.

' Function: fileExist(sPathFile) returns True if a file exists
' Input: sPathFile - the file (including path) to determine if exists
' Output: fileExists - returns true if file exists
' Notes: network shared drives work as well.
Function fileExist(sPathFile) As Boolean
    On Error Resume Next
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    fileExist = fso.FileExists(sPathFile)
    Set fso = Nothing
End Function

' Function: renameFile(oldName, newName) renames a file, can also be used to move a file
' Inputs: oldName - file including path to be renamed
'         newName - file including path of the renamed or moved file
' Notes: renameFile checks if the file exists and the new path exists before renaming or moving
' Dependants: fileExists
Function renameFile(oldName, newName)
    On Error Resume Next
    If fileExist(oldName) And Dir(Left(newName, InStrRev(newName, "/")), vbDirectory) <> vbNullString Then
        Dim fso
        Set fso = CreateObject("Scripting.FileSystemObject")
        fso.MoveFile oldName, newName
        Set fso = Nothing
    End If
End Function

' Function: deleteFile(sPathFile) deletes a file
' Input: sPathFile - the file (including path) to be deleted i.e. "C:/a.txt"
' Notes: deleteFile checks if the file exists first before deleting
' Dependants: deleteFile
Function deleteFile(sPathFile)
    On Error Resume Next
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(sPathFile) Then fso.GetFile(sPathFile).Delete
    Set fso = Nothing
End Function

' Function: copyFile(fileName, copyName) copies a file
' Inputs: fileName - file to be copied, path and file required i.e. "C:/a.txt"
'         copyName - the copied file, path and file required i.e. "C:/b.txt"
' Notes: copyFile checks if fileName exists, as well as the copyName folder
'        if copyName is already present the file is deleted
' Dependants: fileExists, deleteFile
Function copyFile(fileName, copyName)
    On Error Resume Next
    If fileExist(fileName) And Dir(Left(copyName, InStrRev(copyName, "/")), vbDirectory) <> vbNullString Then
        Call deleteFile(copyName)
        Dim fso
        Dim aFile
        Set fso = CreateObject("Scripting.FileSystemObject")
        fso.copyFile fileName, copyName, True
        Set aFile = fso.GetFile(copyName)
        If aFile.Attributes And 1 Then
            aFile.Attributes = aFile.Attributes - 1
        End If
        Set fso = Nothing
        Set aFile = Nothing
    End If
End Function