I am using Aspose PDF in my web application. It is working fine if we receive correct files, but some times we are getting corrupted files which can’t be opened. And now my question is how to verify weather the pdf is correct or not using Aspose PDF. We bought Aspose Total.
We need to verify the below extensions.
.PDF/.JPEG/.TIFF/.DOCX
Hi there,
Thanks for your inquriy. You may use following code snippets to check a valid PDF document using Aspose.Pdf for .NET.
For other file formats, you can use FileFormatUtil.DetectFileFormat method from Aspose.Cells. Aspose.Cells method can detect more file formats http://www.aspose.com/docs/display/cellsnet/Aspose.Cells.FileFormatType+Enumeration. And for image file format detection you can use Aspose.Imaging as following.
// Facades (Aspose.Pdf):
using (var pdfFileInfo = new PdfFileInfo(@"C:\pdftest\InvalidPdf.pdf"))
{
if (!pdfFileInfo.IsPdfFile)
Console.WriteLine("The given PDF content is invalid or encrypted.");
if (pdfFileInfo.IsPdfFile)
Console.WriteLine("The given PDF content is valid.");
}
// DOM (Aspose.Pdf):
private static bool IsCorrupt(string path)
{
try
{
Document doc = new Document(path);
}
catch (Exception ex)
{
return true;
}
return false;
}
// Image file format detection using Aspose.Imaging:
int imageType = (int)Aspose.Imaging.Image.GetFileFormat("Test.PNG");
string image = null;
switch (imageType)
{
case 0:
image = "Undefined";
break;
case 1:
image = "Custom";
break;
case 2:
image = "BMP";
break;
case 4:
image = "GIF";
break;
case 8:
image = "JPEG";
break;
case 16:
image = "PNG";
break;
case 32:
image = "TIFF";
break;
case 64:
image = "PSD";
break;
case 128:
image = "DXF";
break;
case 256:
image = "DWG";
break;
case 512:
image = "Jpeg2000";
break;
case 1024:
image = "Djvu";
break;
}
Console.Out.WriteLine(image);
Please feel free to contact us for any further assistance.
Best Regards,