If given file is not a vaild pdf file (e.g. a txt-file renamed to pdf) method will return false. Perfect.
Unfortunateley the given file is locked now and can not be deleted. Lock will only be removed when Java-VM is finished.
Sorry for delay. We are looking into this issue. We will update you very soon about our findings. Please update us which version of Aspose.PDF are you using?
You can detect a password protected file by using below line of code:
fileInfo.hasOpenPassword()
and by entering its password you can manipulate that file as per your requirements. In case you are facing any problem with such files then kindly explain the scenario while sharing the source files with us so that we may investigate to help you out.
this problem has nothing to do with locking per password.
Problem: After using PdfFileInfo the file is still under access by Aspose. Therefore it can not be deleted or modified within java code afterwards. This problem occurs with non pdf files only!!
Code snippet for test
public static void main(String[] args)
{
// Unlock Aspose.Pdf first
UnlockAspose.getInstance().unlockPdf();
String fileName = "C:\\Users\\mas\\Documents\\NoPdf.pdf";
System.out.println("File content is pdf: " + isPdfFile(fileName));
System.out.println(fileName + " delete: " + new File(fileName).delete());
JOptionPane.showMessageDialog(null, "Delete of file " + fileName + "is not possible now",
"Message before end of Java VM", JOptionPane.INFORMATION_MESSAGE);
}
private static boolean isPdfFile(String addPdfFileName)
{
PdfFileInfo fileInfo = new PdfFileInfo(addPdfFileName);
boolean pdfFile = fileInfo.isPdfFile();
fileInfo.dispose();
fileInfo.close();
return pdfFile;
}
I have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFJAVA-37425 has been logged in our issue management system for further investigation and resolution. The issue ID has been linked with this thread so that you will receive notification as soon as the issue is resolved.
The issues you have found earlier (filed as PDFJAVA-37425) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by asad.ali