Le fichier Python de l'exemple « Le profil ICC embarqué ».
Le profil ICC que la bibliothèque embarque dans un fichier PDF/A.
Python
36 lignes
À quoi sert cet exemple
Cette entrée est un fichier à télécharger, pas une page à regarder. Un fichier destiné à l'archivage est obligé de contenir un profil de couleur décrivant l'appareil pour lequel ses couleurs ont été choisies, et la réponse habituelle consiste à livrer celui de quelqu'un d'autre : une centaine de kilooctets ou plus, avec une licence attachée, recopiés dans chacun de vos documents.
Ce que montre cet exemple
Un profil sRVB complet bâti par la bibliothèque, non livré avec elle.
Le profil que reçoit tout fichier PDF/A quand on n'en indique aucun.
Un téléchargement plutôt qu'une page : examinez-le avec un logiciel spécialisé. Seule la bibliothèque l'écrit, et aucune requête au serveur ne renvoie ce fichier.
"""Writes the ICC profile the library embeds in a PDF/A file.The Python twin of the `write_icc` example in Rust: the same bytes, through thebinding rather than through the library directly.The profile is built from the colorimetry sRGB is defined by rather thanshipped as a file, so what a document embeds can be looked at on its own —whether it is a well-formed ICC profile, and whether it is really sRGB, is what`scripts/check_icc_profile.py` uses this for.Usage: python examples/write_icc.py [out.icc]"""from__future__importannotationsimportsysfrompathlibimportPathimporthqf_pdfROOT=Path(__file__).resolve().parents[3]defmain()->None:out=Path(sys.argv[1])iflen(sys.argv)>1elseROOT/"tmp"/"srgb.icc"profile=hqf_pdf.srgb_icc_profile()out.parent.mkdir(parents=True,exist_ok=True)out.write_bytes(profile)print(f"wrote {out}: {len(profile)} bytes")if__name__=="__main__":main()