Hello. I am using Aspose.PDF as part of an automatic word to PDF and Excel to PDF conversion webapp that is used for internal memos and the like.
I am using the following code to create PDF files from those sources. I do not want to save copies of the files to disk, and so instead am using IO.Stream to move data around.
Dim FileID As Guid = Guid.NewGuid()
Dim PostedFile As HttpPostedFile = Me.FI_FileInput.PostedFile
Dim FileData() As Byte
Dim PDFfile As New Aspose.Pdf.PdfDim filestream As New System.IO.MemoryStream
If PostedFile.FileName.EndsWith(".doc") Then
Dim docfile As New Aspose.Words.Document(PostedFile.InputStream)
Dim XMLStream As New System.IO.MemoryStream
docfile.Save(XMLStream, SaveFormat.AsposePdf)
PDFfile.BindXML(XMLStream, Nothing)
PDFfile.Save(filestream)
End If
If PostedFile.FileName.EndsWith(".xls") Then
Dim xlsfile As New Aspose.Cells.Workbook
xlsfile.Open(PostedFile.InputStream)
Dim XMLStream As New System.IO.MemoryStream
xlsfile.Save(XMLStream, SaveFormat.AsposePdf)
PDFfile.BindXML(XMLStream, Nothing)
PDFfile.Save(filestream)
End If
The difficulty is that the filestream generated by this code gives an unusable PDF for the word conversion, and an error for Excel.
Trying to convert a word file gives me a PDF, but Acrobat Reader claims the file is damaged, and won't read it.
Trying to convert an Excel file throws an exception: There is an invalid character in the given encoding. Line 1, position 1.
Do you have any ideas on how to fix this?