Optimizing a PDF using automation with VB. 
Author Message
 Optimizing a PDF using automation with VB.

Hi Everyone,

Have a look at the following code.  It opens a TIF/PDF/etc. and saves it out
as a PDF.
I want to "optimize" the PDF (the check box on acrobat's save as dialog) so
it can be "byteserved" from a web server.

I have been experimenting with the SetFlags() function - one of the
PDDocFlags is PDDocIsOptimized, but that doesn't seem to work.  Does anyone
have any ideas?

Thanks,

Alastair.

____________________________________

Private Sub Tif2PDF(FileName As String)
Dim AcroApp As CAcroApp
Dim AVDoc As CAcroAVDoc
Dim PDDoc As CAcroPDDoc
Dim IsSuccess As Boolean

    Set AcroApp = CreateObject("AcroExch.App")
    Set AVDoc = CreateObject("AcroExch.AVDoc")

    'AcroApp.Show

    Call AVDoc.Open(FileName, "")

    Set AVDoc = AcroApp.GetActiveDoc

    If AVDoc.IsValid Then

        Set PDDoc = AVDoc.GetPDDoc

        ' This is the line that doesn't do Anything...
        ' It returns true - but the document isn't optimized.
        IsSuccess = PDDoc.SetFlags(2048)

        If PDDoc.Save(1, App.Path & "\pdf\docfile.pdf") <> True Then
            MsgBox "Failed to save " & FileName
        End If

    End If

    'Close the PDF
    AVDoc.Close True
    AcroApp.Exit

    'Cleanup
    Set PDDoc = Nothing
    Set AVDoc = Nothing
    Set AcroApp = Nothing

End Sub



Sun, 19 May 2002 03:00:00 GMT  
 Optimizing a PDF using automation with VB.
See iac.h in the SDK for the full story.


Quote:
> Hi Everyone,

> Have a look at the following code.  It opens a TIF/PDF/etc. and saves it
out
> as a PDF.
> I want to "optimize" the PDF (the check box on acrobat's save as dialog)
so
> it can be "byteserved" from a web server.

> I have been experimenting with the SetFlags() function - one of the
> PDDocFlags is PDDocIsOptimized, but that doesn't seem to work.  Does
anyone
> have any ideas?

> Thanks,

> Alastair.

> ____________________________________

> Private Sub Tif2PDF(FileName As String)
> Dim AcroApp As CAcroApp
> Dim AVDoc As CAcroAVDoc
> Dim PDDoc As CAcroPDDoc
> Dim IsSuccess As Boolean

>     Set AcroApp = CreateObject("AcroExch.App")
>     Set AVDoc = CreateObject("AcroExch.AVDoc")

>     'AcroApp.Show

>     Call AVDoc.Open(FileName, "")

>     Set AVDoc = AcroApp.GetActiveDoc

>     If AVDoc.IsValid Then

>         Set PDDoc = AVDoc.GetPDDoc

>         ' This is the line that doesn't do Anything...
>         ' It returns true - but the document isn't optimized.
>         IsSuccess = PDDoc.SetFlags(2048)

>         If PDDoc.Save(1, App.Path & "\pdf\docfile.pdf") <> True Then
>             MsgBox "Failed to save " & FileName
>         End If

>     End If

>     'Close the PDF
>     AVDoc.Close True
>     AcroApp.Exit

>     'Cleanup
>     Set PDDoc = Nothing
>     Set AVDoc = Nothing
>     Set AcroApp = Nothing

> End Sub



Sun, 19 May 2002 03:00:00 GMT  
 Optimizing a PDF using automation with VB.
Ok, I've sorted it out.

Thanks to Aandi Inston, who "provoked" me to look at the documentation just
a bit harder!  I overlooked the fact you could combine several of the
settings while using the save function.

By combining Linearize and SaveFull, you get an optimized document.
I also add in EmptyGarbage - not sure it has much effect.

See code below:
______________________________________________________

Private Sub Tif2PDF(FileName As String)
Dim AcroApp As CAcroApp
Dim AVDoc As CAcroAVDoc
Dim PDDoc As CAcroPDDoc
Dim IsSuccess As Boolean

    Set AcroApp = CreateObject("AcroExch.App")
    Set AVDoc = CreateObject("AcroExch.AVDoc")

    Call AVDoc.Open(FileName, "")

    Set AVDoc = AcroApp.GetActiveDoc

    If AVDoc.IsValid Then

        Set PDDoc = AVDoc.GetPDDoc

        If PDDoc.Save(1 Or 4 Or 32, App.Path & "\docfile.pdf") <> True Then
            MsgBox "Failed to Save " & FileName
        End If

        PDDoc.Close

    End If

    'Close the PDF
    AVDoc.Close True
    AcroApp.Exit

    'Cleanup
    Set PDDoc = Nothing
    Set AVDoc = Nothing
    Set AcroApp = Nothing

End Sub


Quote:
> Hi Everyone,

> Have a look at the following code.  It opens a TIF/PDF/etc. and saves it
out
> as a PDF.
> I want to "optimize" the PDF (the check box on acrobat's save as dialog)
so
> it can be "byteserved" from a web server.

> I have been experimenting with the SetFlags() function - one of the
> PDDocFlags is PDDocIsOptimized, but that doesn't seem to work.  Does
anyone
> have any ideas?

> Thanks,

> Alastair.



Mon, 20 May 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Converting Word Revision Marks to PDF Annotations Using PDF Marks

2. optimizing performance and data transfer vb->excel and vb->vb

3. optimizing performance and data transfer vb->excel and vb->vb

4. Adding a footnote in to a PDF document using VB (repost)

5. Adding a footnote in to a PDF document using VB

6. HOw to convert text FILE IN TO PDF FILE through VB CODE USING adobe type library

7. using Acrobat Control in VB for saving as PDF file

8. Opening a .pdf file using Acrobat Reader from VB

9. Access97 in Win2k PDF Automation

10. Automation with pdf file and VB5

11. Automation Error during Remote Procedure Call (RPC) using DCOM and Automation Manager

12. optimize data access using ADO

 

 
Powered by phpBB® Forum Software