Error converting from Word to PDF via XML

*I just purchased your Asprose.Word product and I am getting an error when I try to load a typical file of mine (test.doc).

The error is below:

This is an unexpected token. The expected token is ‘EndElement’. Line 65, position 170.*

I am trying to read this document and then save it to an XML stream so I can write it back out as a PDF using Asprose.PDF.

I have attached the document for your review.

Any ideas?

Thanks

Steven Cardinale

Hi Steven,
I’ve just converted your file to PDF using following code:

Document doc = new Document(“test.doc”);
doc.Save(“test.xml”, SaveFormat.FormatAsposePdf);
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(“test.xml”, null);
pdf.Save(“test.pdf”);

There were not any errors. Ok, thanks for your report, we’ll try to figure out what should it be.

Thanks for the code. However, now I get an error saying: “Cannot access a closed file”

The document is created on the fly, however, I can easily open the document with word at the time I am trying to create the document, so I know the document is available and not locked. The file name is passed into the function as a string.

Here is the code I am using:

Private Function convertDoc2PDF(ByVal fileName As String) As String
Dim doc As Aspose.Word.Document, objPdf As New Aspose.Pdf.Pdf
Dim wordLicense As New Aspose.Word.License, pdfLicense As New Aspose.Pdf.License
Dim file As FileInfo, fileBase As String
Try
wordLicense.SetLicense("Aspose.Custom.lic")
pdfLicense.SetLicense("Aspose.Custom.lic")
' Convert the document to a PDF.
fileBase = Left(fileName, Len(fileName) - 4)
' Here is where the error occurs
doc = New Aspose.Word.Document(rfw.docSavePath & fileBase & ".doc")
' Check to see if a conversion should be performed
' Save as the intermediate xml file
doc.Save(rfw.docSavePath & fileBase & ".xml", Aspose.Word.SaveFormat.FormatAsposePdf)
objPdf.BindXML(rfw.docSavePath & fileBase & ".xml", Nothing)
objPdf.Save(rfw.docSavePath & fileBase & ".pdf")
' Delete the intermediate XML file
file = New FileInfo(rfw.docSavePath & fileBase & ".xml")
file.Delete()
' Delete the old word document
file = New FileInfo(rfw.docSavePath & fileBase & ".doc")
file.Delete()
convertDoc2PDF = fileBase & ".pdf"
Catch ex As Exception
Throw ex
End Try
End Function

Any ideas?

OK,

Well I hope I have found the ability to re-create the problem. I have 2 document files, both were generated from the same original MS word doc file. One works fine and one gives me the Cannot Open a Closed file error.

I’m attachine the one that generates the error here. I will attach the one that works fine as a separate Post.

Thanks

Steven Cardinale

Here is the file that works appropriately.

File test_no_work.doc actually has .rtf format. Please resave it as regular Word document and it will be properly opened and processed by Aspose.Word.

Thanks.

The problem is that the way we generate the word doc, we are actually generating a RTF file. I saw the following on the support pages:

"The reason rtf was delayed is because we’ve had too many new features to work on that are no less important. Sorry no firm date for rtf support yet, please check back in 1-2 months.

Roman Korchagin
Lead Developer
Aspose Auckland Team

So, I guess there is no RTF support for the time being. Any other suggestions?

Steven

If you are not able to generate and save your files into binary Word format, then the only suitable solution is waiting for RTF support implementation.