Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Optimizing a PDF using automation with VB.

1,323 views
Skip to first unread message

Alastair Vance

unread,
Dec 1, 1999, 3:00:00 AM12/1/99
to
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

Aandi Inston

unread,
Dec 1, 1999, 3:00:00 AM12/1/99
to
"Alastair Vance" <ava...@cts-eur.com> wrote:

>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?

Optimizing a file requires doing a complete save as, so it is
optimistic to expect that SetFlags will work... in any case
PDDocIsOptimized is not a documented entry for SetFlags or GetFlags.

You need to do a save with the appropriate flags. In particular, you
need to use the PDSaveLinearized flag, also PDSaveFull and
PDSaveCollectGarbage.
---------------------------------------
Aandi Inston qu...@dial.pipex.com
Imposition and booklets for PDF - http://www.quite.com/imposing/

Roy Walter

unread,
Dec 1, 1999, 3:00:00 AM12/1/99
to
See iac.h in the SDK for the full story.

Alastair Vance <ava...@cts-eur.com> wrote in message
news:823l6e$ael$1...@nclient5-gui.server.ntli.net...


> 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?
>

Alastair Vance

unread,
Dec 2, 1999, 3:00:00 AM12/2/99
to
> Optimizing a file requires doing a complete save as, so it is
> optimistic to expect that SetFlags will work... in any case
> PDDocIsOptimized is not a documented entry for SetFlags or GetFlags.

I can't find a SaveAs in the object browser, but there is an entry for
PDDocIsOptimized.

There is a also SetInfo function which takes the form:

SetInfo(szInfoKey As String, szBuffer As String) As Boolean

Do you think I could set the optimize flag with this before saving the
document?

> You need to do a save with the appropriate flags. In particular, you
> need to use the PDSaveLinearized flag, also PDSaveFull and
> PDSaveCollectGarbage.

How would you use these in the one statement.
I tried saving with these other flags individually and it doesn't do
anything.
I'm using PDSaveFull at present.

Al.

Aandi Inston

unread,
Dec 2, 1999, 3:00:00 AM12/2/99
to
"Alastair Vance" <ava...@cts-eur.com> wrote:

>> Optimizing a file requires doing a complete save as, so it is
>> optimistic to expect that SetFlags will work... in any case
>> PDDocIsOptimized is not a documented entry for SetFlags or GetFlags.
>
>I can't find a SaveAs in the object browser, but there is an entry for
>PDDocIsOptimized.

You are trying to work from the object browser alone?? This sounds to
me like a form of masochism, and given the complexity of the object
model, very risky.

Please use the documentation. The Acrobat SDK is on
http://partners.adobe.com/. Anything not in the documentation should
not be used.

Alastair Vance

unread,
Dec 2, 1999, 3:00:00 AM12/2/99
to
>
> You are trying to work from the object browser alone?? This sounds to
> me like a form of masochism, and given the complexity of the object
> model, very risky.

"...complexity..."!! - I would say "shabbiness..." It's seems that OLE
support was an afterthought. Not very well thought out in my opinion.

>
> Please use the documentation. The Acrobat SDK is on
> http://partners.adobe.com/. Anything not in the documentation should
> not be used.

I have the acrobat 4 sdk - which is very sparse to say the least.
Do you work for Adobe by any chance? :-)

Al.

Aandi Inston

unread,
Dec 2, 1999, 3:00:00 AM12/2/99
to
"Alastair Vance" <ava...@cts-eur.com> wrote:

>>
>> You are trying to work from the object browser alone?? This sounds to
>> me like a form of masochism, and given the complexity of the object
>> model, very risky.
>
>"...complexity..."!! - I would say "shabbiness..." It's seems that OLE
>support was an afterthought. Not very well thought out in my opinion.

The object model is closely based on the one used in plug-ins, and in
Acrobat itself, and in that context is very well thought out. Perhaps
it doesn't translate well to OLE.


>
>>
>> Please use the documentation. The Acrobat SDK is on
>> http://partners.adobe.com/. Anything not in the documentation should
>> not be used.
>
>I have the acrobat 4 sdk - which is very sparse to say the least.

I wouldn't call 10,000 pages of documentation sparse. Are you looking
at the right documents?

IACREF.PDF completely documents all supported methods, including how
to combine flags for save. It doesn't mention the PDDocIsOptimized
flag, so I'd therefore recommend avoiding it.

>Do you work for Adobe by any chance? :-)

No.

Alastair Vance

unread,
Dec 2, 1999, 3:00:00 AM12/2/99
to
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


lorr...@gmail.com

unread,
May 19, 2016, 2:12:51 AM5/19/16
to
vb.net .pdf printing in thumbnail sizecan be download on rasteredge and create the best product for your product, try this vb.net .pdf printing in thumbnail size for free on

page rasteredge http://www.rasteredge.com/how-to/vb-net-imaging/pdf-compressing/
0 new messages