Hello Thomas and thanks for the response. Ok, the clone method took care of my debug.assert issue however, I am still not able to add images from a stream. I am not using MDDDL's, is there not a set of compiled assemblies out there with this function built in? I have attached a printout of what I receive when trying to add pictures. My relevant code is posted below. Thanks in advance for any assistance!
Print Function
Code:
Public Sub Print(ByVal tempFile As String)
If Not _bunkToPrint Is Nothing Then
Dim myDoc As Document = CreateBunkDocument(tempFile)
Dim render As DocumentRenderer = New DocumentRenderer(myDoc)
Dim printDoc As MigraDocPrintDocument = New MigraDocPrintDocument()
printDoc.Renderer = render
printDoc.Renderer.PrepareDocument()
printDoc.Print()
End If
End Sub
Create Document
Code:
Private Function CreateBunkDocument(ByVal template As String) As Document
Dim mDoc As Document = New Document()
Dim pgSetup As PageSetup = mDoc.DefaultPageSetup.Clone()
pgSetup.TopMargin = 0
pgSetup.LeftMargin = 0
Dim xDoc As New XmlDocument()
xDoc.Load(template)
Dim root = xDoc.DocumentElement
pgSetup.PageHeight = Convert.ToInt32(root.SelectSingleNode("Height").InnerText)
pgSetup.PageWidth = Convert.ToInt32(root.SelectSingleNode("Width").InnerText)
Dim section As Section = mDoc.AddSection()
section.PageSetup = pgSetup
Dim lblNodeList As XmlNodeList = root.GetElementsByTagName("Label")
If lblNodeList.Count > 0 Then
IterateLabelNodeList(lblNodeList, section)
End If
Dim ImgNodeList As XmlNodeList = root.GetElementsByTagName("Picture")
If ImgNodeList.Count > 0 Then
IterateImgNodeList(ImgNodeList, section)
End If
Return mDoc
End Function
Get Image Values
Code:
Private Sub IterateImgNodeList(ByVal nodeList As XmlNodeList, docSection As Section)
For Each element As XmlElement In nodeList
Dim pic As TicketImage = New TicketImage()
For Each node As XmlNode In element.ChildNodes
Select Case node.Name
Case "Image"
pic.Img = node.InnerText
Case "Top"
pic.Y = Convert.ToInt32(node.InnerText)
Case "Left"
pic.X = Convert.ToInt32(node.InnerText)
Case "Height"
pic.Height = Convert.ToInt32(node.InnerText)
Case "Width"
pic.Width = Convert.ToInt32(node.InnerText)
End Select
Next
CreateSectionImage(pic, docSection)
Next
End Sub
Add Image to Document Section
Code:
Private Sub CreateSectionImage(ByVal ti As TicketImage, sec As Section)
Dim img As Image = sec.AddImage(PicStream(ti.Img))
img.RelativeVertical = RelativeVertical.Page
img.Height = ti.Height
img.Width = ti.Width
img.Top = ti.Y
img.Left = ti.X
End Sub
Image Stream
Code:
Private Function PicStream(ByVal xmlString As String) As MemoryStream
Dim bytes As Byte() = Convert.FromBase64String(xmlString)
Dim stream As MemoryStream = New MemoryStream(bytes, 0, bytes.Length)
Return stream
End Function