sOutputFile and sPDFAOutputIntent values don't get attributed correctly

24 Views Asked by At

My goal is to convert a pdf file into a pdfA/3-b

Here's my code:

import subprocess

gs_path = r"C:\Program Files\gs\gs10.02.1\bin\gswin64.exe"

def convert_to_pdfa(input_path, output_path, output_intent_path):
    command = [
        gs_path,
        "-dPDFA",
        "-dBATCH",
        "-dNOPAUSE",
        "-sDEVICE=pdfwrite",
        "-sOutputFile=" + output_path,
        "-dPDFACompatibilityPolicy=3",
        "-sColorConversionStrategy=RGB",
        "-dUseCIEColor=true",
        "-sPDFAOutputIntent=" + output_intent_path,
        input_path
    ]
    print(command)

    subprocess.run(command)

if __name__ == "__main__":
    input_pdf_path = "facture.pdf"
    output_pdfa_path = "output_pdfa.pdf"
    output_intent_path = "sRGB_v4_ICC_preference.icc"

    convert_to_pdfa(input_pdf_path, output_pdfa_path, output_intent_path)

The pdf gets rendered successfully but when I check the format's validity by using this site : https://avepdf.com/fr/pdfa-validation

I get this error message: Device dependent color space used without matching PDF/A OutputIntent. Page 1 Object ref : 4 0 obj Page 2 Object ref : 18 0 obj

I checked the code in the rendered pdf file:

%%Invocation: path/gswin64.exe -dDisplayFormat=198788 -dDisplayResolution=120 -dPDFA -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=? -dPDFACompatibilityPolicy=3 -sColorConversionStrategy=RGB -dUseCIEColor=true -sPDFAOutputIntent=? ?

4 0 obj
<</Type/Page/MediaBox [0 0 595 841]
/Rotate 0
/Parent 3 0 R
/Resources
<</ProcSet[/PDF /Text] 
/ExtGState 16 0 R 
/Font 17 0 R >>
/Contents 5 0 R
/CropBox [0 0 595 841] >>
endobj

18 0 obj
<</Type/Page/MediaBox [0 0 595 841]
/Rotate 0/Parent 3 0 R
/Resources<</ProcSet[/PDF /Text]
/ExtGState 21 0 R
/Font 22 0 R>>
/Contents 19 0 R
/CropBox [0 0 595 841]>>
endobj

The values of -sOutputFile and -sPDFAOutputIntent have "?" as a value and not the ones I attributed.

I tried using f string but the issue persists:

command = [
    gs_path,
    "-dPDFA",
    "-dBATCH",
    "-dNOPAUSE",
    "-sDEVICE=pdfwrite",
    f"-sOutputFile={output_path}",
    "-dPDFACompatibilityPolicy=3",
    "-sColorConversionStrategy=RGB",
    "-dUseCIEColor=true",
    f"-sPDFAOutputIntent={output_intent_path}",
    input_path
]
0

There are 0 best solutions below