Click here to Skip to main content
14,362,554 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am importing jpg photo(s) and insert into new pdf file(s).
I am trying to save pdf files as pdf reduced size (found in acrobat pro XI menu) using VBA code.
can anyone help, please ?!

What I have tried:

Sub Tif2PDF(FileName As String, PdfNAme As String)
Dim AcroApp   As CAcroApp
Dim AVDoc     As CAcroAVDoc
Dim PDDoc     As CAcroPDDoc
Dim PdfSrc    As CAcroPDDoc
Dim PdfDst    As CAcroPDDoc
Dim jso       As Object
Dim IsSuccess As Boolean

Set AcroApp = CreateObject("AcroExch.App")
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set PdfSrc = CreateObject("AcroExch.PDDoc")
Set PdfDst = CreateObject("AcroExch.PDDoc")

'open jpg
Call AVDoc.Open(FileName, "")
Set AVDoc = AcroApp.GetActiveDoc
If AVDoc.IsValid Then
     

   If CounterPDF = 1 Then
       Set PdfDst = AVDoc.GetPDDoc
     '  PdfDst.Save PdfNAme
       If PdfDst.Save(1 Or 4 Or 32, PdfNAme) <> True Then
          MsgBox "Failed to save " & FileName
       End If
       
       PdfDst.Close
      
    Else
        If PdfDst.InsertPages(PdfDst.GetNumPages() - 1, PdfSrc, 0, PdfSrc.GetNumPages(), True) Then
        Set jso = PdfDst.GetJSObject
       'Save document
        If PdfDst.Save(1, PdfNAme) <> True Then
            MsgBox "Failed to save " & FileName
        End If
   End If
'Clean up
Set jso = Nothing
        PdfDst.Close
     End If
End If

'Close the PDF
AVDoc.Close True
AcroApp.Exit
        
'Cleanup
Set PdfDst = Nothing
Set PdfSrc = Nothing
Set AVDoc = Nothing
Set AcroApp = Nothing

End Sub
Posted
Updated 10-Oct-19 3:35am
v2
Comments
0x01AA 10-Oct-19 6:45am
   
And what does not work?
Any error message?
Any hint which part in the source does not behave as you expect?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

If you don't mind doing this via internet you could use this online API:
PDF to COMPRESS API. The API for compressing PDF files - Convert API[^]
They don't have a VBA library, but maybe you can use a WebRequest and JSON.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100