Bonjour

Je cherche à contrôler les pdfs pour savoir s'ils ont de type A1-b

j'ai trouvé cette exemple sur le site : https://pdfbox.apache.org/1.8/cookbo...alidation.html

Pour information, je ne développe jamais sous eclipse.

1 - je crée un projet
2 - je crée une classe : ValidePdf.java
voici le code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.io.IOException;
import org.apache.pdfbox.preflight.parser.PreflightParser;
import org.apache.pdfbox.preflight.PreflightDocument;
import org.apache.pdfbox.preflight.ValidationResult;
import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
import org.apache.pdfbox.preflight.exception.SyntaxValidationException;
 
public class validepdf {
 
	public static void main(String[] args) throws IOException
	{
 
 
		ValidationResult result = null;
 
		PreflightParser parser = new PreflightParser(args[0]);
		try
		{
 
		    /* Parse the PDF file with PreflightParser that inherits from the NonSequentialParser.
		     * Some additional controls are present to check a set of PDF/A requirements. 
		     * (Stream length consistency, EOL after some Keyword...)
		     */
		    parser.parse();
 
		    /* Once the syntax validation is done, 
		     * the parser can provide a PreflightDocument 
		     * (that inherits from PDDocument) 
		     * This document process the end of PDF/A validation.
		     */
		    PreflightDocument document = parser.getPreflightDocument();
		    document.validate();
 
		    // Get validation result
		    result = document.getResult();
		    document.close();
 
		}
		catch (SyntaxValidationException e)
		{
		    /* the parse method can throw a SyntaxValidationException 
		     * if the PDF file can't be parsed.
		     * In this case, the exception contains an instance of ValidationResult  
		     */
		    result = e.getResult();
		}
 
		// display validation result
		if (result.isValid())
		{
		    System.out.println("The file " + args[0] + " is a valid PDF/A-1b file");
		}
		else
		{
		    System.out.println("The file" + args[0] + " is not valid, error(s) :");
		    for (ValidationError error : result.getErrorsList())
		    {
		        System.out.println(error.getErrorCode() + " : " + error.getDetails());
		    }
		}
	}
}
3 - j'ajoute la librairie preflight-1.8.0.jar
4 - j'ajoute la librairie pdfbox-1.8.12.jar

Dela je run => l'erreur suivante :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.pdfbox.pdfparser.BaseParser.<clinit>(BaseParser.java:70)
at validepdf.main(validepdf.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
5 - j'ajoute la librairiecommons-logging-1.3-.jar

Puis je run => l'erreur suivante

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at org.apache.pdfbox.preflight.utils.COSUtils.<clinit>(COSUtils.java:43)
at org.apache.pdfbox.preflight.process.reflect.ResourcesValidationProcess.validateExtGStates(ResourcesValidationProcess.java:104)
at org.apache.pdfbox.preflight.process.reflect.ResourcesValidationProcess.validate(ResourcesValidationProcess.java:69)
at org.apache.pdfbox.preflight.utils.ContextHelper.callValidation(ContextHelper.java:74)
at org.apache.pdfbox.preflight.utils.ContextHelper.validateElement(ContextHelper.java:49)
at org.apache.pdfbox.preflight.process.reflect.SinglePageValidationProcess.validateResources(SinglePageValidationProcess.java:158)
at org.apache.pdfbox.preflight.process.reflect.SinglePageValidationProcess.validate(SinglePageValidationProcess.java:77)
at org.apache.pdfbox.preflight.utils.ContextHelper.callValidation(ContextHelper.java:74)
at org.apache.pdfbox.preflight.utils.ContextHelper.validateElement(ContextHelper.java:49)
at org.apache.pdfbox.preflight.process.PageTreeValidationProcess.validatePage(PageTreeValidationProcess.java:56)
at org.apache.pdfbox.preflight.process.PageTreeValidationProcess.validate(PageTreeValidationProcess.java:45)
at org.apache.pdfbox.preflight.utils.ContextHelper.callValidation(ContextHelper.java:74)
at org.apache.pdfbox.preflight.utils.ContextHelper.validateElement(ContextHelper.java:88)
at org.apache.pdfbox.preflight.PreflightDocument.validate(PreflightDocument.java:168)
at validepdf.main(validepdf.java:33)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
6 - ajoute la librairie : logaj-1.2.17.jar

run => l'erreur suivante

log4j:WARN No appenders could be found for logger (org.apache.pdfbox.util.PDFStreamEngine).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmpbox/xml/XmpParsingException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.pdfbox.preflight.PreflightConfiguration.getInstanceOfProcess(PreflightConfiguration.java:181)
at org.apache.pdfbox.preflight.utils.ContextHelper.callValidation(ContextHelper.java:73)
at org.apache.pdfbox.preflight.utils.ContextHelper.validateElement(ContextHelper.java:88)
at org.apache.pdfbox.preflight.PreflightDocument.validate(PreflightDocument.java:168)
at validepdf.main(validepdf.java:33)
Caused by: java.lang.ClassNotFoundException: org.apache.xmpbox.xml.XmpParsingException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 9 more
Est ce que c'est normal que je dois faire tout cela?

J'ai regardé sur internet, j'ai trouvé plusieurs explications mais je n'arrive pas a tout comprendre.
Si je comprend bien je dois réaliser un fichier log4j.properties, et dans le fichier je mets
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
log4j.rootLogger=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%-5p] (%F:%M:%L) %m%n
je ne sais pas ce que cela veut dire. Et après j'en fait quoi?

je ne sais pas comment faire marcher ce code.

Cordialement Law