Hi Alexey,
Thanks for the info on Aspose.Words.Rendering. I will read up on it and modify my application accordingly.
In the meantime, we have tried producing a document using Aspose.Words 6.0.0 and were unsuccessful in converting it to a PDF using the distiller in Adobe Acrobat Professional 8.
I have attached the document so you can examine it and perhaps try converting it and see if you get the same error.
The attached document was produced with the following code. I have highlighted two function calls by increasing their font, InsertDocumentAtBookmark() and AppendDoc() that you sent me in an earlier post. I have included them below. Perhaps they do some sort of formatting that the distiller doesn't recognize?
Dim doc As Document = New Document(word_templates_path & strTemplate)
Dim docBuilder As New DocumentBuilder(doc)
Dim subDoc As Document
Dim subDocName As String
Dim bookmarks As BookmarkCollection = doc.Range.Bookmarks
Dim strBookmarkName As String = ""
Dim strBookmarkType As String = ""
Dim strBookmarkStyle As String = ""
For i = 0 To dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows.Count - 1
Try
strBookmarkName = dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_name").ToString()
strBookmarkType = dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_type").ToString()
strBookmarkStyle = dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_style").ToString()
If strBookmarkType = "IN" Then ' Insert the file specified by bookmark_text at this bookmark
If strBookmarkStyle = "Bold" Then
docBuilder.Font.Bold = True
End If
subDocName = Trim(strSubstitutionDocumentPath) & Trim(dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_text").ToString)
subDoc = New Document(subDocName)
InsertDocumentAtBookmark(strBookmarkName, doc, subDoc)
Else ' Normal bookmark so just write the bookmark value at the bookmark
If Not bookmarks(strBookmarkName) Is Nothing Then
docBuilder.MoveToBookmark(strBookmarkName, True, True)
If dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_text") <> "" Then
If strBookmarkStyle = "Bold" Then
docBuilder.Font.Bold = True
End If
docBuilder.Write(dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_text"))
Else
If strBookmarkName Like ("*Address*") And bookmarks(strBookmarkName).Text = "" Then
' Remove blank address lines
docBuilder.MoveToBookmark(strBookmarkName)
Dim Node As Node = doc.Range.Bookmarks(strBookmarkName).BookmarkStart
Node.Remove()
docBuilder.CurrentParagraph.Remove()
End If
End If
End If
End If
Catch ex As Exception
lblError.Text = lblError.Text & " ? " & strBookmarkName & ", " & strBookmarkType & ", " & "Subdocname = " & subDocName & " " & ex.Message
Return
Finally
End Try
Next i
If j > 0 Then
doc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage
End If
AppendDoc(docMaster, doc)
Next j
docMaster.FirstSection.Remove()
--------------------------------------------------------------------------------------------------------------------------------------
Sub InsertDocumentAtBookmark(ByVal bookmarkName As String, ByVal dstDoc As Document, ByVal srcDoc As Document)
'Create DocumentBuilder
Dim builder As DocumentBuilder = New DocumentBuilder(dstDoc)
'Move cursor to bookmark and insert paragraph break
builder.MoveToBookmark(bookmarkName)
builder.Writeln()
'Content of srcdoc will be inserted after this node
Dim insertAfterNode As Node = builder.CurrentParagraph.PreviousSibling
'Content of first paragraph of srcDoc will be apended to this parafraph
Dim insertAfterParagraph As Paragraph = CType(insertAfterNode, Paragraph)
'Content of last paragraph of srcDoc will be apended to this parafraph
Dim insertBeforeParagraph As Paragraph = builder.CurrentParagraph
'We will be inserting into the parent of the destination paragraph.
Dim dstStory As CompositeNode = insertAfterNode.ParentNode
'Remove empty paragraphs from the end of document
While (Not srcDoc.LastSection.Body.LastParagraph.HasChildNodes)
srcDoc.LastSection.Body.LastParagraph.Remove()
End While
'Loop through all sections in the source document.
Dim srcSection As Section
For Each srcSection In srcDoc.Sections
'Loop through all block level nodes (paragraphs and tables) in the body of the section.
Dim srcNode As Node
For Each srcNode In srcSection.Body
'Do not insert node if it is a last empty paragarph in the section.
Dim para As Paragraph = CType(srcNode, Paragraph)
If (Not para Is Nothing) AndAlso para.IsEndOfSection AndAlso (Not para.HasChildNodes) Then
Exit For
End If
'If current paragraph is first paragraph of srcDoc
'then appent its content to insertAfterParagraph
If (para.Equals(srcDoc.FirstSection.Body.FirstParagraph)) Then
Dim node As Node
For Each node In para.ChildNodes
Dim dstNode As Node = dstDoc.ImportNode(node, True, ImportFormatMode.KeepSourceFormatting)
insertAfterParagraph.AppendChild(dstNode)
Next
'If subdocument contains only one paragraph
'then copy content of insertBeforeParagraph to insertAfterParagraph
'and remove insertBeforeParagraph
If (srcDoc.FirstSection.Body.FirstParagraph.Equals(srcDoc.LastSection.Body.LastParagraph)) Then
While (insertBeforeParagraph.HasChildNodes)
insertAfterParagraph.AppendChild(insertBeforeParagraph.FirstChild)
End While
insertBeforeParagraph.Remove()
End If
'If current paragraph is last paragraph of srcDoc
'then appent its content to insertBeforeParagraph
ElseIf (para.Equals(srcDoc.LastSection.Body.LastParagraph)) Then
Dim previouseNode As Node
Dim node As Node
For Each node In para.ChildNodes
Dim dstNode As Node = dstDoc.ImportNode(node, True, ImportFormatMode.KeepSourceFormatting)
If (previouseNode Is Nothing) Then
insertBeforeParagraph.InsertBefore(dstNode, insertBeforeParagraph.FirstChild)
Else
insertBeforeParagraph.InsertAfter(dstNode, previouseNode)
End If
previouseNode = dstNode
Next
Else
'This creates a clone of the node, suitable for insertion into the destination document.
Dim newNode As Node = dstDoc.ImportNode(srcNode, True, ImportFormatMode.KeepSourceFormatting)
'Insert new node after the reference node.
dstStory.InsertAfter(newNode, insertAfterNode)
insertAfterNode = newNode
End If
Next
Next
End Sub
-------------------------------------------------------------------------------------------------------------------------------------
Public Sub AppendDoc(ByVal dstDoc As Document, ByVal srcDoc As Document)
' Loop through all sections in the source document.
For Each srcSection As Section In srcDoc
' Importing a node creates a copy of the original node
Dim dstSection As Node = dstDoc.ImportNode(srcSection, True, ImportFormatMode.KeepSourceFormatting)
' Now the new section node can be appended to the destination document.
dstDoc.AppendChild(dstSection)
Next srcSection
End Sub
Thanks again for all your help.
C.