Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Apr 24, 2020 9:39 pm

I am scouring the documentation, but I don't see any examples of simply testing whether any file is a PDF. I need to test them as they are uploaded by users, so I can response appropriately. I can attempt to load it, but there is no documentation I found that tells me what exceptions to expect if its not valid. Is there an API reference somewhere? Something that explains the document model properties and methods?

JRodman1
 
Posts: 1
Joined: Fri Apr 24, 2020 9:29 pm

Sun Apr 26, 2020 2:57 am

Hello,

Thanks for your inquiry.
You can specify the file format as PDF when calling the "LoadFromFile" method, like the below code. If the loaded document is not in PDF format, the application will throw the exception "Invalid/Unknown/Unsupported format".
Code: Select all
    PdfDocument pdf = new PdfDocument();
    pdf.LoadFromFile(filepath, FileFormat.PDF);

As for API reference, please visit the below link. Any other question, please feel free to contact us.
https://www.e-iceblue.com/Tutorials/API/Spire.PDF.html

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF