We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Determine conversion result

Hi,

I built a PDF converter for different files formats (e.g. Word, Excel, Powerpoint and some bitmap formats e.g. jpg, gif, png). Based on the extension of the inputFile, I’m using Aspose.Word.Document.SaveToPdf(outputFile) for Word, Aspose.Cells.Workbook.Save(outputFile, FileFormattype.Pdf) for Excel, Aspose.Slides.Presentation.Save(outputFile, SaveFormat.Pdf) for Powerpoint and Aspose.Pdf.Pdf.Save(outputFile) for bitmaps.

Everything is working perfectly so far. Thank you so much for making all this so easy for us!

Here is my question:
What happens if the conversion fails? Let’s say I have an input file called “test.doc” which is not in MS Word format. What is Aspose.Word.Document.SaveToPdf() going to do? As all the methods mentioned above have no return type, how can I tell if the conversion was successful and led to a valid PDF?
Is there a way I can check, if a certain file is a valid PDF?

Thanks,
Ingmar

Hi

Thanks for your inquiry. If an input file is corrupted or Aspose.Words does not support such file format, Aspose.Words will throw an appropriate exception upon loading the document.
If you need to check whether the file is PDF document or not, you can check the first 4 bytes of the file. PDF files always starts with %PDF. Please see PDF specification for more information (section 3.4.1)
http://www.pdf-tools.com/public/downloads/pdf-reference/pdfreference17.pdf
Hope this helps.
Best regards.