Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

VB
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 2:35am
v2
Comments
[no name] 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

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900