Hi,
i know how to word document save as image,
but not the same picture content with the word document.
Can you help me to see which part of the wrong?
I have attached five sample files as
I hope the final out of the picture as File attachment:Ok.Png
File attachment:Step1.doc
I use code like as
Dim strItems As Integer = 4
Dim Doc As New Aspose.Words.Document(SourceFileName)
Dim Builder As New Aspose.Words.DocumentBuilder(doc)
Dim OkDoc As New Aspose.Words.Document
Dim OkBuilder As New Aspose.Words.DocumentBuilder
OkDoc.ViewOptions.ViewType = Settings.ViewType.PageLayout
OkDoc.Save(OkFileName)
OkDoc = New Aspose.Words.Document(OkFileName)
OkBuilder = New Aspose.Words.DocumentBuilder(OkDoc)
For i As Integer = 0 To strItems - 1
Builder.MoveToSection(i * 2 + 1)
Builder.MoveToParagraph(0, 0)
sFont = Builder.Font
sFont.ClearFormatting()
sFont.Name = "Times New Roman"
sFont.Italic = False
Builder.Write(" (" & Chr(65 + i) & ")")
sFont.ClearFormatting()
Next
doc.ViewOptions.ViewType = Settings.ViewType.PageLayout
doc.Save(SourceFileName)
File attachment: Step2.doc
I use code Like as
doc = New Aspose.Words.Document(SourceFileName)
Builder = New Aspose.Words.DocumentBuilder(doc)
Builder.MoveToSection(0)
srcNode = Builder.CurrentSection.Body
insertNode = OkDoc.FirstSection.Body
Dim importer As New NodeImporter(doc, OkDoc, ImportFormatMode.KeepSourceFormatting)
AppendBookmarkedText(importer, srcNode, insertNode)
For i As Integer = 0 To strItems - 1
Builder.MoveToSection(i * 2 + 1)
insertNode = OkDoc.FirstSection.Body
srcNode = Builder.CurrentSection.Body
AppendBookmarkedText(importer, srcNode, insertNode)
Next
OkDoc.ViewOptions.ViewType = Settings.ViewType.PageLayout
OkDoc.Save(OkFileName)
Private Sub AppendBookmarkedText(ByVal importer As NodeImporter, ByVal srcNode As CompositeNode, ByVal textNode As CompositeNode)
' This is the paragraph that contains the beginning of the bookmark.
Dim startPara As Paragraph = TryCast(srcNode.FirstChild, Paragraph)
' This is the paragraph that contains the end of the bookmark.
Dim endPara As Paragraph = TryCast(srcNode.LastChild, Paragraph)
If (startPara Is Nothing) OrElse (endPara Is Nothing) Then
Throw New InvalidOperationException("Parent of the bookmark start or end is not a paragraph, cannot handle this scenario yet.")
End If
' Limit ourselves to a reasonably simple scenario.
If startPara.ParentNode IsNot endPara.ParentNode Then
Throw New InvalidOperationException("Start and end paragraphs have different parents, cannot handle this scenario yet.")
End If
' We want to copy all paragraphs from the start paragraph up to (and including) the end paragraph,
' therefore the node at which we stop is one after the end paragraph.
Dim endNode As Node = endPara
' This is the loop to go through all paragraph-level nodes in the bookmark.
Dim curNode As Node = startPara
Do While curNode IsNot endNode
' This creates a copy of the current node and imports it (makes it valid) in the context
' of the destination document. Importing means adjusting styles and list identifiers correctly.
Dim newNode As Node = importer.ImportNode(curNode, True)
' Now we simply append the new node to the destination.
textNode.AppendChild(newNode)
curNode = curNode.NextSibling
Loop
End Sub
File attachment : Step3.doc
I use code Like As
OkDoc = New Aspose.Words.Document(OkFileName)
OkBuilder = New Aspose.Words.DocumentBuilder(OkDoc)
OkBuilder.MoveToDocumentStart()
startPara = OkBuilder.CurrentParagraph
OkBuilder.MoveToDocumentEnd()
endPara = OkBuilder.CurrentParagraph
CombineParagraphsIntoOne(startPara, endPara)
OkDoc.ViewOptions.ViewType = Settings.ViewType.PageLayout
OkDoc.Save(OkFileName)
File attachment : Step4.Png
I use code Like As
OkDoc = New Aspose.Words.Document(OkFileName)
OkBuilder = New Aspose.Words.DocumentBuilder(OkDoc)
Dim intTextLength As Integer = OkBuilder.CurrentParagraph.Range.Text.Length
Dim ps As PageSetup = OkBuilder.PageSetup
ps.PageHeight = ConvertUtil.MillimeterToPoint(20)
ps.PageWidth = ConvertUtil.MillimeterToPoint(intTextLength / 2 * 10)
ps.TopMargin = ConvertUtil.MillimeterToPoint(5)
ps.BottomMargin = ConvertUtil.MillimeterToPoint(5)
ps.LeftMargin = ConvertUtil.MillimeterToPoint(5)
ps.RightMargin = ConvertUtil.MillimeterToPoint(5)
ps.VerticalAlignment = PageVerticalAlignment.Center
OkDoc.Save(strFilePath, SaveFormat.Png)