Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Jun 19, 2014 8:48 am

I have downloaded a trial version a few days ago. My scenario:

In a loop, load RTF as a memory stream, then save it as a PDF to a memory stream.

I have tried to cobble code together to prove it works and it ALWAYS crashes on the second iteration with "Index was out of range. Must be non-negative and less than the size of the collection."

I have tried all the different "load rtf" methods I could find but none seem to work.

Code snippet below:

Dim memoryStream1 As New MemoryStream()
Dim streamWriter As New StreamWriter(memoryStream1)

Dim memoryStreamPDF As New MemoryStream()

If Me.ReferralBodyFormat = "RTF" Then
streamWriter.Write(Me.ReferralBody)
memoryStream1.Position = 0

'convert to pdf
Dim document As New Document()
document.LoadFromStream(memoryStream1, FileFormat.Rtf) <------ *** errors here ***
document.SaveToStream(memoryStreamPDF, FileFormat.PDF)
document.Close()
document.Dispose()

End If

memoryStreamPDF.Position = 0

Thanks,
Dave

david.martin
 
Posts: 2
Joined: Fri Jun 13, 2014 6:46 am

Thu Jun 19, 2014 9:04 am

Dear Dave,

Thanks for your inquiry.
To help us to reproduce your issue, would you please save your rtf data to rtf file and then share it here?
You could also send your file to support@e-iceblue.com or amy.zhao@e-iceblue.com.
Thanks.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Jun 20, 2014 7:03 am

It's multiple rtf's, about 250 at the moment.

david.martin
 
Posts: 2
Joined: Fri Jun 13, 2014 6:46 am

Fri Jun 20, 2014 7:30 am

Dear Dave,

Thanks for your reply.
Please try Paragraph.AppendRTF method.
Code: Select all
Dim section As Section =document.AddSection()
Dim paragraph As Paragraph = section.AddParagraph()
paragraph.AppendRTF(Me.ReferralBody);
document.SaveToStream(memoryStreamPDF, FileFormat.PDF)


If you still have the issue, would you please provide us a .bin file?
Code: Select all
System.Text.UTF8Encoding asc = new System.Text.UTF8Encoding();
 byte[] bArrRTF = asc.GetBytes(Me.ReferralBody);
 System.IO.File.WriteAllBytes("sample.bin",bArrRTF);


Thanks.

Best wishes,
Amy
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc