[
https://issues.apache.org/jira/browse/PDFBOX-6120?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18044819#comment-18044819
]
Tilman Hausherr edited comment on PDFBOX-6120 at 12/13/25 5:04 AM:
-------------------------------------------------------------------
The {{PreflightDocument}} is closeable so that should do the thing.
What jdk version are you using?
You should also consider to move to veraPDF:
{code:java}
static void checkWithVeraPDF(File file) throws IOException, VeraPDFException
{
// https://docs.verapdf.org/develop/
VeraGreenfieldFoundryProvider.initialise();
try (VeraPDFFoundry foundry = Foundries.defaultInstance();
PDFAParser parser = foundry.createParser(file,
PDFAFlavour.PDFA_1_B);
PDFAValidator validator =
foundry.createValidator(PDFAFlavour.PDFA_1_B, false))
{
assertTrue(validator.validate(parser).isCompliant());
}
}
{code}
was (Author: tilman):
Why not just call {{PreflightParser.validate(file)}} ?
And btw the {{PreflightDocument}} is closeable.
You should also consider to move to veraPDF:
{code:java}
static void checkWithVeraPDF(File file) throws IOException, VeraPDFException
{
// https://docs.verapdf.org/develop/
VeraGreenfieldFoundryProvider.initialise();
try (VeraPDFFoundry foundry = Foundries.defaultInstance();
PDFAParser parser = foundry.createParser(file,
PDFAFlavour.PDFA_1_B);
PDFAValidator validator =
foundry.createValidator(PDFAFlavour.PDFA_1_B, false))
{
assertTrue(validator.validate(parser).isCompliant());
}
}
{code}
> PreflightParser .validate leads to "Too many open files"
> --------------------------------------------------------
>
> Key: PDFBOX-6120
> URL: https://issues.apache.org/jira/browse/PDFBOX-6120
> Project: PDFBox
> Issue Type: Bug
> Components: Preflight
> Affects Versions: 3.0.6 PDFBox
> Reporter: Théo Lenoble
> Priority: Major
>
> Hi from France,
> Hope my english will be clear enough to explain what we encounter :D
> We use org.apache.pdfbox:preflight:3.0.6, calling static method
> PreflightParser.validate we encounter "Too many open files" issues.
> We solved it locally by extending PreflightParser, implementing Closeable
> interface and overriding validate function.
> Exemple of our solution :
> {code:java}
> public class CustomPreflightParser extends PreflightParser implements
> Closeable {
> public static ValidationResult validate(File file) throws IOException {
> ValidationResult result;
> try(
> // we move PreflightParser initialisation here
> CustomPreflightParser parser = new CustomPreflightParser(file);
> PreflightDocument document = (PreflightDocument) parser.parse()
> ) {
> result = document.validate();
> }
> catch (SyntaxValidationException e)
> {
> result = e.getResult();
> }
> return result;
> }
> @Override
> public void close() {
> IOUtils.closeQuietly( this.source );
> IOUtils.closeQuietly( this.document );
> // May be missing close ressources, seems to be enought for us
> }
> }
> {code}
> We didn't spend more time on it so may be there is a better solution ?
> We wanted to share it with you in case you validate the issue and provide a
> proper fix.
> And may be it could help other to avoid having the same issue (or have a
> quick imperfect solution).
> Hope this could help :)
> Regards,
> Théo Lenoble
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]