mattb$2007080
mattb

03/22/2007 :: 21:38

Registered

My business case is to open a multi-page TIFF file, add some specified text *to each page*, resave the final multi-page TIFF to a new file (that will be printed later).

I am having some difficulty with the methods to use... My attempts have largely looked like this (generates errors when tyring to add pages to the TIFF although I can get a first or last page saved).

Dim GdPicture As GdpicturePro.cGdPicture
GdPicture = New GdpicturePro.cGdPicture
GdPicture.SetLicenceNumber("0012345678910111213141516")

Dim i As Integer

With GdPicture

.CreateImageFromFile("c:\t14024.tif")
Dim c As Integer = GdPicture.TiffGetPageCount()

For i = 1 To c

.TiffSelectPage(i)
.ConvertTo16Bpp()
.DrawText("TEST ADDING A TEXT LINE", 100, 100, 20, 1)
If i = 1 Then
.TiffSaveAsNativeMultiPage("C:\TESTGDTIF.TIF")
Else : .TiffAddToNativeMultipage(i)
End If

i = i + 1

Next

.TiffCloseNativeMultiPage()
GdPicture = Nothing


End With



Best method I can think of would be to load the image page in memory, add the text, *rinse/repeat*, then create the final file.

Thank you for your assistance.
Loïc$2006306
Loïc

03/23/2007 » 15:26

Registered

Good morning.

I give you a sample. I you have a question i am here !




Dim oGdPicture As New GdpicturePro.cGdPicture
Dim sOpenFilePath As String
Dim sWriteFilePath As String
Dim nCpt As Long
Dim tbFramesString() As String
Dim nPagesCount As Long
Dim nInputMultipageHandle As Long
Dim nNewMultiPageHandle As Long
Dim nTmpImageHandle As Long


sOpenFilePath = "d:\multipage.tif"
sWriteFilePath = "d:\newmultipage.tif"

nInputMultipageHandle = oGdPicture.CreateImageFromFile(sOpenFilePath)
If nInputMultipageHandle <> 0 Then
'First: extraction of each pages
nPagesCount = oGdPicture.TiffGetPageCount
ReDim tbFramesString(1 To nPagesCount)
For nCpt = 1 To nPagesCount
oGdPicture.TiffSelectPage (nCpt)
tbFramesString(nCpt) = oGdPicture.SaveAsString("TIF", 2)
Next nCpt
oGdPicture.CloseImage (nInputMultipageHandle)

'Second: draw text on each pages and recompose new multipage tif file
For nCpt = 1 To nPagesCount
oGdPicture.CreateImageFromString (tbFramesString(nCpt))
Call oGdPicture.ConvertTo24Bpp
nTmpImageHandle = oGdPicture.GetNativeImage()
Call oGdPicture.DrawText("Page " & Str(nCpt) & " / " & Str(nPagesCount), 1, 1, 12, 0, oGdPicture.ARGB(255, 255, 0, 0), "Arial", True)
If nCpt = 1 Then
Call oGdPicture.TiffSaveAsNativeMultiPage(sWriteFilePath, 2)
Else
oGdPicture.TiffAddToNativeMultipage (nTmpImageHandle)
oGdPicture.CloseImage (nTmpImageHandle)
End If
Next nCpt
oGdPicture.TiffCloseNativeMultiPage
MsgBox "Done!"
Else
MsgBox "Can't open " & sOpenFilePath
End If

Set oGdPicture = Nothing



Best regards,

Loïc Carrère

Edited by @lcarrere  
mattb$2007080
mattb

03/23/2007 :: 21:13

Registered

Thank you!
back to forum