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

Use vbScript to combine several TIF files into a single PDF

750 views
Skip to first unread message

Harvey Colwell

unread,
Feb 21, 2005, 12:48:37 PM2/21/05
to
I've downloaded the SDK and have read numerous post on creating PDF through
automation. I have no problem getting acrobat [exchange] to open the first
TIFF file, but I can't save it nor can I find a way to get acrobat append
any additional files that are opened.

I'm using Acrtobat ver 5, but I the final script will run against ver 6.

Any examples will be appreciated.

TIA


Aandi Inston

unread,
Feb 21, 2005, 1:50:17 PM2/21/05
to
"Harvey Colwell" <har...@sds400.com> wrote:

>I've downloaded the SDK and have read numerous post on creating PDF through
>automation. I have no problem getting acrobat [exchange] to open the first
>TIFF file

Which is strange, if you think about it, because there isn't a method
in the Acrobat 5 SDK for opening a TIFF file. I suspect you are using
AVDoc.Open which in some versions seems to do this.

Perhaps you could make separate PDF files in this way and combine them
with PDDoc.InsertPages. Don't expect this to be a robust solution,
indeed I'm not really hopeful it will work in 6.0.
----------------------------------------
Aandi Inston qu...@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

Harvey Colwell

unread,
Feb 21, 2005, 5:16:27 PM2/21/05
to
Yes I'm using AVDoc.Open. I just mentioned that I have the SDK available if
anyone wanted to point me to something it contains.

I'll try the PDDoc.InsertPages.


"Aandi Inston" <qu...@dial.pipex.con> wrote in message
news:421a2d11....@read.news.uk.uu.net...

Aandi Inston

unread,
Feb 22, 2005, 2:45:18 AM2/22/05
to
"Harvey Colwell" <har...@sds400.com> wrote:

>Yes I'm using AVDoc.Open. I just mentioned that I have the SDK available if
>anyone wanted to point me to something it contains.

There is nothing in the SDK to convert TIFF to PDF in Acrobat 5. No
supported method - except printing a TIFF file to a PDF driver.

Reinhard Franke

unread,
Feb 22, 2005, 2:55:19 AM2/22/05
to
Have a look at this discussion:

http://www.adobeforums.com/cgi-bin/webx?1...@194.Dh8cd7jySAr.4293533@.3bb81397/15

and you will find all vbs examples you need.

MfG. Reinhard Franke

Ross A. Finlayson

unread,
Feb 22, 2005, 3:10:39 AM2/22/05
to

Hi Harvey,

I recommend the ImagePDF COM component for that purpose. I'm biased as
I wrote it myself and sell it for money.

http://www.apexintsoft.com/imagepdf_features.htm

Also there is the convenient TIFFProp shell extension for viewing the
tags of TIFF documents. Consider
http://www.tiki-lounge.com/~raf/tiff/fields.html .

Regards,

Ross Finlayson

--
"Also, consider this: the unit impulse function times
one less twice the unit step function times plus/minus
one is the mother of all wavelets."

Ralf Koenig

unread,
Feb 22, 2005, 3:41:23 AM2/22/05
to
Harvey Colwell schrieb:

In case, a stand-alone application also serves your needs (you can typically
call external command-line tools), here is a *free* TIFF->PDF converter.

Open source variant with tiff2pdf:
http://www.libtiff.org/

See man-page for details:
http://www.libtiff.org/man/tiff2pdf.1.html

Once you converted the single TIFF files to single PDF's, you can use a tool
such as *free* pdftk to combine them into a single PDF.

http://www.accesspdf.com/pdftk/

Before using that in your software projects, have a look at the licenses.

Ralf

Harvey Colwell

unread,
Feb 22, 2005, 11:07:35 AM2/22/05
to
Thanks, these utilities look quite promising.

I'm going to continue my current vbScript project for now, but I will
definitely come back to these, wrap a vbScript envelope around them and see
how they stack up performance wise. I have a passon for using freeware and
automating command line solutions.


"Ralf Koenig" <ralf....@informatik.tu-chemnitz.de> wrote in message
news:cver7m$efd$1...@anderson.hrz.tu-chemnitz.de...

Harvey Colwell

unread,
Feb 22, 2005, 11:07:50 AM2/22/05
to
Below is what I've done so far. The script is still very much in flux.
Especially in the UI area. I have subs/functions that are not being used
yet.

But here's what I got so far. Under the "Main" section. I pieced together a
couple of differnt samples into a loop, processing each file in the source
folder (sDataFdr). If it processing the first file opened (bFirstFile), I
save the automatically created PDF. For all subsequent files, I insert the
automatically created PDF into the first then and resave it. This much is
working for uo to two files.


I get a "Subsequent TIFF file failed to Open!" when processing the 3rd file.

My immediate problem, as I see it, is Line 79: oPDDoc2.Close

