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
 
Hey friends,
compressing pdf files with ghostscript does a much better job.

VBA Code:
Public Sub Compress_Pdf_Ghostscript()

'options for quality:

'/screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
'/ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
'/printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
'/prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
'/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.

Dim FileCompress As String  

FileCompress = "C:\Temp\Article.pdf"

Dim wsh As Object 'WshShell
Set wsh = CreateObject("WScript.Shell")   'New WshShell
Dim  t1, t2, t3 As String
                           
t1 = "C:\PdfPrograms\ghost\gs9.54.0\bin\gswin32 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite"
t2 = " -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=C:\Temp\Article_Compressed.pdf" & " " & FileCompress
t3 = t1 & t2

'Debug.Print 3, t3
wsh.Run t3, 0, True

End sub
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,224,518
Messages
6,179,258
Members
452,901
Latest member
LisaGo

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