Hello,
I’m using this PDFTron example to extract the logical structure of tagged PDFs. After extracting the structure I 'am not able to delete the file from JAVA I’m getting the following error in JAVA on Windows 10.
The process cannot access the file because it is being used by another process
PDFNet.initialize("KEY OVER HERE");
try { // Extract Logical Structure from PDF document and return it.
pdfTronDoc = new PDFDoc(inputFile);
pdfTronDoc.lockRead();
pdfTronDoc.initSecurityHandler();
STree tree = pdfTronDoc.getStructTree();
if (tree.isValid()) {
System.out.println("Document has a StructTree root.");
} else {
System.out.println("This document does not contain any logical structure.");
}
System.out.println("Extraction of PDF logical structure and page content.");
{
// A map which maps page numbers(as Integers)
// to page Maps(which map from struct mcid(as Integers) to text Strings)
Map<Integer, Map<Integer, String>> mcid_doc_map = new TreeMap<Integer, Map<Integer, String>>();
ElementReader reader = new ElementReader();
for (PageIterator itr = pdfTronDoc.getPageIterator(); itr.hasNext();) {
Page current = itr.next();
reader.begin(current);
Map<Integer, String> page_mcid_map = new TreeMap<Integer, String>();
mcid_doc_map.put(Integer.valueOf(current.getIndex()), page_mcid_map);
ProcessElements2(reader, page_mcid_map);
reader.end();
}
if (tree.isValid()) {
for (int i = 0; i < tree.getNumKids(); ++i) {
ProcessStructElement2(tree.getKid(i), mcid_doc_map, 0);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
try {
pdfTronDoc.unlockRead();
pdfTronDoc.close();
System.out.println("Closed Document");
} catch (PDFNetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new HashMap<String, ArrayList<String>>(documentMap);
}
The above code is to extract the content using pdftron.
and below is the code to delete the file.
Basically after opening the file with PDFTron and reading the contents I cannot delete the file. I get the following error “The process cannot access the file because it is being used by another process” using the JAVA SDK on Windows 10.
Thank you for your response. I see you are using the Files API to load the document. In order for us to reproduce the exact issue on our end, could you please provide us with the full code along with an example file you are using ? In addition, are you experiencing this issue with all files, or just some?