Hello -
I am attempting to use the Aspose libraries to append a Microsoft Word Document (DOC file's contents) onto an Aspose concatenated stream. I am getting an error when the code tries to execute the .Concatenate method. Essentially, I read in the Word Document, convert to a PDF, resave then load it into a stream and try to concatenate it to the existing output stream. Here is the error:
Invalid pdf format:pdf head signature is not found!
Here is the code:
Dim sURL As String = "... path to the Word Document *.DOC ..."
Dim stDoc As New FileStream(sURL, System.IO.FileMode.Open)
stDoc.Seek(0, SeekOrigin.Begin)
Dim wlicense As Aspose.Words.License = New Aspose.Words.License
wlicense.SetLicense("Aspose.Words.lic")
Dim doc1 As Aspose.Words.Document = New Aspose.Words.Document(stDoc)
stDoc.Dispose()
Dim sURLWordToPDF As String = sURL.Replace(".DOC", ".PDF")
doc1.Save(sURLWordToPDF, Aspose.Words.SaveFormat.Pdf)
Dim stURLdoc As New FileStream(sURLWordToPDF, System.IO.FileMode.Open)
stURLdoc.Seek(0, SeekOrigin.Begin)
Dim lic As Aspose.Pdf.Kit.License = New Aspose.Pdf.Kit.License
lic.SetLicense("Aspose.PDF.Kit.lic")
Dim pdfEditor As Aspose.Pdf.Kit.PdfFileEditor = New Aspose.Pdf.Kit.PdfFileEditor
pdfEditor.Concatenate(streamFile, stURLdoc, streamOutput)
streamFile = streamOutput
stURLdoc.Dispose()
I am able to validate that the intermediate PDF file is valid - I can open / view it after it has been created, then close the file during my testing / debugging (the file is not open during the Concatenate operation). Attached is the PDF file (as converted from the original Word DOC file).
I am using Aspose.Pdf 4.8.0.0, Aspose.Words 9.5.0.0, Aspose.Pdf.Kit 5.1.0.0
I expect that there may even be cleaner / more efficient methods for converting the Word Doc into a stream then concatenating it to the composite stream. I eagerly await your recommendations.
Cheers, PDG