File: pdfboxValidate.py

package info (click to toggle)
endesive 2.18.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,540 kB
  • sloc: python: 17,934; java: 1,000; xml: 800; sh: 306; javascript: 118; makefile: 8
file content (22 lines) | stat: -rwxr-xr-x 663 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env vpython3
import sys
import pdfbox
from jnius import autoclass


pdfname = 'pdf.pdf'
if len(sys.argv) > 1:
    pdfname = sys.argv[1]
parser = autoclass('org.apache.pdfbox.preflight.parser.PreflightParser')(pdfname)
parser.parse()
#org.apache.pdfbox.preflight.PreflightDocument
document = parser.getPreflightDocument()
document.validate()
result = document.getResult()
document.close()
if result.isValid():
    print("The file:{} is a valid PDF/A-1b file".format(pdfname))
else:
    print("The file: {} is not valid, error(s) :".format(pdfname))
    for error in result.getErrorsList():
        print(error.getErrorCode(), " : ", error.getDetails())