The second automatically created PDF file isn't closing, therefore, the
oAVDoc2 and oPDDoc2 variables can't be reused.


[--- Begin: CreatePDF3.vbs ---]

001. ' Windows Script Host - VBScript
002.
' --------------------------------------------------------------------------------
003. ' Name: Convert TIFF to PDF
004. ' By: Harvey Colwell
005. ' CopyRight: (c) Feb 2005, All Rights Reserved!
006. '
007. '
********************************************************************************
008. Option Explicit
009.
010. Dim oWS, oWN, oFS, oRE
011.
012. Set oWS = WScript.CreateObject("WScript.Shell")
013. Set oWN = WScript.CreateObject("WScript.Network")
014. Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
015. Set oRE = new RegExp
016.
017. Dim bDebugMode : bDebugMode = True
018.
019. Const sTitle = "Convert TIFF to PDF"
020.
021. '----------
022. ' Script SetUp
023. '----------
024. Dim sScript, sPath, sOutFile
025. Dim sDataFdr, oDataFdr, oDataFile
026. Dim aFileList
027.
028. sScript = GetShortPath(WScript.ScriptFullName)
029. sPath = Left(sScript, InStrRev(sScript, "\"))
030.
031. sOutFile = sPath & "Scan_Archive.PDF"
032. DelIfExists sOutFile
033.
034. sDataFdr = "C:\Temp\Images\"
035.
036.
037. '---------------
038. ' Main
039. '---------------
040. Dim oAApp, oAVDoc1, oAVDoc2, oPDDoc1, oPDDoc2, bSuccess
041.
042. Set oDataFdr = oFS.GetFolder(sDataFdr)
043.
044. If (oDataFdr.Files.Count > 0) Then
045. Set oAApp = CreateObject("AcroExch.App")
046. Set oAVDoc1 = CreateObject("AcroExch.AVDoc")
047. Set oAVDoc2 = CreateObject("AcroExch.AVDoc")
048. Set oPDDoc1 = CreateObject("AcroExch.PDDoc")
049. Set oPDDoc2 = CreateObject("AcroExch.PDDoc")
050.
051. oAApp.Show
052.
053. Dim bFirstFile : bFirstFile = True
054.
055.
056. For Each oDataFile In oDataFdr.Files
057. If bFirstFile Then
058. bFirstFile = False
059. If oAVDoc1.Open(oDataFile.Path, "") Then
060. Set oAVDoc1 = oAApp.GetActiveDoc
061. If oAVDoc1.IsValid Then
062. Set oPDDoc1 = oAVDoc1.GetPDDoc
063. bSuccess = oPDDoc1.SetFlags(&H800)
064. If oPDDoc1.Save(1, sOutFIle) <> True Then call
Cleanup("First PDF file failed to Save!")
065. Else
066. Call CleanUp("First Active PDF is not Valid")
067. End IF
068. Else
069. Call CleanUp("First TIFF file failed to Open!")
070. End If
071. Else
072. If oAVDoc2.Open(oDataFile.Path, "") Then
073. Set oAVDoc2 = oAApp.GetActiveDoc
074. If oAVDoc2.IsValid Then
075. Set oPDDoc2 = oAVDoc2.GetPDDoc
076. bSuccess = oPDDoc2.SetFlags(&H800)
077. oPDDoc1.InsertPages "0", oPDDoc2, "0", "1", "0"
078. If oPDDoc1.Save(1, sOutFIle) <> True Then call
Cleanup("Subsequent PDF file failed to Save!")
079. oPDDoc2.Close
080. MsgBox "Finished processing file: " & oDataFile.Name
081. Else
082. Call CleanUp("Subsequent Active PDF is not Valid")
083. End If
084. Else
085. Call CleanUp("Subsequent TIFF file failed to Open!")
086. End If
087. End IF
088. Next
089.
090. End If
091.
092. Set oDataFdr = Nothing
093.
094.
095. ' oAApp.CloseAllDocs
096. ' oAApp.Exit
097.
098. ' oInPDDoc = Nothing
099. ' oPDDoc = Nothing
100. ' oAVDoc = Nothing
101. ' oAApp = Nothing
102.
103.
104. '---------------------
105. Sub CleanUp(sExitMsg)
106.
107. If sExitMsg <> "" Then MsgBox sExitMsg, vbExclamation, sTitle
108.
109. Set oRE = Nothing
110. Set oWS = Nothing
111. Set oWN = Nothing
112. Set oFS = Nothing
113. WScript.Quit
114. End Sub
115.
116. '---------------------
117. Sub DelIfExists(sFile)
118. If oFS.FileExists(sFile) Then oFS.DeleteFile(sFile)
119. End Sub
120.
121. '---------------------
122. Function GetShortPath(pName)
123. GetShortPath = oFS.GetFile(pName).ShortPath
124. End Function
125.
126. '---------------------
127. Function GetFileList(sFdr)
128. Dim oFile
129. oRE.IgnoreCase = True
130. oRE.Pattern = "TIF"
131. For Each oFile In oFS.GetFolder(sFdr).Files
132. If oRE.Test(oFile.Ext) Then GetFileList = GetFileList &
oFile.Name & vbTab
133. Next
134. End Function
135.
136.

[--- End: CreatePDF3.vbs ---]

Ross A. Finlayson

unread,
Feb 22, 2005, 7:41:26 PM2/22/05
to
Hi Harvey,

I hope you don't mind if I promote my software product, but I was
interested to see what the code would be using the ImagePDF COM
component, see http://www.apexintsoft.com/imagepdf_features.htm , which
is designed for batch processing of the file conversion of TIFF and
other image files to PDF.


037. '---------------
038. ' Main
039. '---------------

040. Dim oImagePDF, nResult


041.
042. Set oDataFdr = oFS.GetFolder(sDataFdr)
043.
044. If (oDataFdr.Files.Count > 0) Then

045. Set oImagePDF = CreateObject("ImagePDF.Main")

056. For Each oDataFile In oDataFdr.Files

nResult = oImagePDF.AddImage(oDataFile.Path)

If (nResult < 0) Then MsgBox "Error" vbExclamation, sTitle

088. Next
089.

nResult = oImagePDF.WritePDF(sOutFile)

If (nResult < 0) Then MsgBox "Error" vbExclamation, sTitle

090. End If
091.
092. Set oDataFdr = Nothing
093.

101. oImagePDF = Nothing
102.


I wrote that libtiff tiff2pdf program, it's a good little program,
160192 bytes in length, and carefully scrutinized by the zillions of
compilers that make libtiff every year, but it doesn't offer
thumbnails, linearization, encryption, bookmarks and annotations,
etcetera, although it does effectively use the compressed data as
appropriate without recompressing the data, nor does it contribute to
my coffer, although I'm happy to modify it for you on spec. I don't
know if it's my place to discuss their competitive products, but
fastio.com and davince.com are each websites representing Fast I/O and
Da Vince Software's respective programs named tiff2pdf that predate
libtiff tiff2pdf, with perhaps A. Accomazzi's and EPFL's tiff2pdf
predating them, each being robust and efficient programs with a wide
user base. Long ago, an example program in T. Merz' PDFLib,
pdflib.com, was called imagepdf.c, before I heard of it, then it was
changed to pdfimage.c, and today some outfit calling itself "Klonsoft"
markets their product "ImagePDF Creator". There are many, many
programs to convert TIFF to PDF, because billions of pages have been
scanned into TIFF files and many users understand PDF means PDF.
Indeed, if you search for "TIFF PDF" there are ready results of dozens
or scores of programs for the express task of wrapping TIFF image files
into being PDF files, without the professional high-end Optical
Character Recognition, OCR. Of those, ImagePDF offers a rich
compliment of features, at not the costliest price, but it only
generates files compatible with PDF <= 1.2. It's not perfect, just
good. Please report ImagePDF errors to software at apexintsoft.com.

Regards,

Ross Finlayson

Reinhard Franke

unread,
Feb 23, 2005, 6:45:54 AM2/23/05
to
I got already problems with the first file. "("First Active PDF is not
Valid")" although if it is saved correctly (AA5/W2K).

>My immediate problem, as I see it, is Line 79: oPDDoc2.Close

In the script I stated to you I tried this also without luck, so I
took app.CloseAllDocs, which works. Regarding this and also what Aandi
said (undocumented / unsupported) I would simplify the script:

1. Function: Read (/sort) all files into an array.
2. Function: Change the files from TIFF -> PDF
3. Function: Merge all PDF-Files

That script is easy to debug and to maintain and increases your VBS
library.

HTH, Reinhard

Harvey Colwell

unread,
Feb 23, 2005, 11:25:17 AM2/23/05
to
I took a look at your software and one thing that jumped out at me was CALs
support.

I created a document imaging solution for a customer that now has just under
500,000 documents in their archive. I choose CALs since it was the most
efficient file format for B&W scanned images. I don't know why more software
products don't support CALs when they support other FAX and scanner formats.

For this project, I was planning on first converting the CAL images to TIFF.
I didn't even want to mention CALs to the newsgroup because of its zero
name-recognition issues. Anyway I've downloaded your COM object and will try
it out soon.

Another post pointed out the libtiff tiff2pdf program., which I plan to take
a look at as well.

-----

From a personal standpoint, I still want to better understand Acrobat's
automation interface. I don't care about how easy or hard it is to use. I
write hundreds of scripts a year (I'm not exaggerating!) and I'm sure that
after I've mastered it, I will be able to us the knowledge again and again.


"Ross A. Finlayson" <r...@tiki-lounge.com> wrote in message
news:1109119286....@c13g2000cwb.googlegroups.com...

0 new messages