Using PdfFileInfo leads to locked files

Hi,

i want to check files for pdf content with given code snippet.

private static boolean isPdfFile(String addPdfFileName)
{
	PdfFileInfo fileInfo = new PdfFileInfo(addPdfFileName);
	boolean pdfFile = fileInfo.isPdfFile();
	fileInfo.dispose();
	fileInfo.close();
	return pdfFile;
}

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.

Best regards
Matthias

@curmas,

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?

@curmas

Thank you for contacting support.

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.

i reproduced this error with latest version of Aspose.Pdf for Java 18.1

Best regards
Matthias

Hi Farhan,

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;
}

Best regards
MatthiasNoPdf.pdf (51.6 KB)

@curmas

Thank you for explaining the problem.

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.

We are sorry for the inconvenience.

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