Forum How do I...?

ConvertMultiple with Stream Output?

jms04081974
How can I alter this method to output a stream instead?

Public Function ConvertMultiple(ByVal xmlPaths As String(), ByVal pdfPath As String) As Boolean _
Implements IPrince.ConvertMultiple
Dim args As String
Dim doc As String
Dim docPaths As String

docPaths = ""
For Each doc In xmlPaths
docPaths = docPaths + Chr(34) + doc + Chr(34) + " "
Next

args = getArgs() + docPaths + " -o " + Chr(34) + pdfPath + Chr(34)

Return Convert1(args)
End Function
mikeday
You can merge it with the Convert method that writes to a stream! :)
jms04081974
Ha, was hoping you already wrote it :) Here it is in case anyone finds this thread who's using the .net wrapper and needs same.

Public Function ConvertMultiple(ByVal xmlPaths As String(), ByVal pdfOutput As Stream) As Boolean

Dim buf(4096) As Byte
Dim bytesRead As Integer
Dim prs As New Process
Dim args As String
Dim doc As String
Dim docPaths As String

docPaths = ""
For Each doc In xmlPaths
docPaths = docPaths + Chr(34) + doc + Chr(34) + " "
Next

If Not pdfOutput.CanWrite Then
Throw New ApplicationException("The pdfOutput stream is not writable")
Else
args = getArgs() + "--silent " + "" + docPaths + " -o -"
prs = StartPrince(args)

prs.StandardInput.Close()

bytesRead = prs.StandardOutput.BaseStream.Read(buf, 0, 4096)
Do While bytesRead <> 0
pdfOutput.Write(buf, 0, bytesRead)
bytesRead = prs.StandardOutput.BaseStream.Read(buf, 0, 4096)
Loop
prs.StandardOutput.Close()

If ReadMessages(prs) = "success" Then
Return True
Else
Return False
End If
End If
End Function