reduce pdf file size / compress pdf file size through Macro VBA

prati

Board Regular
Joined
Jan 25, 2021
Messages
51
Office Version
  1. 2019
Platform
  1. Windows
Hey,

I wonder if there is a way to reduce pdf file size through Macro VBA.
I don't have Adobe Acrobat Professional, so I need a free way to achieve this goal.
I know two software's that can reduce pdf file size for free.

First software - Free PDF Compressor

Below are the files of the program - the program has main dll files gsdll32.dll and gswin32c that make the compression

1629108901798.png


Below is the main window of the program

1629108975843.png




Second software - Compress PDF - Reduce pdf size easily - Free PDF Compressor

Below are the files of the program - the program has several dll files

1629109144834.png


Below is the main window of the program

1629109119224.png


The question is how can I use one to the above programs through VBA In order to reduce pdf file size and not through the graphical / user-friendly interface.

Any alternative free way to reduce pdf file size only through VBA plus a free software would be perfect as well
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
The 4dots compressor can be called from the command line:

In VBA use the Shell function or WScript.Shell object to run the command line string.
 
Upvote 0
The 4dots compressor can be called from the command line:

In VBA use the Shell function or WScript.Shell object to run the command line string.
Thanks

I created the macro below but nothing happened it seems i failed to run it from command

Public Sub CompressPdf_4dots()

Dim Wsh As Object 'WshShell

Set Wsh = CreateObject("WScript.Shell") 'New WshShell

Wsh.Run ("cmd /c 4dotsFreePDFCompress " & "C:\Temp\Example.pdf"""), 0, True

End Sub

Of course I put a pdf file named Example at C:\Temp
and it's the only file in the folder
 
Upvote 0
Looks like insufficient quotes. Please use VBA code tags -
VBA Code:
Wsh.Run "cmd /c 4dotsFreePDFCompress.exe " & """C:\Temp\Example.pdf""", 0, True
You might need the full path to the .exe if it isn't in the Path environment variable.
 
Upvote 0
Solution
Looks like insufficient quotes. Please use VBA code tags -
VBA Code:
Wsh.Run "cmd /c 4dotsFreePDFCompress.exe " & """C:\Temp\Example.pdf""", 0, True
You might need the full path to the .exe if it isn't in the Path environment variable.
Hey
I use the full path
Wsh.Run "cmd /c\PdfPrograms\4dotsFreePDFCompress.exe " & """C:\Temp""", 0, True

The code just load all the files located in C:\Temp....

1629139893143.png


I thought that the code can work "behind the scenes" like PDFtk server......In another words, I thought It could compress all the files without showing the graphical interface.
 
Upvote 0
Hey
I use the full path
Wsh.Run "cmd /c\PdfPrograms\4dotsFreePDFCompress.exe " & """C:\Temp""", 0, True

The code just load all the files located in C:\Temp....

View attachment 44974

I thought that the code can work "behind the scenes" like PDFtk server......In another words, I thought It could compress all the files without showing the graphical interface.
I changed the command as follows

Wsh.Run "cmd /c\PdfPrograms\4dotsFreePDFCompress.exe " & """C:\Temp""" & " " & ", 0, True

Now it doesn't load the program
 
Upvote 0
Looks like insufficient quotes. Please use VBA code tags -
VBA Code:
Wsh.Run "cmd /c 4dotsFreePDFCompress.exe " & """C:\Temp\Example.pdf""", 0, True
You might need the full path to the .exe if it isn't in the Path environment variable.
Hey,
As usual you are a Genius.
Since it is not in the enviroment i replaced the word cmd with the full path. Now it work's


Public Sub Compress_Pdf_4dots()
Dim s as String
Dim Wsh As Object 'WshShell
Set Wsh = CreateObject("WScript.Shell") 'New WshShell

s = "c:\PdfPrograms\4dotsFreePDFCompress.exe " & "C:\Temp" & " /overwrite"
Wsh.Run s, 0, True
End Sub

Could you explain what the 0 does?
What the True does?

I just copy the Wsh.Run s, 0, True in every macro without knowing what it actully does.

Anyway - it works perfect - compress all the files in C:\Temp folder and also overwrite the existing files.
 
Upvote 0
The VBA code works great, however 4dots pdf compressor sometimes destroy the pdf files, sometimes fill the page with black background.
I should search for alternative way to compress pdf through vba.

The code itself indeed works great.
The compressor/the application is bad. Even if the pdf size become smaller, the downside is that several pages in the pdf files have an error.
I should search for alternative command line solution
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top