-
Notifications
You must be signed in to change notification settings - Fork 568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge pdf files. Merged files are not released and cannot be deleted #1112
Comments
This really looks like the files are still open by the process. I assume you are also using Windows, as this OS is known for keeping resources locked. Important is that the documents you want to delete are all closed. You may check if the "closeStream" flag of the Objects are really "true". Maybe it is being set somewhere to "false". Please check if the currentPdfReaderInstance.getReader().close();
currentPdfReaderInstance.getReaderFile().close(); are really being executed in |
It seems, that the Files are only closed if the PdfReader.close() is still as from 2010. I think |
yes, i am usign widnows.
but they don't do anything because they don't respect the conditions |
Hello guys, I want to share my experience with PdfReader. as workaround you can control how file opened for PdfReader for (File file : files) {
boolean forceRead = file.length() <= 10_000_000; // limit memory usage, set greater value if your app can use large heap
boolean plainRandomAccess = true; // do not use MappedRandomAccessFile, Note: this flag ignored when forceRead=true
try (RandomAccessFileOrArray raf = new RandomAccessFileOrArray(file.getPath(), forceRead, plainRandomAccess);
PdfReader reader = new PdfReader(raf, null)) {
// do copy
}
} |
I have a Java method that needs to read the PDF files inside a folder and create a file corresponding to the merge of all those inside the folder. Finally I have to delete the files and leave only the result in the folder.
The problem is that once the final file is created, I can't delete all the other files used for the merge, as if it doesn't release them after use. I also tried to delete them manually from the file explorer, but I can't (as long as the application remains running). I'm using this version:(Java 11)
My Code:
if after this piece of code I try to delete all the files in the "files" list by calling the .delete() method, it doesn't work
I also tried removing the try wth resources and manually closing reader, document copy etc... I tried inserting the PdfCopy in the try with resources together with document, but nothing, I can't find a solution...
The text was updated successfully, but these errors were encountered: