ryan.boud
April 4, 2007, 17:03:24
Hi
We have a template which is stored in our database and has a footer defined that contains serveral text fields. One of the textfields acts as a marker for where to insert an image into the footer.
Here is the code we use:
Dim TXDocument As New TXTextControl.ServerTextControl
Dim TXOut As New TXTextControl.ServerTextControl
Try
TXOut.Create()
TXDocument.Create()
Dim loadSettings As New TXTextControl.LoadSettings
'This stores the previously generated document
Dim OByte() As Byte = Nothing
'Used to get Address Objects from the database
Dim AHandler As New AddressHandler
'Loop through each address and create a new copy of the document
For Each int As Integer In arrayCorrespondenceAddressIDs
'Load the template from the object
TXDocument.Load(dt.Template, TXTextControl.BinaryStreamType.InternalFormat)
'#########
'Footer
'#########
'Activate the footer to insert the images and office data
TXDocument.HeadersAndFooters.GetItem(TXTextControl .HeaderFooterType.Footer).Activate()
For Each mergeField As TXTextControl.TextField In TXDocument.TextFields
If mergeField.Name = "UserImage" Then
mergeField.ScrollTo()
Dim X As New TXTextControl.Image
X.SaveMode = TXTextControl.ImageSaveMode.SaveAsData
X.ExportMaxResolution = 300
X.ExportCompressionQuality = 100
X.FileName = "D:\sites_dotnet\intranet\Site\Documents\office.jpg"
'Remove the text from the merge field
mergeField.Text = ""
TXDocument.Images.Add(X, TXDocument.InputPosition.TextPosition)
Else
'Not an image, get the value
mergeField.Text = GetFieldValue(obj, mergeField)
End If
Next
'Deactivate the footer
TXDocument.HeadersAndFooters.GetItem(TXTextControl .HeaderFooterType.Footer).Deactivate()
'#########
'MAIN
'#########
For Each mergeField As TXTextControl.TextField In TXDocument.TextFields
If mergeField.Name = "CorrespondenceAddress" Then
mergeField.Text = SetAddress(AHandler.GetAddress(int), mergeField)
Else
mergeField.Text = GetFieldValue(obj, mergeField)
End If
Next
'Check its not the last address to use, if not add a new page
If Not arrayCorrespondenceAddressIDs.IndexOf(int) = arrayCorrespondenceAddressIDs.Count - 1 Then
TXDocument.Select(TXDocument.Text.Length, 0)
TXDocument.Selection.Text = Convert.ToChar(12).ToString
TXDocument.Select(TXDocument.Text.Length, 0)
End If
'Save the merged document to the byte array
TXDocument.Save(OByte, TXTextControl.BinaryStreamType.InternalFormat)
'Add the byte array to the main document
TXOut.Selection.Load(OByte, TXTextControl.BinaryStreamType.InternalFormat)
Next
Dim savesettings As New TXTextControl.SaveSettings
Dim gu As Guid = Guid.NewGuid
'Save the file
TXOut.Save(System.Configuration.ConfigurationManag er.AppSettings("PATH_TO_LETTINGS_DOCS").ToString & gu.ToString & ".pdf", TXTextControl.StreamType.AdobePDF, savesettings)
Catch ex As Exception
Finally
TXDocument.Dispose()
TXOut.Dispose()
End Try
The PDF is generated and saved correctly but the footers are empty?
Are we doing something stupid?:confused:
Thanks
We have a template which is stored in our database and has a footer defined that contains serveral text fields. One of the textfields acts as a marker for where to insert an image into the footer.
Here is the code we use:
Dim TXDocument As New TXTextControl.ServerTextControl
Dim TXOut As New TXTextControl.ServerTextControl
Try
TXOut.Create()
TXDocument.Create()
Dim loadSettings As New TXTextControl.LoadSettings
'This stores the previously generated document
Dim OByte() As Byte = Nothing
'Used to get Address Objects from the database
Dim AHandler As New AddressHandler
'Loop through each address and create a new copy of the document
For Each int As Integer In arrayCorrespondenceAddressIDs
'Load the template from the object
TXDocument.Load(dt.Template, TXTextControl.BinaryStreamType.InternalFormat)
'#########
'Footer
'#########
'Activate the footer to insert the images and office data
TXDocument.HeadersAndFooters.GetItem(TXTextControl .HeaderFooterType.Footer).Activate()
For Each mergeField As TXTextControl.TextField In TXDocument.TextFields
If mergeField.Name = "UserImage" Then
mergeField.ScrollTo()
Dim X As New TXTextControl.Image
X.SaveMode = TXTextControl.ImageSaveMode.SaveAsData
X.ExportMaxResolution = 300
X.ExportCompressionQuality = 100
X.FileName = "D:\sites_dotnet\intranet\Site\Documents\office.jpg"
'Remove the text from the merge field
mergeField.Text = ""
TXDocument.Images.Add(X, TXDocument.InputPosition.TextPosition)
Else
'Not an image, get the value
mergeField.Text = GetFieldValue(obj, mergeField)
End If
Next
'Deactivate the footer
TXDocument.HeadersAndFooters.GetItem(TXTextControl .HeaderFooterType.Footer).Deactivate()
'#########
'MAIN
'#########
For Each mergeField As TXTextControl.TextField In TXDocument.TextFields
If mergeField.Name = "CorrespondenceAddress" Then
mergeField.Text = SetAddress(AHandler.GetAddress(int), mergeField)
Else
mergeField.Text = GetFieldValue(obj, mergeField)
End If
Next
'Check its not the last address to use, if not add a new page
If Not arrayCorrespondenceAddressIDs.IndexOf(int) = arrayCorrespondenceAddressIDs.Count - 1 Then
TXDocument.Select(TXDocument.Text.Length, 0)
TXDocument.Selection.Text = Convert.ToChar(12).ToString
TXDocument.Select(TXDocument.Text.Length, 0)
End If
'Save the merged document to the byte array
TXDocument.Save(OByte, TXTextControl.BinaryStreamType.InternalFormat)
'Add the byte array to the main document
TXOut.Selection.Load(OByte, TXTextControl.BinaryStreamType.InternalFormat)
Next
Dim savesettings As New TXTextControl.SaveSettings
Dim gu As Guid = Guid.NewGuid
'Save the file
TXOut.Save(System.Configuration.ConfigurationManag er.AppSettings("PATH_TO_LETTINGS_DOCS").ToString & gu.ToString & ".pdf", TXTextControl.StreamType.AdobePDF, savesettings)
Catch ex As Exception
Finally
TXDocument.Dispose()
TXOut.Dispose()
End Try
The PDF is generated and saved correctly but the footers are empty?
Are we doing something stupid?:confused:
Thanks