I have a use case to verify the incomming pdf is corrupted or not before I merge. Any help is appreciated.
thanks
Hi there,
Thanks for your inquiry. You can use CorruptedFileAction property of PdfFileEditor. This property defines behavior of PDfFileEditor.Concatenate and Append functions when some of files to concatenate/append are corrupted.
- If CorruptedFileAction is “StopWithError” then process will be stopped and exception thrown or false returned as result of unsuccessful operation (in depend of AllowConcatenateExceptions state)
- If CorruptFileAction is “ConcatenateIgnoringCorrupted” then only valid files will be concatenated, so the resultant file will be correct too.
Information about corrupted files will be collected and accessible in CorruptedItems property.
No exceptions are thrown in this case (operation is succeeded anyway)
Please check following sample code snippet for the reference.
PdfFileEditor pfe = new PdfFileEditor();
pfe.CorruptedFileAction = PdfFileEditor.CorruptedFileActions.ConcatenateIgnoringCorrupted;
pfe.Concatenate(new string[] { “file1.pdf”, “file2.pdf”, “file3.pdf” }),
“output.pdf”);
if (pfe.CorruptedItems.Length > 0)
{
Console.WriteLine(“Corrupted documents:” );
foreach(CorruptedItem item in pfe.CorruptedItems)
{ Console.WriteLine(item.Index + " reason " + item.Exception.Message); }
}
else Console.WriteLine(“No corrupted documents”);
Please feel free to contact us for any further assistance.
Best Regards,
Thanks for your response. Further, is there a way I can just get the information about pdf whether it is currupted before I attempt to any operation like merge and fill?
Hi Rayasam,
Thanks for your feedback. I’m afraid currently there is no such feature available to detect whether PDF file is corrupt in Aspose.Pdf. However, I’ve logged an investigation ticket for the purpose in our issue tracking system as PDFNEWNET-35497. We will keep you updated about the issue progress via this forum thread.
Meanwhile, It would be helpful in investigation, if you please share some corrupt document here.
Sorry for the inconvenience faced. Please feel free to contact us for any further assistance.
Best Regards,
Hi Rayasam,
Thanks for your patience. Please check following sample function. Hopefully it will serve the purpose.
bool IsCorrupt(string path)
{
try
{ Document doc = new Document(path) }
catch()
{ return true; }
return false;
}
Please feel free to contact us for any further assistance.
Best Regards,
The issues you have found earlier (filed as PDFNEWNET-35497) have been fixed in Aspose.Pdf for .NET 8.3.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Any news on this?
Is it possible to just verify is the file is corrupt?
(Attached is a corrupted file - page 19)
The code proprosed does not work:
public static bool IsCorrupt(string path)
{
try
{
Document doc = new Document(path);
}
catch (Exception)
{
return true;
}
<span style="color:blue;">return</span> <span style="color:blue;">false</span>;
}
Hi Bruno,
Thanks for your inquriy. It seems your document has some different issue, the suggested code works in case of a completely corrupt PDF and Aspose.Pdf could not load it at all. However, we have logged a ticket PDFNEWNET-40785 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.
We are sorry for the inconvenience caused.
Best Regards,
Hi!
Can you check the status on this bug for me, please?
Thanks!!
Hi Bruno,
Thanks for your patience.
As we recently have noticed earlier reported PDFNEWNET-40785 issue, so its pending for review and is not yet resolved. However the product team will surely consider investigating/fixing it as per development schedule and as soon as we have some definite updates regarding its resolution, we will let you know. Please be patient and spare us little time. We are sorry for this delay and inconvenience.
Hi Bruno,
Thanks for your inquriy. I am afraid your issue is still pending for investigation, as currently product team is busy in resolving other issues in the queue, reported earlier. However we will notify you as soon as we made some significant progress towards your issue resolution.
Thanks for your patience and cooperation.
Best Regards,